Electrons migrate from $N$ side to $P$ side until a equilibrium is reached.
If we consider the width of each side like $ -w_p $ as the width of $P$ side, $ w_n $ as the width of $N$ side, with $ 0 $ being the coordinate of the contact between $P$ and $N$ sides.
The length of the $PN$ diode will be $ [-w_p, w_n ] $
If we use the charge depletion approximation, a diode will have two types of regions:
(1) the space charge region - SCR which forms in between the P and N sides; the length of this region is measured as $ [-x_p, x_n] $
(2) two quasi neutral regions - QNR; one in between the ohmic contact of the P side and the
The concentration of excess populations will be :
$$ n'(-x_p) = \left( \frac{n_i^2}{N_{Ap}} \right) (e ^ {\frac{qv_{AB}}{k_B T}} - 1) $$
$$ p'(x_n) = \left( \frac{n_i^2}{N_{Dn}} \right) (e ^ {\frac{qv_{AB}}{k_B T}} - 1) $$
In a photovoltaic cell electrons from SCR are freed by photons and separated immediately by the electric field present in the SCR, holes to $P$ and electrons to $N$ side. A potential will appear between the P and the N side : $ v_{AB} $. The cell is engineered such that for the direct current $ I_d(v_{AB}) $ for the $ v_{AB} $ is as little as possible (while balancing other factors too, etc).
What prevents the electrons in the N-type semiconductor from just filling in the holes of the P-type directly instead of travelling through the front grid?
The field created near SCR is opposite to the field created by the free electrons in the $N$ side forcing them to stay in the $N$ side, in a so called equilibrium (and also the field in SCR is forcing holes to stay in the $P$ region). You can compare this situation with a virtual capacitor.
Only the excess carriers will flow throw the SCR from $N$ side to $P$ side.
SCR length will diminish with the increase of $v_{AB}$ under the action of light. This means that fewer and fewer electrons/holes can be freed from the SCR with the increase of $v_{AB}$ due to photoelectric effect.
Some graphics could help too and so I recommend you to read the following OpenCourse lecture from MIT 6-012 Microelectronic Devices and Circuits
and see lecture 6
Regarding $I_d$ see Losses occurring in solar cells