How does the atomic structure of crystals determines its shapes?
It’s all about minimizing the energy of the system. Imagine a 2D example:

 

You can imagine the green circles as the cations ($\ce{Na+}$) and the blue ones as anions ($\ce{Cl-}$). Where is the next chloride you add going to go?


Not a great choice – it doesn’t really balance. The nearest blue ion is already balancing its charge with two other green ions and so can’t help the new ion balance its charge as well.
This is on the grid but still has all the same problems where the new ion doesn’t get its charge nicely balanced because the nearest blue ion is already donating part of its charge to two other ions.
This is the best option because it can share partial charges with two other blue ions. It gets more shared charge and the whole thing ends up being lower energy.


This pattern will keep happening with every addition until you get a macro-scale cube. It is always lower energy to fit new ions into gaps then to branch out and make new structures.

Ions that aren’t part of a complete unit cell will develop surface charges. These surface charges are better at attracting ions that are precipitating onto the surface from solution.