Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
aj-geddes avatar

Event Sourcing

  • 843 installs
  • 305 repo stars
  • Updated March 4, 2026
  • aj-geddes/useful-ai-prompts

event-sourcing is a skill that implements versioned domain events, aggregates, and an EventStore with optimistic concurrency in TypeScript for developers who need reliable audit trails and reconstructable application sta

About

event-sourcing is a TypeScript pattern skill from aj-geddes/useful-ai-prompts for building an in-memory EventStore that appends DomainEvent records with aggregateId, aggregateType, eventType, payload data, and versioned metadata. It demonstrates optimistic concurrency via expectedVersion checks before append and defines Aggregate interfaces for replay-based state reconstruction. Developers use event-sourcing when modeling financial ledgers, workflow histories, or collaborative domains that require append-only audit logs instead of destructive updates. The skill ships reference TypeScript interfaces and EventStore methods rather than a specific vendor framework.

  • Implements an in-memory EventStore with optimistic concurrency control
  • DomainEvent interface with aggregate versioning and metadata
  • Aggregate root pattern support for BankAccount and similar entities
  • getEvents and getCurrentVersion query methods for replay
  • Prevents concurrency conflicts during event append operations

Event Sourcing by the numbers

  • 843 all-time installs (skills.sh)
  • +12 installs in the week ending Aug 2, 2026 (Skillselion tracking)
  • Ranked #475 of 4,347 Backend & APIs skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/aj-geddes/useful-ai-prompts --skill event-sourcing

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs843
repo stars305
Security audit3 / 3 scanners passed
Last updatedMarch 4, 2026
Repositoryaj-geddes/useful-ai-prompts

How do you implement event sourcing in TypeScript?

Implement reliable, versioned state changes using event sourcing patterns in TypeScript projects.

Who is it for?

Backend developers adding append-only event logs, audit trails, or reconstructable aggregate state in TypeScript services.

Skip if: Simple CRUD APIs where relational row updates suffice and event replay complexity adds no business value.

When should I use this skill?

User mentions event sourcing, DomainEvent, EventStore, aggregate versioning, or optimistic concurrency in TypeScript.

What you get

TypeScript DomainEvent types, Aggregate models, and EventStore with version-checked append and event replay support.

  • EventStore class
  • DomainEvent types
  • aggregate replay logic

Files

SKILL.mdMarkdownGitHub ↗

Event Sourcing

Table of Contents

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:

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:

GuideContents
Event Store (TypeScript)Event Store (TypeScript)
Projections (Read Models)Projections (Read Models)
Event Store with PostgreSQLEvent Store with PostgreSQL
Snapshots for PerformanceSnapshots 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

Related skills

How it compares

Use event-sourcing for audit-heavy domains; use standard CRUD or ORM skills when mutable rows without event history are enough.

FAQ

What does the event-sourcing skill implement in TypeScript?

event-sourcing provides DomainEvent and Aggregate interfaces plus an EventStore class with appendEvents and optimistic concurrency via expectedVersion. Events carry aggregateId, eventType, data, and timestamped metadata for replay.

When should developers choose event sourcing over CRUD?

event-sourcing fits domains needing immutable audit history and reconstructable state from an append-only log. Skip it when simple row updates meet requirements without replay or version-conflict handling overhead.

Is Event Sourcing safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

Backend & APIsbackendintegrations

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.