The compositional and evolutionary logic of metabolism