In this paper, we present the physical foundations and the development of the thermodynamic part of a Modelica library with the fundamental components for modeling thermofluid systems. We have chosen Modelica because it is an object-oriented modeling language that allows an elegant design of the library, with a top-down conception that starts from very general components where we model the thermodynamic properties common to all simple substances and descend by inheritance to model the properties of each particular substance. To model the behavior of each component, we have used: classical thermodynamics to define the equilibrium states, the local equilibrium hypothesis of Classical Irreversible Thermodynamics to model the changes of state, and the port-Hamiltonian approach to obtain the equations of the system dynamics. With this formulation, we implement the thermodynamic behavior of ideal gases (including monatomic gases as a particular case), the 2073 substances defined for the CEA (Chemical Equilibrium with Applications) NASA Glenn computer program, the IAPWS Formulation 1995 for the Thermodynamic Properties of Water Substance for General and Scientific Use, and the Syltherm 800 HTF (Heat Transfer Fluid). We also define graphical symbols for each library component that facilitate modeling complex systems with simple drag-and-drop manipulations, component connection, and parameter selection. These symbols are a slightly modified version of those used in bond graphs to facilitate their reading and the representation of the structure of complex systems. We also show the modeling, simulation, and comparison for accuracy, performance, and scalability of some thermodynamic systems implemented with the Modelica Standard Library (MSL) and the proposed library.