We saw that white light can be separated into different colours (wavelengths) by shining it through a prism. This uses the principle of refraction of light, that bends at the boundary between two different densities. The refraction occurs twice when light enters and exits the prism.
A better separation of the wavelengths can be obtained with diffraction, which is the bending of light when it touches a sharp edge. Diffraction is also a typical wave phenomenon and can be demonstrated with water waves and even sound waves.
Image scipp.ucsc.edu (edited)
Modern spectrographs use a diffraction grating on which many very fine parallel grooves are etched. Extreme accuracy is required in the constant thickness of the lines and in their spacing that should be in the order of the wavelength of light.
Only very few companies can make these gratings to scientific standards, and even then the manufacturing process is one of trial and error, where only a few of the end products ever make it through the quality control. Especially for space born spectrographs, which cannot be serviced after launch, the requirements are at the limit of technical capabilities. But the results of such spectrographs are spectacular.
The rest of a spectrograph is fairly straightforward in principle. If only one wavelength is focused onto the detector, the instrument works as a very narrow wavelength filter (aka "monochromator"). Otherwise many but separate wavelengths are recorded on the detector.
Schematic of a spectrograph,
Image outreach.atnf.csiro.au (edited)
In early models the detector was a photographic plate, but nowadays, a CCD type camera is used, that is directly connected to a computer readout and the process is fully automatic.
Early line spectrum recorded
on photographic plate.
In observatories, the spectrograph is usually placed in a climate controlled room, away from the telescope. Often the light from the telescope enters the spectrograph through fibre optics.
No astronomer looks at the light, but only analyses the resulting spectrum at the computer, where processing can be done automatically as well.
Typical plots that are studied are not only the nice colour spectra as we know them, but more often graphs of intensity (vertical) versus wavelength (horizontal). Dips in the graph show the location of absorption lines.