The structure of leaves lets gases diffuse in and out of the cell.
Carbon dioxide diffuses into the air spaces within the leaf, then it diffuses into the cells where photosynthesis happens, the leafs structure has adapted so that this can happen easily.
The oxygen (produced in photosynthesis) and water vapour also diffuse out through stomata.
The size of the stomata are controlled by the guard cells. These close the stomata if the plant is loosing water faster than it is being replaced by its roots. Without the guard cells the plant would wilt.
The flattered shape of the leaf increases the area of this exchange surface so that its more effective.
The walls of the cells inside the leaf form another exchange surface. The air spaces inside the leaf increases the area of this surface so there's more chance for carbon dioxide to get into the cells.
The water vapour evapourates from the cells inside the leaf. Then it escapes by diffusion because there's a lot of it inside the leaf and less of it in the air outside.