In this essay we present and explore a mathematical foundation for thermodynamics which is simple in concept and sufficiently broad to support the many manifestations of the subject found in physics, including thermodynamical theories of" systems with memory". Our discussion splits naturally into two parts. Sections 1 through 8 comprise Part I and deal mainly with basic concepts and assumptions which appear to be present in all branches of thermodynamics; the theory developed in Part I permits us to discuss questions of existence, uniqueness, and regularity of energy and entropy functions. In Sections 9-13, ie Part II, we illustrate our general theory by developing a theory of" simple material elements" which contains as special cases the classical theories of elastic elements and viscous elements as well as recent theories of elements with internal variables and elements with fading memory. In Part II we show that many results which have been obtained from the Clausius-Duhem inequality are consequences of a weaker form of the Second Law of Thermodynamics.