Nw Ddd Eventsourcing logo

Nw Ddd Eventsourcing

Organization
nWave-ai
nw-ddd-eventsourcing

Event Sourcing and CQRS as DDD implementation patterns — when to use, aggregate event streams, projections, snapshots, sagas, upcasting, conflict resolution

Overview

PublishernWave-ai
RepositorynWave
Skill namenw-ddd-eventsourcing
Stars
616
Forks
65
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by nWave-ai on GitHub. Read the source before you install it.

Installation

Install the Nw Ddd Eventsourcing AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/nWave-ai/nWave/tree/main/nWave/skills/nw-ddd-eventsourcing
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/nWave-ai/nWave.git /tmp/nWave
mkdir -p .claude/skills
cp -r /tmp/nWave/nWave/skills/nw-ddd-eventsourcing .claude/skills/nw-ddd-eventsourcing
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Nw Ddd Eventsourcing in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Nw Ddd Eventsourcing on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Nw Ddd Eventsourcing is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Event Sourcing and CQRS

Implementation patterns for DDD. Event Sourcing stores every state change as an immutable event and derives current state from replay. CQRS separates write and read models. These are tools, not mandatory architecture -- apply selectively to domains where they add value.

When to Use Event Sourcing

ES adds value when:

  • Complete audit trail required (financial, regulatory, medical)
  • Temporal queries needed ("what was the state on January 15?")
  • Multiple views of same data (different read models for different consumers)
  • Complex domain with rich business rules (natural fit with DDD aggregates)
  • Event-driven integration with other systems
  • Debugging requires replay ("what exactly happened?")

ES is overkill when:

  • Simple CRUD with no audit requirements
  • Team unfamiliar and project has no learning budget
  • No business value from history
  • Domain has no behavior (data in, data out)

Key question: "Does knowing the history of how we got here provide business value?" Yes -> consider ES. No -> traditional CRUD is simpler.

Core Concepts

Events as Facts

Events are immutable records of things that happened. Past tense: OrderPlaced, PaymentReceived, ItemShipped.

Event structure: Include all data needed to understand what happened (self-contained) | Use domain language | One event per meaningful business fact | Events carry data only, no behavior

Granularity: Too coarse (OrderUpdated { order: {...} }) loses what changed. Too fine (OrderFieldChanged { field, old, new }) is generic audit log. Just right (OrderConfirmed { orderId, confirmedBy, confirmedAt }) has clear business meaning.

The Event Store

Single source of truth. Core operations:

  • append(streamId, expectedVersion, events) -> success or concurrency conflict
  • read(streamId) -> ordered list of events
  • subscribe(filter) -> push notification for new events

Properties: Append-only (never modify/delete) | Ordered within stream | Immutable | Versioned (each event has position)

Stream identity: Each aggregate instance owns a stream: Order-123, Customer-789. The stream ID is the aggregate ID.

Aggregate Event Lifecycle

  1. Receive command -> validate business rules
  2. Emit events -> record what happened
  3. Apply events -> update internal state (no validation, no side effects)
  4. Persist events -> append to event store

Loading (rehydration): Read all events from stream -> create empty aggregate -> apply each event in order -> aggregate in current state, ready for commands.

CQRS Split

AspectWrite Side (Commands)Read Side (Queries)
PurposeValidate + change stateServe information
ModelAggregates (normalized)Projections (denormalized)
OptimizationConsistency, correctnessQuery speed, UX
ScaleLower throughput typicallyHigher throughput
TechnologyEvent storeAny DB (SQL, NoSQL, search, graph)

Data flow: Command -> Aggregate -> Event Store -> Projection -> Read Model -> Query

Key Patterns

Projections and Read Models

Projections transform events into query-optimized views. Properties: disposable (rebuild from event store anytime) | eventually consistent (lag between event and update) | purpose-specific (one per use case) | multiple (same events feed many views)

Types: Live (real-time as events arrive) | Catch-up (replay from beginning, then switch to live) | One-off (replay once for analytics/migration)

Rebuilding: Delete read model -> replay all events from position 0 -> switch to live processing. This is a superpower: add new views retroactively from complete history.

Snapshots

For aggregates with thousands of events, periodically save state snapshot. On load: load latest snapshot + replay only events after snapshot. Fewer events to process.

When: After every N events (e.g., 100) or when load time exceeds threshold. Don't snapshot prematurely -- most aggregates have <100 events and load in milliseconds.

Sagas and Process Managers

Business processes spanning multiple aggregates. A saga listens for events and issues commands to coordinate multi-step processes.

Key principles: React to events, issue commands (no business logic in saga) | Maintain process state (which step completed) | Handle compensation (rollback on failure) | Keep simple -- complex saga = design smell

Todo Pattern (alternative): Model process as a "todo list" aggregate tracking what needs to be done. All state visible in one place, progress queryable, easy to add/remove steps.

Upcasting (Event Versioning)

Events are immutable, but schemas evolve. Transform old formats to new during loading.

Weak schema (start here): Flexible format (JSON), handle missing fields with defaults.

Explicit upcaster: Transform V1 -> V2 in a pipeline during event loading, before reaching aggregate/projection.

Upcaster chain: V1 -> V2 -> V3. Each handles one version jump. Test all paths.

Conflict Resolution

Two concurrent commands on same aggregate cause version conflict. Strategies: Retry (default, reload and re-execute) | Merge (domain-specific, both changes apply) | Reject (inform user, safest for critical operations). Start with retry -- most conflicts resolve automatically.

Eventual Consistency

Read side lags write side. Typical: microseconds (same process) to low seconds (across network).

Mitigation: Read-your-own-writes (return command result directly, not from read model) | Optimistic UI (apply expected change on client immediately) | Causal consistency (version token with queries, wait until projection catches up)

Additional Patterns

Reservation Pattern: Enforce uniqueness constraints (unique email) using dedicated reservation aggregate or DB constraint. Uniqueness in ES is harder than CRUD -- choose strictness based on criticality.

Outbox Pattern: Atomically update event store AND publish to message broker by writing to outbox table in same transaction. Relay process publishes to broker asynchronously.

Decider Pattern: Purely functional aggregate: decide(Command, State) -> List<Event>, evolve(State, Event) -> State, initialState() -> State. Trivially testable, framework-agnostic.

Tombstone Events: Handle deletion in append-only store by emitting a tombstone event. Aggregate refuses commands after tombstone. For GDPR: crypto-shredding or event replacement.

Event-Carried State Transfer: Include relevant data in events even if duplicated from other aggregates. Self-contained events eliminate callback lookups for projections.

Temporal Queries: Replay events up to a timestamp to reconstruct historical state. Impossible with traditional state-based storage. Use for: compliance, debugging, analytics, dispute resolution.

Technology Options

TechnologyPlatformNotes
EventStoreDBAny (gRPC)Purpose-built, native projections, by Greg Young
Axon Server/FrameworkJava/KotlinFull CQRS/ES framework with command/query bus
Marten.NET (C#)PostgreSQL as event store + document DB
PostgreSQL (manual)AnyAppend-only table with indexing -- simple but manual
Eventuous.NET (C#)Lightweight modern .NET ES framework

Testing Strategy

Given/When/Then is the primary pattern:

GIVEN: [prior events that set up state]
WHEN:  [command being issued]
THEN:  [resulting events OR error]

Testing pyramid: Value Objects (base) -> Aggregate G/W/T (bulk) -> Projection tests -> Saga tests -> E2E (few)

Implementation maps directly from Event Model specifications to test code. The specification IS the test.

Frequently asked questions

What does the Nw Ddd Eventsourcing AI skill do?

Event Sourcing and CQRS as DDD implementation patterns — when to use, aggregate event streams, projections, snapshots, sagas, upcasting, conflict resolution

Why use Nw Ddd Eventsourcing on TypingMind?

Because you install it once and use it with any model. Nw Ddd Eventsourcing is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Nw Ddd Eventsourcing in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/nWave-ai/nWave/tree/main/nWave/skills/nw-ddd-eventsourcing. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Nw Ddd Eventsourcing?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Nw Ddd Eventsourcing?

As many as you like. As long as a model supports skills, you can use Nw Ddd Eventsourcing with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Nw Ddd Eventsourcing AI skill free?

Yes. It is published on GitHub by nWave-ai under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇