Boundaries of boundaries: A systematic approach to lattice models with solvable boundary states of arbitrary codimension