We present a general formalism to model and calculate linear and nonlinear optical processes in composite systems, based on a graphical representation of light-matter interactions by loop diagrams associated with Feynman rules. Through this formalism, we recover the usual second-order response of a simple system by drawing four times fewer loop diagrams than doubled-sided ones. For composite systems, we introduce coupling Hamiltonians between subsystems (for example, a molecule and a substrate), graphically represented by virtual bosons. In this way, we enumerate all the diagrams describing the second-order response of the system and show how to select those relevant for the calculation of the molecular second-order hyperpolarizabilities under the influence of the substrate, including effective second-order contributions from the molecular third-order response. As it applies to all nonlinear processes and an arbitrary number of interacting partners, this representation provides a general frame for the calculation of the nonlinear response of arbitrarily complex systems.