Skip to main content
Welcome to ddd_cqrs_es! This library is a lightweight, high-performance Rust framework designed to help you construct highly reliable, testable, and maintainable software systems using the combined power of Domain-Driven Design (DDD), Command Query Responsibility Segregation (CQRS), and Event Sourcing (ES). The distinguishing design philosophy of this framework is that it is completely infrastructure-light. Your core domain logic—the rules that govern how your business operates—is kept entirely free of dependencies on databases, serialization formats, web frameworks, or asynchronous runtimes.

🚀 Installation

Add the crate as a dependency in your Cargo.toml:

Feature Flags

Our framework is highly modular. You can enable specific adapters and engines depending on your production requirements.

Enabling Durable Database Adapters:

  • SQLite Support: Enable the "sqlite" feature (uses the rusqlite driver under the hood).
  • PostgreSQL Support: Enable the "postgres" feature (uses the postgres driver under the hood).
  • MySQL Support: Enable the "mysql" feature (uses the mysql driver under the hood).
  • Spin MySQL Helper: Enable "spin-mysql" for Spin SDK MySQL query execution.

Supported Backends:

  • SQLite / Local File: Standard local embedded SQL.
  • PostgreSQL: Stable high-performance relational database.
  • MySQL: High-performance relational database with native stores plus a Spin runtime query helper ("spin-mysql").
  • LibSQL / Turso: Supported for distributed edge SQL via the "wasi-libsql" query helper.
  • Redis: Supported for async event store, checkpoints, and pub/sub notifications via "redis" / "wasi-redis" / "spin-redis".

Realtime and Notification Support:

The root crate provides durable stores, checkpoints, idempotency stores, and notification primitives. HTTP streaming is application-owned.
  • PostgreSQL / SQLite / MySQL: Use durable events and checkpoints to drive polling, SSE, WebSocket, or worker pipelines in your application.
  • Redis: Provides experimental async persistence plus notification-only pub/sub wake messages. Durable replay remains the source of truth.
  • MySQL: MySQL does not provide a built-in pub/sub stream in this library; pair it with Redis, an outbox worker, binlog CDC, NATS, Kafka, or WebSocket fan-out when low-latency push notifications are required.

API Notes:

  • Aggregates are loaded by the repository using the external stream ID; the Aggregate trait does not require an id() method.
  • EventType is a serde-transparent newtype. Convert it with as_str() or into_string() when a database, UI, or protocol needs a plain string.
  • SqlSchemaConfig table-name builders validate eagerly and return Result.
  • Process managers can be coordinated by ProcessManagerRunner or AsyncProcessManagerRunner.
  • execute_idempotent(...) is portable but not crash-atomic across separate stores. Use execute_idempotent_atomic(...) with native SQL stores for production request idempotency.

⚡ Quick 10-Second Example

Here is how simple it is to initialize our write path, tie it to an in-memory event ledger, and execute a transactional command:

🗺️ How to Navigate This Documentation

We structured our guides as a structured, chronological path designed to take you from a complete beginner to building full-scale, distributed production applications:

Start with the CLI: ddd CLI

  • What you’ll learn: Install the ddd command, scaffold a new app with ddd init, add domain events and commands with ddd add, enable Redis/gRPC/tracing capabilities, run Spin-focused apps, and use dry-run JSON for agent/MCP workflows.

Module 1: The Patterns (Theory)

Module 2: Domain Modeling (Tutorial)

  • What you’ll learn: Build a fully validated Bank Account domain step-by-step. Implement Commands, Events (implementing DomainEvent), Errors (handling invariants), and the core Aggregate Root struct.

Module 3: Domain Tests

  • What you’ll learn: Write bulletproof business validations in microseconds. Learn why Event Sourcing is a unit-testing superpower and write elegant Given-When-Then tests using the Aggregate Test Fixture API.

Module 4: Configuring an Application

Module 5: Building an Application (Production)

Module 6: Fullstack SaaS (Spin + wasi-auth)

Module 7: Leptos WASM SSR + Spin CQRS and Runtimes

  • What you’ll learn: The counter-style implementation path (domain → Spin storage → projections → server APIs → UI → backends → execution), then Wasmtime vs Spin deployment trade-offs.
For documentation site navigation (which public pages are registered), see docs/docs.json. Internal roadmap and PRD notes under docs/prd/ and docs/PRD.md stay in the repo for maintainers and are not published in the sidebar.