My head canon has replicators just being fancy 3D printers.
Mainly going off the
TNG episode where the Enterprise is stuck in a rift and can't move. Troi kept getting visions from psychic aliens saying "one moon circles" because they need hydrogen to cause an explosion. At one point Data shows off a list of elements and says "these are the elements we have available... perhaps if we can communicate this inventory..." If they could synthesize everything in demand, the dialogue might be different? (Enterprise being low energy in the episode could mean they couldn't synthesize the other half of the explode-y bit with hydrogen.)
It makes me think the most ships keep an inventory of elements they can use to make parts and food. The TNG Technical Manual definitely says they keep replicator feedstock for food, air, and water and recycle that. The rest of the elemental inventory is for repair and parts manufacture through replicators.
It also ties in nicely why through all through TNG, DS9, VOY, and beyond there still exist Federation mining colonies. They still have to mine for all the elements they use, the replicator just helps manufacture stuff. What the replicators "can't replicate" is either the elements/compounds not being placed by the replicators accurately enough or parts are too detailed/too large to replicate.
(Though I think the Federation still has nuclear alchemy, but they may or may not do it through the replicator and the alchemy probably has a high energy penalty. The penalty could make it worthwhile to actually mine for stuff.)