[][src]Crate cqrs

cqrs

cqrs is an event-driven framework for writing software that uses events as the "source of truth" and implements command–query responsibility separation (CQRS).

The framework is built around a few key concepts:

  • Events: The things that happened in the system
  • Aggregates: Projections of events that calculate a view of the current state of the system
  • Commands: Intentions which, when executed against an aggregate, may produce zero or more events, or which may be prohibited by the current state of an aggregate
  • Reactions: Processes that execute an action when certain events occur in the system

The framework is written to be applicable to a generic backend, with an implementation provided for a PostgreSQL backend.

For an example of how to construct a domain which includes aggregates, events, and commands, look at the cqrs-todo-core crate, which is a simple to-do list implementation.

The source repository also contains a binary in the cqrs-todoql-psql directory which demonstrates the use of the todo domain in concert with the PostgreSQL backend and a GraphQL frontend using the juniper crate.

Modules

memory

A basic, in-memory event stream.

reactor
trivial

Provides a trivial implementation of event/snapshot/entity source/sink/store constructs.

Structs

AlwaysSnapshot

A snapshot strategy that will always recommend taking a snapshot.

BorrowedRawEvent

An owned, raw view of event data.

CompositeEntitySink

Combines an EventSink and a SnapshotSink of different types by reference so that they can be used jointly as an EntitySink.

CompositeEntitySource

Combines an EventSource and a SnapshotSource of different types by reference so that they can be used jointly as an EntitySource.

CompositeEntityStore

Combines an EntitySource and an EntitySink into a single type so that they can be jointly used as an EntityStore.

Entity

An identified, specific instance of a hydrated aggregate.

EventNumber

Represents an event sequence number, starting at 1

NeverSnapshot

A snapshot strategy that will never recommend taking a snapshot.

RawEvent

An owned, raw view of event data.

VersionedAggregate

A structured tuple combining an aggregate and its current version.

VersionedEvent

A structured tuple combining an event number and an event.

VersionedEventWithMetadata

A structured tuple combining an event number and an event.

Enums

Precondition

A precondition that must be upheld for a command to be executed or for events to be persisted.

Since

The starting point when reading a stream of values from an EventSource.

SnapshotRecommendation

A recommendation on whether or not a snapshot should be persisted.

Version

An aggregate version.

Traits

Aggregate

A projected state built from a series of events.

AggregateCommand

A command that can be executed against an aggregate.

AggregateEvent

An event that can be applied to an aggregate.

AggregateId

An identifier for an aggregate.

CqrsError

Represents a common trait that all errors handled by CQRS should implement.

DeserializableEvent

An event that can be deserialized from a buffer.

EntitySink

A sink for persisting an Entity.

EntitySource

A source for loading an Entity.

EntityStore

A generalized entity store that can perform operations on its entities.

Event

A thing that happened.

EventSink

A sink for writing/persisting events with associated metadata.

EventSource

A source for reading/loading events.

Events

An iterable and sliceable list of events.

SerializableEvent

An event that can be serialized to a buffer.

SnapshotSink

A sink for writing/persisting snapshots of aggregates.

SnapshotSource

A source for reading/loading snapshots of aggregates.

SnapshotStrategy

A strategy determining when to recommend a snapshot be taken.

Type Definitions

CommandError

The error produced when this command cannot be executed against an aggregate.

ProducedEvent

The event type produced by this command.

ProducedEvents

The event sequence produced by this command.