We study the dynamical evolution of the TRAPPIST-1 system under the influence of orbital circularization through tidal interaction with the central star. We find that systems with parameters close to the observed one evolve into a state where consecutive planets are linked by first order resonances and consecutive triples, apart from planets c, d and e, by connected three body Laplace resonances. The system expands with period ratios increasing and mean eccentricities decreasing with time. This evolution is largely driven by tides acting on the innermost planets which then influence the outer ones. In order that deviations from commensurability become significant only on $Gy$ time scales or longer, we require that the tidal parameter associated with the planets has to be such that $Q > sim 10^{2-3}.$ At the same time, if we start with two subsystems, with the inner three planets comprising the inner one, $Q$ associated with the planets has to be on the order (and not significantly exceeding) $10^{2-3}$ for the two subsystems to interact and end up in the observed configuration. This scenario is also supported by modelling of the evolution through disk migration which indicates that the whole system cannot have migrated inwards together. Also in order to avoid large departures from commensurabilities, the system cannot have stalled at a disk inner edge for significant time periods. We discuss the habitability consequences of the tidal dissipation implied by our modelling, concluding that planets d, e and f are potentially in habitable zones.