  This is an expended and revised version of the preprint "Schematization of
homotopy types".
  The purpose of this work is to introduce a notion of \emph{affine stacks},
which is a homotopy version of the notion of affine schemes, and to give
several applications in the context of algebraic topology and algebraic
geometry. As a first application we show how affine stacks can be used in order
to give a new point of view (and new proofs) on rational and $p$-adic homotopy
theory. This gives a first solution to A. Grothendieck's \emph{schematization
problem} described in \cite{gr}. We also use affine stacks in order to
introduce a notion of \emph{schematic homotopy types}. We show that schematic
homotopy types give a second solution to the schematization problem, which also
allows us to go beyound rational and $p$-adic homotopy theory for spaces with
arbitrary fundamental groups. The notion of schematic homotopy types is also
used in order to construct various homotopy types of algebraic varieties
corresponding to various cohomology theories (Betti, de Rham, $l$-adic, ...),
extending the well known constructions of the various fundamental groups.
Finally, as algebraic stacks are obtained by gluing affine schemes we define
\emph{$\infty$-geometric stacks} as a certain gluing of affine stacks. Example
of $\infty$-geometric stacks in the context of algebraic topology (moduli
spaces of dga structures up to quasi-isomorphisms) and Hodge theory
(non-abelian periods) are given.
