Aggregates and the Tools Layer

A conference system has a registration screen that checks everything: ticket type, dietary needs, payment. Then someone adds a quick endpoint that changes a delegate's ticket type directly, because going through the usual path was slower. Six months later the invoices do not match the badges. The bug is not in any one function. A door was left open.

The root is the only door

In DDD, outsiders reach an aggregate only through its root entity. The aggregate is a cluster of objects, such as a registration with its tickets and payments, that must stay consistent together. LVD turns that into a working discipline for the Tools layer. Every root gets its own family of tool handlers, and a tool never manipulates the inner parts of an aggregate that some other root owns.

For the conference system this means tools such as register-delegate, change-ticket-type and cancel-registration all operate on the registration through its root, so the root's rules always run. A tool that edits a ticket row directly would be the open door from the opening story. It would skip the checks the root exists to apply, and nothing in a code review would necessarily flag it, because every individual line looks reasonable. The book points out that this kind of shortcut breaks both the aggregate pattern and Axiom A5, the rule that tools do not depend on one another.

One handler, one aggregate, one transaction

DDD also says a single transaction should modify exactly one aggregate. The Tools layer fits this almost by accident, since each handler already represents one unit of work. The interesting case is an operation that seems to need two aggregates: registering a delegate and holding a seat in a workshop.

LVD's recommendation is a saga. Instead of one large transaction spanning both, you run two separate tool invocations coordinated by domain events:

register-delegate (tool)  ->  DelegateRegistered (event, L1)
        |  picked up by the sessions context
hold-seat (tool)          ->  SeatHeld (event, L1)

Each tool guarantees the consistency of its own aggregate and nothing more. The coordination between them is eventual, driven by events, and explicit, which means you can read it. The price is that you must decide what happens if the second step fails, a question the saga machinery exists to answer; transaction boundaries and sagas covers that side.

What a handler checks beyond the schema

The Schema layer can reject a malformed registration, but some rules need more context than a single record offers. Does the delegate exist? Is the workshop open for this ticket class? Those are aggregate-level business rules, and the tool handler enforces them.

The book's place-order example shows the shape. The handler looks up what it needs through repositories in Resources, computes totals with pure functions from Utils, assembles the aggregate, persists it through the repository and publishes the event, all inside one aggregate-sized transaction. The point it draws out is that the handler stays readable because the complexity is linear: each concern has been delegated to the layer built for it, and the handler only sequences them. A newcomer can open it, follow the steps in order, and see which layer owns each one.

It also answers a review question that otherwise stays vague. When someone proposes a new tool, you can ask which aggregate root it belongs to. If it cannot name one, or if it needs to change two, the design needs another look before any code is written.

The takeaway

Treat the aggregate root as the unit your tools are organised around. One root, a set of tools, one transaction per handler, and events between aggregates. The result is a Tools layer where the question "who may change this?" has a single answer. If the A5 rule behind it is new to you, read Axiom A5, and for the events that tie aggregates together see domain events across layers. The anatomy of a single handler is in the anatomy of a tool.

What the book covers

  • Aggregate roots as the boundary of a set of tool handlers
  • Why a transaction should touch exactly one aggregate and how sagas handle two
  • Consistency rules inside a tool handler, step by step
  • A full place-order handler spread across Schema, Utils, Resources and Tools