Skip to main content
skill CX Codex

event-sourcing — Claude Code skill: events, CQRS, audit trails

A skill that guides your coding agent through event sourcing and CQRS: an event store, aggregates, projections and snapshots. Useful when you need a full change history and queries against past state.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a claude-code
Open on GitHub

What event-sourcing does

The skill covers storing state as a sequence of events instead of a single current row. That gives you audit trails, temporal queries and event replay. A short TypeScript example shows the DomainEvent and Aggregate interfaces plus an EventStore class with an appendEvents method, and the full implementations live in the references/ directory.

Four reference guides are listed: a TypeScript event store, projections as read models, an event store on PostgreSQL, and snapshots for performance. A best-practices section spells out the do's and don'ts: keep events immutable, version them, use optimistic concurrency, never mutate past events, and never read from the event store to serve queries.

This is a design guide with code samples, not a library you import. If your project already leans on an ORM with mutable entities, expect to rework that part, because events are append-only and reads go through projections. Worth checking whether your database and deploy setup handle that write pattern.

What it helps with

  • build an audit trail per aggregate
  • read an object's state at any point in time
  • split event writes from reads through projections
  • add snapshots so long histories are not replayed
  • evolve an event schema without losing old records

Example prompts for the agent

  • Design an event store for orders: aggregate, events, optimistic concurrency on version
  • Show me how to build a read projection for the order list on PostgreSQL
  • Add snapshots for an aggregate with a long event history

How to install event-sourcing

1Skills CLI (Vercel)

npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a claude-code

2Manually: put the files in place

~/.claude/skills/event-sourcing/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/event-sourcing/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about event-sourcing

How do I install event-sourcing in Claude?

Run npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a claude-code. The skill file then sits at ~/.claude/skills/event-sourcing/SKILL.md.

What does event-sourcing do?

It walks through event sourcing and CQRS: keeping changes as events, rebuilding aggregates, and deriving read models through projections. It ships a TypeScript example and links to longer implementations.

Does it require a specific database?

No, the approach is not tied to one database. One of the reference guides covers an event store on PostgreSQL, and the remaining examples are written in TypeScript.

Source text

SKILL.md · MIT
---
name: event-sourcing
description: >
  Implement event sourcing and CQRS patterns using event stores, aggregates, and
  projections. Use when building audit trails, temporal queries, or systems
  requiring full history.
---

# Event Sourcing

## Table of Contents

- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)

## Overview

Store state changes as a sequence of events rather than the current state, enabling temporal queries, audit trails, and event replay.

## When to Use

- Audit trail requirements
- Temporal queries (state at any point in time)
- Event-driven microservices
- CQRS implementations
- Financial systems
- Complex domain models
- Debugging and analysis
- Compliance and regulation

## Quick Start

Minimal working example:

```typescript
interface DomainEvent {
  id: string;
  aggregateId: string;
  aggregateType: string;
  eventType: string;
  data: any;
  metadata: {
    userId?: string;
    timestamp: number;
    version: number;
  };
}

interface Aggregate {
  id: string;
  version: number;
}

class EventStore {
  private events: DomainEvent[] = [];

  async appendEvents(
    aggregateId: string,
    expectedVersion: number,
    events: Omit<DomainEvent, "id" | "metadata">[],
// ... (see reference guides for full implementation)
```

## Reference Guides

Detailed implementations in the `references/` directory:

| Guide | Contents |
|---|---|
| [Event Store (TypeScript)](references/event-store-typescript.md) | Event Store (TypeScript) |
| [Projections (Read Models)](references/projections-read-models.md) | Projections (Read Models) |
| [Event Store with PostgreSQL](references/event-store-with-postgresql.md) | Event Store with PostgreSQL |
| [Snapshots for Performance](references/snapshots-for-performance.md) | Snapshots for Performance |

## Best Practices

### ✅ DO

- Store events immutably
- Version your events
- Use optimistic concurrency
- Create snapshots for performance
- Use projections for queries
- Keep events small and focused
- Include metadata (timestamp, user, etc.)
- Handle event versioning/migration

### ❌ DON'T

- Mutate past events
- Store current state only
- Skip concurrency checks
- Query event store for reads
- Make events too large
- Forget about event schema evolution

© aj-geddes · MIT · aj-geddes/useful-ai-prompts

Similar skills

Everything for Backend and APIs →

From the same set118

penetration-testing Security testing skill that guides ethical hacking, simulated attacks, and vulnerability documentation across applications and infrastructure. CX Codex +1 1,100installs responsive-web-design A skill that steers your coding agent toward mobile-first CSS with Flexbox, Grid and media queries. Useful when one layout has to hold up on phones and desktops. CX Codex +1 1,100installs css-architecture A skill that gives your coding agent conventions for structuring CSS with BEM, SMACSS and CSS-in-JS. Handy when stylesheets outgrow the naming scheme you started with. CX Codex +1 959installs api-contract-testing Verifies API contracts between consumers and providers without full integration tests. Helps stop breaking schema changes before deploying microservices. CX Codex +1 913installs root-cause-analysis A skill that walks an incident down to the cause you can actually fix, instead of patching the symptom again. CX Codex +1 884installs mobile-first-design A skill that sets the order of UI work: design the phone screen first, then scale to tablet and desktop. Useful when layouts break on small devices. CX Codex +1 857installs mobile-app-testing Provides testing guidelines for iOS and Android apps. Covers unit, UI, and performance tests using Jest, Detox, Espresso, and XCTest. CX Codex +1 823installs technical-specification Gives your agent a structure for technical specs, PRDs, ADRs and RFCs: requirements, architecture, acceptance criteria. Useful before you start coding a feature. CX Codex +1 804installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor