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

CQRS & Domain Events

Command handlers

Every mutating operation is a Command struct carrying an IdempotencyKey (newtype Uuid v4), handled by a CommandHandler in application/commands/.

#![allow(unused)]
fn main() {
pub struct RunInvestigationCommand {
    pub idempotency_key: IdempotencyKey,
    pub objective: String,
    pub config: AgentConfig,
    pub auth: AuthContext,
}
}

Handlers check the idempotency_keys table before executing. Duplicate commands return the cached result without re-running.

Query handlers

Every read operation is a Query struct handled by a QueryHandler in application/queries/. Queries never mutate state.

Domain events

Every significant state transition emits a typed DomainEvent variant:

VariantTrigger
SessionCreatedNew session initialised
AgentStartedInvestigation loop begins
ToolCalledA tool is dispatched
AgentCompletedLoop returns a final answer
WikiEntryWrittenA wiki page is created or updated

Events are immutable value types. Aggregate methods append them to a pending_events: Vec<DomainEvent>; the session store persists them via append_event.