  State sum constructions, such as Kuperberg's algorithm, give partition
functions of physical systems, like lattice gauge theories, in various
dimensions by associating local tensors or weights, to different parts of a
closed triangulated manifold. Here we extend this construction by including
matter fields to build partition functions in both two and three space-time
dimensions. The matter fields introduces new weights to the vertices and they
correspond to Potts spin configurations described by an $\mathcal{A}$-module
with an inner product. Performing this construction on a triangulated manifold
with a boundary we obtain the transfer matrices which are decomposed into a
product of local operators acting on vertices, links and plaquettes. The vertex
and plaquette operators are similar to the ones appearing in the quantum double
models (QDM) of Kitaev. The link operator couples the gauge and the matter
fields, and it reduces to the usual interaction terms in known models such as
$\mathbb{Z}_2$ gauge theory with matter fields. The transfer matrices lead to
Hamiltonians that are frustration-free and are exactly solvable. According to
the choice of the initial input, that of the gauge group and a matter module,
we obtain interesting models which have a new kind of ground state degeneracy
that depends on the number of equivalence classes in the matter module under
gauge action. Some of the models have confined flux excitations in the bulk
which become deconfined at the surface. These edge modes are protected by an
energy gap provided by the link operator. These properties also appear in
"confined Walker-Wang" models which are 3D models having interesting surface
states. Apart from the gauge excitations there are also excitations in the
matter sector which are immobile and can be thought of as defects like in the
Ising model. We only consider bosonic matter fields in this paper.
