Shouldn't $dU=TdS-PdV$ be true for every closed system? For a closed system, if there aren't chemical reactions or a phase change inside it, $dU=TdS-PdV$ is the fundamental thermodynamic relation.
This expression can be generalized, for a closed system undergoing phase transition, or chemical reactions, as $dU=TdS-PdV+\sum_i \mu_idN_i$
The generalized relation above seems to have a straightforward physical meaning, it takes into account the energy change due to chemical reactions or phase transitions.
However, when i think that the system is closed, it seems wrong, because, for a closed system, $dU=\delta Q +\delta W $, and, for a reversible process, we have $(\delta Q)_{rev}=TdS$,  $(\delta W)_{rev}=-PdV$. So, substituting, we get $dU=TdS-PdV$, that, since it is an equation between state functions, is true for every transformation.
I pondered about the derivation above, i'm pretty sure that, the equations $dU=\delta Q +\delta W $, and  $(\delta Q)_{rev}=TdS$, are always true for a closed system. On the other hand, i'm not sure about $(\delta W)_{rev}=-PdV$, that may be wrong if the system is undergoing phase transition or chemical reactions. If that is the case, however, i can't figure out why.
 A: It is not sufficient that the system is closed (i.e., does not exchange matter with the outside world) - it should be also in equilibrium, as all the equations you use are for systems in equilibrium. This includes the reversible process, since, by definition, it is a process so slow that at every point the system can be regarded as being in equilibrium.
Further, in statistical physics a change of internal energy is usually decomposed into a change caused by macroscopic factors - like changing the volume, change of external field, etc., and microscopic factors - e.g., due to the energy exchange between the molecules with the adjacent regions. These are called respectively work and heat. Work is not necessarily a result of changing volume - we often define generalized forces and generalized coordinates, so that
$$
dU = TdS -PdV+\sum_i F_idX_i
$$
One frequently used example is magnetization and the external magnetic field for magnetic systems (e.g., in Ising model.)
When including term $\sum_i\mu_idN_i$ the notion of closed system becomes somewhat ambiguous and loses its value, since this can be viewed as several systems exchanging particles - and hence manifestly open systems (rather than closed.)
