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, serialization
The Envelope Pattern
Events travel with metadata, but domain types stay pure:
Event Envelope aggregate_id, kind, correlation_id, timestamp
Domain Event (pure business data)
- 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 deserialize 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> begin transaction append events commit offer_snapshot()? Ok(())
- Optionally load a snapshot to skip replaying old events
- Load remaining events from the store
- Replay events to rebuild aggregate state
- Execute the command handler
- Persist new events atomically
- Optionally create a new snapshot
Projection Building Flow
Application Repository EventStore Projection build_projection() .event::<E1>().event::<E2>() .load() load_events(filters) Vec<StoredEvent> default() apply_projection(id, event, meta) [For each event] Projection
Projections specify which events they care about. The repository loads only those events and replays them into the projection.
Key Types
| Type | Role |
|---|---|
Repository<S> | Orchestrates aggregates and projections (no snapshots) |
Repository<S, C, Snapshots<SS>> | Snapshot-enabled repository orchestration |
EventStore | Trait for event persistence |
SnapshotStore | Trait for aggregate snapshots |
Codec | Trait for serialization/deserialization |
Aggregate | Trait for command-side entities |
Projection | Trait for read-side views |
DomainEvent | Marker trait for event structs |
Next
Installation — Add the crate to your project