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.
npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a claude-codeWhat 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-code2Manually: put the files in place
~/.claude/skills/event-sourcing/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/event-sourcing/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a codex2Manually: put the files in place
.agents/skills/event-sourcing/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a cursor2Manually: put the files in place
.cursor/skills/event-sourcing/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install aj-geddes/useful-ai-prompts event-sourcing2Manually: put the files in place
.github/skills/event-sourcing/SKILL.md1Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a gemini-cli2Platform CLI
gemini skills install https://github.com/aj-geddes/useful-ai-prompts --path skills/event-sourcingManually: put the files in place
.devin/skills/event-sourcing/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add aj-geddes/useful-ai-prompts --skill event-sourcing -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
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