Dark-field X-ray microscopy, DFXM, is a new full-field imaging technique that non-destructively maps the structure and local strain inside deeply embedded crystalline elements in three dimensions. In DFXM an objective lens is placed along the diffracted beam to generate a magnified projection image of the local diffracted volume. In this work, a general formalism based on geometrical optics is provided for the diffraction imaging, valid for any crystallographic space group. This allows the simulation of DFXM images based on micro-mechanical models. Example simulations are presented with the formalism, demonstrating how this may be used to design new experiments or to interpret existing ones. In particular, it is shown how modifications to the experimental design may tailor the reciprocal-space resolution function to map specific components of the deformation-gradient tensor. The formalism supports multi-length-scale experiments, as it enables DFXM to be interfaced with 3D X-ray diffraction. To illustrate the use of the formalism, DFXM images are simulated from different contrast mechanisms on the basis of the strain field around a straight dislocation.