Short answer
After a yolk is ovulated, the oviduct adds albumen and membranes. The shell gland then deposits a calcium-carbonate shell over many hours before pigment and the protective cuticle are added near laying.
Building from the inside out
The yolk enters the oviduct first. Layers of albumen form around it, including the chalazae that help keep it centred. Inner and outer shell membranes are added next, creating the surfaces on which the mineral shell develops.
The shell is mineralised
In the shell gland, calcium and carbonate are deposited as crystals, producing a strong but porous structure. The hen draws calcium from the diet and body reserves. Heat stress, age, illness and nutrition can affect shell thickness and texture.
Pigment, pores and cuticle
Genetic pigments create white, brown, blue or green shells. Thousands of pores allow gas and moisture exchange. A final protein-rich cuticle covers the surface and helps limit microbial entry, which is one reason egg-washing systems must be carefully controlled.