Skip to main content

Module workflow

Module workflow 

Source
Expand description

Workflow trait, EventPayload, CommandPayload, and CommandContext.

§Design contract

Workflows are pure state machines:

  • Workflow::apply folds a domain event into the current state.
  • Workflow::handle validates a command against the current state and returns the events to emit. It has no I/O, no side effects, and no clock access. The same state + command always produce the same events.

All I/O (parsing raw bytes, calling external services) must happen before the command is constructed and passed to the write path. This keeps workflows deterministic and trivially replayable.

§Serialization boundary

Domain events must implement serde::Serialize and serde::de::DeserializeOwned so the engine can persist them as JSON inside EventEnvelope::payload. The EventPayload trait adds a stable event_type discriminant for projection routing.

§Write path

The public write path is Process::execute / Process::execute_with. These delegate to the crate-internal execute_command function. Direct use of execute_command is intentionally not part of the public API; use Process instead.

Structs§

CommandContext
Contextual metadata attached to every command dispatch.
WorkflowOutput
The combined output of Workflow::handle: domain events and optional outbox messages to be atomically co-persisted.

Traits§

CommandPayload
Marker trait for domain command types.
EventPayload
Marker trait for domain event types.
Workflow
A versioned, deterministic domain workflow.