the link to free energy and statistical mechanics
Large deviations and equilibrium statistical mechanics are the same mathematics in different dress, and seeing the dictionary is one of the deepest payoffs of the theory. The exponential weighting that defines the Gibbs-Boltzmann measure, e^(-beta H) / Z, is precisely an exponential tilt; the partition function Z is precisely the normalising exponential integral that Varadhan's lemma evaluates; the free energy is precisely a scaled cumulant generating function; and the thermodynamic entropy is precisely a large-deviation rate function. The Legendre duality between entropy and free energy that physicists write down is the same Legendre-Fenchel duality between rate function and log-mgf.
Concretely, for a system of N particles with energy H, the free energy density is f(beta) = -lim (1/(beta N)) log Z_N(beta), where Z_N(beta) = Sum over states of e^(-beta H) is the partition function and beta is inverse temperature. Up to sign and scaling, beta f is a scaled cumulant generating function in the Gartner-Ellis sense, with the energy per particle playing the role of the tilted observable. Its Legendre-Fenchel transform is the (Boltzmann/thermodynamic) entropy as a function of energy, s(u) = inf over beta of (beta u - beta f(beta)) up to sign, which is exactly the large-deviation rate function for the empirical energy: the probability that the system has energy density near u is e^(N s(u)) relative to the maximum. Equilibrium is the energy that maximises entropy at fixed temperature, i.e. the zero of the rate function, recovering the variational principle of thermodynamics from the LDP.
This correspondence is not a loose analogy; it is exploited in both directions. Sanov's relative-entropy rate function is the statistical-mechanics entropy of a non-interacting (ideal) system, and the Gibbs conditioning principle is the maximum-entropy derivation of equilibrium ensembles. Phase transitions appear as non-analyticities of the free energy f(beta), equivalently as non-strict-convexity (flat pieces or kinks) of the rate function, where the Legendre transform loses its one-to-one correspondence — a flat segment of the entropy is a first-order transition with phase coexistence, and a kink in the free energy is a latent heat. An honest caution: for interacting systems the free-energy limit may fail to exist or the rate function may be non-convex, and then the naive Legendre transform gives only the convex hull (Maxwell equal-area construction), missing metastable branches that a direct large-deviation analysis can still see.
In the Curie-Weiss (mean-field Ising) model the empirical magnetisation m of N spins satisfies an LDP with rate function I(m) = (Legendre dual of the free energy). Above the critical temperature I has a single well at m = 0; below it, I develops two symmetric wells at +/- m* with a flat-ish barrier between — the rate function literally pictures spontaneous magnetisation and phase coexistence.
Free energy and entropy are a log-mgf / rate-function Legendre pair; transitions are its kinks.
Phase transitions are exactly where Legendre duality breaks down: a non-convex rate function transforms to a free energy with a flat segment, and inverting loses information (only the convex hull is recovered). So convex-duality intuition silently erases metastable and coexisting phases unless you keep the full rate function.