In the past years, ground-based and space telescopes have given us inestimable information about the Universe we leave in. We can now study the physical properties of galaxies from the present day, up to 13 billion years ago. Such quantity and quality of data require more and more advanced tools to best exploit the observations. To do this, we have developed a sophisticated approach to extract meaningful informations from any type of galaxy observation, from rest-frame ultraviolet to near-infrared wavelengths. We have built a physically motivated library of galaxy spectral energy distributions by combining the semi-analytic post-treatment of a large cosmological simulation with state-of-the-art models of the stellar and nebular emission and the effect of dust. Our approach allows us to constrain the star formation histories of galaxies and thus assess how galaxies form, evolve and, after some ups and downs, eventually quench their star formation and evolve passively. In particular, we wish to constrain the relative importance of certain evolutionary mechanisms, such as mergers, feedback events, and gas accretion. I will show constraints derived from local galaxies, using data from the GALEX, SDSS, and WISE surveys, as well as from distant galaxies applying our approach to the CANDELS dataset.