We introduce a simple and general framework for the construction of thermodynamically compatible schemes for the numerical solution of overdetermined hyperbolic PDE systems that satisfy an extra conservation law. As a particular example in this paper, we consider the general Godunov-Peshkov-Romenski (GPR) model of continuum mechanics that describes the dynamics of nonlinear solids and viscous fluids in one single unified mathematical formalism.A main peculiarity of the new algorithms presented in this manuscript is that the entropy inequality is solved as a primary evolution equation instead of the usual total energy conservation law, unlike in most traditional schemes for hyperbolic PDE. Instead, total energy conservation is obtained as a mere consequence of the proposed thermodynamically compatible discretization. The approach is based on the general framework introduced in Abgrall (2018) [1]. In order to show the universality of the concept proposed in this paper, we apply our new formalism to the construction of three different numerical methods. First, we construct a thermodynamically compatible finite volume (FV) scheme on collocated Cartesian grids, where discrete thermodynamic compatibility is achieved via an edge/face-based correction that makes the numerical flux thermodynamically compatible. Second, we design a first type of high order accurate and thermodynamically compatible discontinuous Galerkin (DG) schemes that employs the same edge/face-based numerical fluxes that were already used inside the finite volume schemes. And third, we introduce a second type of thermodynamically compatible DG schemes, in which thermodynamic compatibility is achieved via an element-wise correction, instead of the edge/face-based corrections that were used within the compatible numerical fluxes of the former two methods. All methods proposed in this paper can be proven to be nonlinearly stable in the energy norm and they all satisfy a discrete entropy inequality by construction. We present numerical results obtained with the new thermodynamically compatible schemes in one and two space dimensions for a large set of benchmark problems, including inviscid and viscous fluids as well as solids. An interesting finding made in this paper is that, in numerical experiments, one can observe that for smooth isentropic flows the particular formulation of the new schemes in terms of entropy density, instead of total energy density, as primary state variable leads to approximately twice the convergence rate of high order DG schemes for the entropy density.