HomeChallengesRepsProblemsLeaderboardTake a challenge

The Aggregate Boundary

An order with lines. Decide what is a root, what is inside it, and what rule belongs to neither — then make it impossible to reach a line without going through the order.

Advanced25 min on the clock5 graded checks · 100 pointsLayered Architecture and Modular SystemsPro
Graded by reading your code against the checklist below.

What you build

  • Order as an aggregate root with a private line collection
  • OrderLine as an entity inside the aggregate, not a root
  • One repository, for the root only
  • A rule spanning two aggregates in a DomainService
  • A domain event raised by the aggregate that knows it happened

Done means

Nothing outside the aggregate can construct or modify an OrderLine.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. Order is an aggregate root with a private collection+25Aggregates and boundaries
  2. OrderLine is an entity inside the aggregate, not a root+20Aggregates and boundaries
  3. A repository for the root, and only the root+20Aggregates and boundaries
  4. A cross-aggregate rule lives in a DomainService+20Aggregates and boundaries
  5. The aggregate raises its own event+15Aggregates and boundaries

What it teaches

Aggregates and boundariesadvanced

An aggregate root is the only door into a cluster of objects, and keeping that door the only one is what makes an invariant like "the total always matches the lines" true by construction rather than by discipline.

The rest of Layered Architecture and Modular Systems