Developer ResourcesAddress
Address Module Overview
The customer address book — delivery addresses, the default-address invariant, and the snapshot rule for orders.
Audience: Product owners, QA, frontend and backend developers Scope: A customer's own delivery addresses, default handling, and the rule orders must follow
Address Module - Overview
1. What the module is
The customer address book: a customer's own delivery addresses, with at most one default and a soft-delete/restore lifecycle. Seven routes, all scoped to the authenticated customer — there is no admin surface over this table, deliberately, because it holds names, phone numbers and GPS coordinates.
2. The rules that matter
- Orders must SNAPSHOT the delivery address — never foreign-key to
customer_address. The FK fromcustomersisON DELETE CASCADE, so erasing a customer erases their addresses (they are PII that must not outlive their owner). An order that referenced an address row would lose its shipping destination at that moment; an order's address must stay truthful for as long as the order does. Copy the resolved fields onto the order at checkout. - The first address becomes the default automatically.
isDefaultonly matters from the second address onward. - A customer with zero active addresses has no default. That is a legal state — never assume a default always exists.
- Restoring an archived address does NOT restore its old default flag. It becomes the default only if the customer has no other active addresses.
municipality.idisnullon every address — the reference table ships empty by design.municipality.nameis free text the customer types; render the name, never wait for an id.- Serviceability is computed on every read from the live shipping configuration. It is never stored, so an admin editing a district immediately changes what every address reports.
3. The lifecycle
| State | Meaning | Writes allowed |
|---|---|---|
active | Usable for delivery; the default must be active | PATCH, DELETE (archive), PUT /default |
archived | Soft-deleted; readable, restorable | POST /restore only |
- Archiving the default promotes the newest remaining active address.
- PATCH, DELETE and PUT /default on an archived address return 409 — restore first.
- The active set is capped at 20; archived addresses do not count.
4. The phone rule
recipientPhone accepts a local number — 9812345678 is normalized to +9779812345678 on the way in, and responses always return E.164. Do not pre-format it client-side.
Page guide
| Page | Read it for |
|---|---|
| Features and flows | Actor journeys, the default-address state machine, edge cases |
| Backend | Schema, the CASCADE/snapshot rule, the advisory lock |
| API | All seven endpoints, DTOs and error codes |