In this paper we present a self-contained macroscopic description of diffusive systems interacting with boundary reservoirs and under the action of external fields. The approach is based on simple postulates which are suggested by a wide class of microscopic stochastic models where they are satisfied. The description however does not refer in any way to an underlying microscopic dynamics: the only input required are transport coefficients as functions of thermodynamic variables, which are experimentally accessible. The basic postulates are local equilibrium which allows a hydrodynamic description of the evolution, the Einstein relation among the transport coefficients, and a variational principle defining the out of equilibrium free energy. Associated to the variational principle there is a Hamilton-Jacobi equation satisfied by the free energy, very useful for concrete calculations. Correlations over a macroscopic scale are, in our scheme, a generic property of nonequilibrium states. Correlation functions of any order can be calculated from the free energy functional which is generically a non local functional of thermodynamic variables. Special attention is given to the notion of equilibrium state from the standpoint of nonequilibrium.