  We generalise the theory of Cuntz-Krieger families and graph algebras to the
class of finitely aligned $k$-graphs. This class contains in particular all
row-finite $k$-graphs. The Cuntz-Krieger relations for non-row-finite
$k$-graphs look significantly different from the usual ones, and this
substantially complicates the analysis of the graph algebra. We prove a
gauge-invariant uniqueness theorem and a Cuntz-Krieger uniqueness theorem for
the $C^*$-algebras of finitely aligned $k$-graphs.
