Changes
Comparing empty → 160dc49.
| @@ -1,0 +1,38 @@ | ||
| 1 | +--- | |
| 2 | +title: Data model | |
| 3 | +sort: 2 | |
| 4 | +--- | |
| 5 | + | |
| 6 | +# Data model | |
| 7 | + | |
| 8 | +The relationships between the top-level resources. Cardinality is shown next to the line; `1..n` | |
| 9 | +means one customer can have many orders, never the inverse. | |
| 10 | + | |
| 11 | +```drawio | |
| 12 | +{"meta":"placeholder — this fenced block is rendered by the drawio escape hatch on the live server. The local app exposes an in-app editor for it."} | |
| 13 | +``` | |
| 14 | + | |
| 15 | +A textual version of the same shape, for screen readers and grep-ability: | |
| 16 | + | |
| 17 | +- A **tenant** owns everything below. | |
| 18 | +- A **customer** belongs to one tenant. Has `1..n` orders, `1..n` carts, `0..n` payment methods, | |
| 19 | + `1..n` addresses. | |
| 20 | +- A **product** belongs to one tenant. Has `1..n` variants. Variants carry the price and the | |
| 21 | + inventory. | |
| 22 | +- A **cart** belongs to one tenant, optionally to one customer. Has `1..n` line items, each | |
| 23 | + pointing at a variant. | |
| 24 | +- A **checkout session** belongs to one cart. Is the immutable, signed handoff to the hosted | |
| 25 | + payment page. | |
| 26 | +- An **order** is the immutable promotion of a cart at the moment of payment. It carries a | |
| 27 | + snapshot of the line items, not a reference, so price changes do not retroactively alter | |
| 28 | + historical orders. | |
| 29 | +- A **refund** belongs to one order. Up to N refunds can sum to ≤ the order total. | |
| 30 | + | |
| 31 | +## Invariants | |
| 32 | + | |
| 33 | +- Currency is set on the cart at creation and cannot change. A cart cannot mix currencies. | |
| 34 | +- A product's `currency` does not constrain the cart's currency — pricing tables handle the | |
| 35 | + cross-product per-currency price. | |
| 36 | +- Order line items snapshot product name, SKU, and unit price at the moment the order is created. | |
| 37 | + Editing the product after the fact does not retroactively change the order. | |
| 38 | +- Customer email is unique per tenant, case-folded. | |