  Twist defects in surface codes can be used to encode more logical qubits,
improve the code rate, and implement logical gates. In this work we provide a
rigorous formalism for constructing surface codes with twists generalizing the
well-defined homological formalism introduced by Kitaev for describing CSS
surface codes. In particular, we associate a surface code to \emph{any} graph
$G$ embedded on \emph{any} 2D-manifold, in such a way that (1) qubits are
associated to the vertices of the graph, (2) stabilizers are associated to
faces, (3) twist defects are associated to odd-degree vertices. In this way, we
are able to reproduce the variety of surface codes, with and without twists, in
the literature and produce some new examples. We also calculate and bound
various code properties such as the rate and distance in terms of topological
graph properties such as genus, systole, and face-width.
