  We characterize inverse limits of nilsystems in topological dynamics, via a
structure theorem for topological dynamical systems that is an analog of the
structure theorem for measure preserving systems. We provide two applications
of the structure. The first is to nilsequences, which have played an important
role in recent developments in ergodic theory and additive combinatorics; we
give a characterization that detects if a given sequence is a nilsequence by
only testing properties locally, meaning on finite intervals. The second
application is the construction of the maximal nilfactor of any order in a
distal minimal topological dynamical system. We show that this factor can be
defined via a certain generalization of the regionally proximal relation that
is used to produce the maximal equicontin uous factor and corresponds to the
case of order 1.
