Skip to content

Building Blocks

Building blocks are the tactical patterns of Domain-Driven Design: the concrete elements you use to model, enforce, and evolve business logic in code. Protean provides a decorator-driven element for each pattern, so you can focus on domain semantics rather than infrastructure code.

The elements are organized into four layers, each with a distinct responsibility.

Flowchart

Domain Model

The domain model holds the business logic of the system. It captures the essential complexity of the business in code: the concepts, rules, and relationships that the software exists to serve.

Element Purpose
Aggregate Root entity and transaction boundary for a cluster of objects
Entity Object with unique identity, always accessed through its aggregate
Value Object Immutable, identity-less object defined entirely by its attributes
Domain Service Stateless operation that spans multiple aggregates

Application Layer

The application layer receives requests from the external world and passes them to the domain model. It translates intentions into domain operations without containing business logic itself.

Element Purpose
Application Service Coordinates a use-case by orchestrating aggregates and domain services
Command Immutable DTO expressing an intent to change state
Command Handler Receives a command, loads the aggregate, invokes domain logic, and persists

Reactive Layer

The reactive layer responds to things that have already happened. Reactive elements propagate state changes, maintain read models, and connect to external systems. None of this work couples back to the code that produced the original change.

Element Purpose
Event Immutable fact recording a state change in the domain
Event Handler Reacts to domain events with side effects and cross-aggregate coordination
Process Manager Stateful coordinator for multi-step processes spanning multiple aggregates
Projection Read-optimized, denormalized view of domain data
Projector Specialized handler that keeps a projection in sync with domain events
Query Immutable, validated read intent targeting a projection
Query Handler Processes named read intents and returns results from projections
Subscriber Consumes messages from an external message broker

Persistence

Persistence elements separate the domain model from storage technology, so aggregates do not depend on how and where they are stored.

Element Purpose
Repository Collection-oriented interface to persist and retrieve aggregates