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 DefinitionRepositoryEventStoreSnapshotStore    



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

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













Projection Loading Flow

ApplicationRepositoryEventStoreProjection  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

TypeRole
RepositoryOrchestrates command execution, aggregate loading, and projection loading
EventStoreTrait for event persistence
SnapshotStoreTrait for aggregate/projection snapshots
AggregateTrait for command-side entities
ProjectionFiltersBase trait for event subscribers (projections)
ProjectionStable KIND identifier for projection snapshot storage
ApplyProjection<E>Per-event handler for projections
FiltersBuilder for event filter specs + handler closures
DomainEventMarker 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