  TRAPPIST-1 is an 0.09 $M_{\odot}$ star, which harbours a system of seven
Earth-sized planets. Two main features stand out: (i) all planets have similar
radii, masses, and compositions; and (ii) all planets are in resonance.
Previous works have outlined a pebble-driven formation scenario where planets
of similar composition form sequentially at the H$_2$O snowline (${\sim}0.1$ au
for this low-mass star). It was hypothesized that the subsequent formation and
migration led to the current resonant configuration. Here, we investigate
whether the sequential planet formation model is indeed capable to produce the
present-day resonant configuration, characterized by its two-body and
three-body mean motion resonances structure. We carry out N-body simulations,
accounting for type-I migration, stellar tidal damping, disc
eccentricity-damping, and featuring a migration barrier located at the disc's
inner edge. Due to the sequential migration, planets naturally form a chain of
first-order resonances. But to explain the period ratios of the b/c/d-system,
which are presently in higher-order resonances, we find that planets b and c
must have marched across the migration barrier, into the gas-free cavity,
before the disc has dispersed. We investigate both an early and late cavity
infall scenario and find that the early infall model best matches the
constraints, as well as being more probable. After the dispersal of the gaseous
disc, stellar tidal torque also contributes towards a modest separation of the
inner system. We outline how the insights obtained in this work can be applied
to aid the understanding of other compact resonant planet systems.
