Lesson 9 of 9 · The whole system assembled, then the same play on your own product · ~40 minutes
No new concepts today. We assemble — and then you take the wheel. Keep the patterns cheat sheet open beside you; that's the permanent artifact from this course.
src/
core/ # pure — no I/O imports allowed, ever
shared/
result.ts # Result<T,E>, err — the one shared kernel type
ordering/ # ← the core domain; lessons 1–5
types.ts # OrderId, Email, Cents, DraftOrder|PlacedOrder|ShippedOrder, OrderEvent
parse.ts # parseEmail, parseCents, parseOrderId — smart constructors
transitions.ts # addLine, removeLine, place, ship — state + events out
billing/ # generic subdomain: our payment language
types.ts # PaymentCaptured, PaymentId — BigPay appears NOWHERE
shipping/
types.ts # ShippingProduct (weight, dims), Shipment
shell/ # imperative — every effect, nothing else
http.ts # handlers: parse → load → transition → save → dispatch → respond
order-repo.ts # loadOrder/saveOrder + rowToOrder/orderToRow translators
bigpay-acl.ts # toPaymentCaptured — the only file that knows BigPay
dispatch.ts # event handlers: emailer, warehouse, analytics
Read the dependencies: core imports nothing outside core/shared.
shell imports both, and nothing imports shell. The context boundaries
(L6) are folder boundaries; the purity boundary (L8) is the core//shell/
split. Both are enforceable by a lint rule — ask me to set that up with you.
Trace one checkout through the whole system. Each move cites its lesson — this is the interleaved review.
| # | Move | Code | Lesson |
|---|---|---|---|
| 1 | Customer submits cart; body is untrusted | parsePlaceBody(raw): Result<PlaceBody> | 1 |
| 2 | Load the draft from storage | loadOrder(id) → rowToOrder(row) | 2, 8 |
| 3 | Validate the draft as an aggregate | addLine/removeLine already kept it consistent | 3 |
| 4 | Transition draft → placed | place(draft, payment, now) | 4 |
| 5 | Collect the facts | events: [OrderPlaced] | 5 |
| 6 | Persist the new stage | saveOrder(placed) → orderToRow | 8 |
| 7 | Learn payment succeeded | toPaymentCaptured(webhook) | 7 |
| 8 | Announce to the world | dispatch(events) → email, warehouse, analytics | 5, 8 |
The guarantee chain, in one breath: a placed order in the database was a draft with lines, paid positively, placed by a transition — and every subscriber was told, exactly once, in their own language. Not one line of that is enforced by developer discipline; it's all enforced by types, transitions, and the folder line.
Now the real assignment — your product. Work through these in order; each maps to a lesson. Small surface first: one flow, one aggregate.
assertNever. (L4)Fourteen questions, drawn from every lesson, in random order. Mixed practice is harder than blocked practice — that difficulty is the point.
RESOURCES.md with usage notes.