Aggregate Block

An aggregate is a consistency boundary. It receives commands, enforces business rules, and emits domain events.

When To Use It

Use an Aggregate block when a group of data and behaviour must stay consistent together. Aggregates are most valuable where the business has rules such as “an order cannot ship until payment is authorized” or “a claim cannot be approved after it is withdrawn.”

Required Data

  • Name: business noun, such as Order, Claim, Subscription, or Route Assignment.
  • Aggregate identity: the identifier used by commands and events.
  • Handled commands: commands this aggregate accepts.
  • Emitted events: events this aggregate can produce.
  • Invariants: rules that must always remain true inside the aggregate.
  • Lifecycle states: allowed states and transitions, if relevant.

Recommended Data

  • Child entities: entities managed inside the aggregate boundary.
  • Value objects: descriptive values used by the aggregate.
  • Concurrency rule: how simultaneous commands should be resolved.
  • Persistence style: current-state storage or event-sourced storage.
  • Ownership: product or engineering owner for the aggregate model.

Connections

Examples

Order Aggregate

  • Handles: Place Order, Cancel Order, Mark Order Paid.
  • Emits: Order Placed, Order Cancelled, Order Paid.
  • Invariant: An order cannot be cancelled after it has shipped.

Appointment Aggregate

  • Handles: Schedule Appointment, Reschedule Appointment, Cancel Appointment.
  • Emits: Appointment Scheduled, Appointment Rescheduled, Appointment Cancelled.
  • Invariant: A clinician cannot be double-booked for the same time range.

Generation Notes

Code Genie uses aggregate definitions to generate domain models, command decision logic, state transitions, event emission, persistence mapping, and tests around invariants. Keep aggregates small enough to protect one consistency boundary, not an entire business department.