Define Domain Elements
DDD CQRS ES
This section covers how to model your business concepts as domain elements in Protean -- aggregates, entities, value objects, events, and the relationships between them.
For the conceptual foundations behind these patterns, see Building Blocks.
What's in This Section
Aggregates
Define your root entities -- the coarse-grained building blocks that encapsulate business logic, enforce invariants, and define transaction boundaries. Start here when modeling a new domain concept.
Entities
Add child objects with unique identity inside an aggregate. Entities are always accessed through their parent aggregate and share its lifecycle.
Value Objects
Model immutable descriptive concepts like Money, Email, or Address. Value objects are defined by their attributes, not identity, and are embedded within aggregates or entities.
Fields
Declare attributes on your domain elements. Pick the right field type, make fields required, set defaults, constrain values, add custom validation, and wire up relationships.
Identity
Configure how aggregate and entity identifiers are generated — UUIDs, integers, user-supplied keys, or a custom function you write yourself.
Relationships
Connect domain elements with HasOne, HasMany, and Reference fields.
Express one-to-one, one-to-many, and cross-aggregate references.
Events
Define domain events -- immutable records of state changes that enable decoupled communication between different parts of your system. Events can be processed synchronously or asynchronously.
Related
- Fields Reference -- All field types, arguments, and definition styles.
- Identity Reference -- Full configuration surface for identity strategies and types.
- Choosing Element Types -- Guidance on when to use an aggregate vs. entity vs. value object.