Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Architecture

This page shows how the crate’s components connect and where your domain code fits in.

Component Overview

Your Applicationsourcery crateCommandAggregate DefinitionEvent DefinitionsProjection DefinitionRepositoryEventStoreSnapshotStoreCodec    



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

ApplicationRepository (snapshots enabled)EventStoreAggregateSnapshotStore  execute_command(id, cmd, meta)load(id)?  Optional snapshotload_events(filters)Vec<StoredEvent>replay events (apply)handle(command)Vec<Event>begin transactionappend eventscommitoffer_snapshot()?Ok(())















  1. Optionally load a snapshot to skip replaying old events
  2. Load remaining events from the store
  3. Replay events to rebuild aggregate state
  4. Execute the command handler
  5. Persist new events atomically
  6. Optionally create a new snapshot

Projection Building Flow

ApplicationRepositoryEventStoreProjection  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

TypeRole
Repository<S>Orchestrates aggregates and projections (no snapshots)
Repository<S, C, Snapshots<SS>>Snapshot-enabled repository orchestration
EventStoreTrait for event persistence
SnapshotStoreTrait for aggregate snapshots
CodecTrait for serialization/deserialization
AggregateTrait for command-side entities
ProjectionTrait for read-side views
DomainEventMarker trait for event structs

Next

Installation — Add the crate to your project