Since the suggestion of relativistic shocks as the origin of gamma-ray bursts (GRBs) in the early 1990s, the mathematical formulation of this process has stayed at a phenomenological level. One of the reasons for the slow development of theoretical works has been the simple power-law behaviour of the afterglows hours or days after the prompt gamma-ray emission. It was believed that they could be explained with these formulations. Nowadays, with the launch of the Swift satellite and implementation of robotic ground follow-ups, GRBs and their afterglow can be observed at multi-wavelengths from a few tens of seconds after trigger onwards. These observations have led to the discovery of features unexplainable by the simple formulation of the shocks and emission processes used up to now. Some of these features can be inherent in the nature and activities of the GRBs' central engines which are not yet well understood. On the other hand, the devil is in the detail and others may be explained with a more detailed formulation of these phenomena and without ad hoc addition of new processes. Such a formulation is the goal of this work. We present a consistent formulation of the kinematics and dynamics of the collision between two spherical relativistic shells, their energy dissipation and their coalescence. It can be applied to both internal and external shocks. Notably, we propose two phenomenological models for the evolution of the emitting region during the collision. One of these models is more suitable for the prompt/internal shocks and late external shocks, and the other for the afterglow/external collisions as well as the onset of internal shocks. We calculate a number of observables such as flux, lag between energy bands and hardness ratios. One of our aims has been a formulation complex enough to include the essential processes, but simple enough such that the data can be directly compared with the theory to extract the value and evolution of physical quantities. To accomplish this goal, we also suggest a procedure for extracting parameters of the model from data. In a companion paper, we numerically calculate the evolution of some simulated models and compare their features with the properties of the observed GRBs.