Architecture
This page shows how the crate’s components connect and where your domain code fits in.
Component Overview
You define: Aggregates, events, commands, projections
The crate provides: Repository orchestration, store abstraction, serialisation
The Envelope Pattern
Events travel with metadata, but domain types stay pure:
- Aggregates receive only the pure event—no IDs or metadata
- Projections receive the full envelope—aggregate ID and metadata included
- Stores persist the envelope but deserialise only what’s needed
This keeps domain logic free of infrastructure concerns.
Command Execution Flow
Application Repository (snapshots enabled) EventStore Aggregate SnapshotStore execute_command(id, cmd, meta) load(id)? Optional snapshot load_events(filters) Vec<StoredEvent> replay events (apply) handle(command) Vec<Event> commit_events() offer_snapshot()? Ok(())
Projection Loading Flow
Application Repository EventStore Projection load_projection::<P>(&instance_id) P::filters(&instance_id) Filters (event filters + handlers) load_events(filters) Vec<StoredEvent> P::init(&instance_id) apply_projection(id, event, meta) [For each event] Projection
Projections define their event filters centrally in the ProjectionFilters trait. The repository calls filters() to determine which events to load, then replays them into the projection.
Key Types
| Type | Role |
|---|---|
Repository | Orchestrates command execution, aggregate loading, and projection loading |
EventStore | Trait for event persistence |
SnapshotStore | Trait for aggregate/projection snapshots |
Aggregate | Trait for command-side entities |
ProjectionFilters | Base trait for event subscribers (projections) |
Projection | Stable KIND identifier for projection snapshot storage |
ApplyProjection<E> | Per-event handler for projections |
Filters | Builder for event filter specs + handler closures |
DomainEvent | Marker trait for event structs |
For exact generic signatures, see the API docs on docs.rs. This page is intentionally focused on responsibilities and flow.
Next
Installation — Add the crate to your project