Capstone: Meridian Checkout, End to End

Lesson 9 of 9 · The whole system assembled, then the same play on your own product · ~40 minutes

1 · Value objects 2 · Entities & identity 3 · Aggregates 4 · Lifecycle state machines 5 · Domain events 6 · Bounded contexts 7 · Context mapping 8 · Functional core 9 · Capstone
Why this matters for your mission This is the payoff: one coherent system where every business rule is enforced by a type or a transition, every effect sits at the rim, and every piece is independently testable. Then the real assignment: the same architecture, on your product.

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.

1 · The map of what we built

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.

2 · The flow, in eight moves

Trace one checkout through the whole system. Each move cites its lesson — this is the interleaved review.

#MoveCodeLesson
1Customer submits cart; body is untrustedparsePlaceBody(raw): Result<PlaceBody>1
2Load the draft from storageloadOrder(id) → rowToOrder(row)2, 8
3Validate the draft as an aggregateaddLine/removeLine already kept it consistent3
4Transition draft → placedplace(draft, payment, now)4
5Collect the factsevents: [OrderPlaced]5
6Persist the new stagesaveOrder(placed) → orderToRow8
7Learn payment succeededtoPaymentCaptured(webhook)7
8Announce to the worlddispatch(events) → email, warehouse, analytics5, 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.

3 · What “done” looks like: the transfer checklist

Now the real assignment — your product. Work through these in order; each maps to a lesson. Small surface first: one flow, one aggregate.

  1. Pick one flow with real business rules (not CRUD). Name it in the business's words — that's your first ubiquitous-language artifact. (L1)
  2. Value objects: list every concept with a rule; brand + parse the top three. Delete the scattered validation. (L1)
  3. Entities: mark which concepts have identity; give each a branded id and an identity-equality function. (L2)
  4. One aggregate: choose the cluster whose rules must be instantly true; write its transitions; make everything else read-only. (L3)
  5. Lifecycle: if the flow has stages, replace the status string with a discriminated union + assertNever. (L4)
  6. Events: list the side effects; return them as typed facts; move handlers to the shell. (L5)
  7. Contexts: draw the map — core / supporting / generic, and the one vendor you'll wrap in an ACL. (L6–7)
  8. Shell: one handler as a parse → load → transition → save → dispatch chain; the repository parses. (L8)
Wisdom: take it to real practitioners Reading gives knowledge; argument gives wisdom. Two moves: (1) bring your draft aggregate boundaries to me — stress-testing them is what I'm for; (2) take the genuinely contested ones to the DDD/CQRS/ES Discord (invite link lives on the awesome-ddd page) or r/typescript — “here's my ordering aggregate, where would you draw the line?” is a rite of passage there, and the answers will sharpen instincts no lesson can.

4 · Retrieval check — the whole course, mixed

Fourteen questions, drawn from every lesson, in random order. Mixed practice is harder than blocked practice — that difficulty is the point.

5 · Where to go from here

Your teacher is the agent The course is complete; the teaching isn't. Bring your product's first aggregate design, your context map, or your ugliest vendor webhook — working sessions on your code are the natural next sessions. Ask anything, any time.
← Lesson 8: Functional core Patterns cheat sheet →