Facets Hold No State Variable Data. All State Variable Data is Stored in a Diamond Proxy Contract
A diamond proxy contract is the smart contract with the fallback function that delegates function calls to facets. Here’s a link to a diamond proxy contract source code: https://github.com/mudgen/diamond-1-hardhat/blob/main/contracts/Diamond.sol
A facet is a smart contract that a diamond proxy contract delegates function calls to.
A facet can define structs which contain state variable declarations or it can import and use Solidity libraries that define structs that contain state variable declations. A facet can contain code that reads and writes to state variables in structs. Or a facet can import Solidity libraries that read or write to state variables in structs.
It is important to understand that any state variable read or written from code from a facet is read and written using the diamond proxy contract storage and not a facet’s contract storage.
No state variables are read or written in facet contract storage.
All code in a facet, including its Solidity libraries, reads and writes to a diamond proxy contract’s storage.
A diamond proxy contract is a central contract storage location for all facets.
Facets provide the code used by a diamond proxy contract.
Facet constructor functions that read or write to state variables don’t work because facet constructor functions don’t read or write to a diamond proxy contract storage. More informationan about that from this blog post: Constructor Functions Don't Work in Facets
The reason facets read and write to a diamond proxy contract’s storage is because `delegatecall` is used. How `delegatecall` works is explained in this article: Understanding delegatecall And How to Use It Safely