  We develop a novel semi-analytic spectral fitting approach to quantify the
star-formation histories (SFHs) and chemical enrichment histories (ChEHs) of
individual galaxies. We construct simple yet general chemical evolution models
that account for gas inflow and outflow processes as well as star formation, to
investigate the evolution of merger-free star-forming systems. These models are
fitted directly to galaxies' absorption-line spectra, while their emission
lines are used to constrain current gas phase metallicity and star formation
rate. We apply this method to spiral galaxies selected from the SDSS-IV MaNGA
survey. By fitting the co-added absorption-line spectra for each galaxy, and
using the emission-line constraints on present-day metallicity and star
formation, we reconstruct both the SFHs and the ChEHs for all objects in the
sample. We can use these reconstructions to obtain archaeological measures of
derived correlations such as the mass--metallicity relation at any redshift,
which compare favourably with direct observations. We find that both the SFHs
and ChEHs have strong mass dependence: massive galaxies accumulate their
stellar masses and become enriched earlier. This mass dependence causes the
observed flattening of the mass--metallicity relation at lower redshifts. The
model also reproduces the observed gas-to-stellar mass ratio and its mass
dependence. Moreover, we are able to determine that more massive galaxies have
earlier gas infall times and shorter infall time-scales, and that the early
chemical enrichment of low-mass galaxies is suppressed by strong outflows,
while outflows are not very significant in massive galaxies.
