backend-event-sourcing
Use when the user asks about event sourcing, storing every change as an append-only event log, event store, rehydrating aggregates, snapshots, upcasting or…
от j4flmao★ 47 звёзд на GitHub
Установить backend-event-sourcing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Backend Event Sourcing
Purpose
Store state changes as an append-only sequence of events. Current state is derived by replaying events. Every event is immutable, auditable, and replayable.
Agent Protocol
Trigger
Exact user phrases: "event sourcing", "event store", "event stream", "event sourced", "rehydrate from events", "event replay", "projection rebuild", "append-only log", "event history", "event store pattern".
Input Context
- Domain aggregates and their state changes.
- Event store technology (PostgreSQL, EventStoreDB, DynamoDB).
- Projection requirements (read models, search indexes, materialized views).
Output Artifact
Event sourcing design as text. No file unless requested.
Response Format
Aggregate: {name}
Events: [{EventName, version, key fields}]
Current state: {derived by replay}
Projections: [{name, rebuild from}]
Completion Criteria
- All state changes are captured as events (not just some).
- Event store is append-only — no updates or deletes.
- Aggregate state can be rebuilt by replaying all events.
- Projections can be rebuilt from scratch by replaying all events.
- Events are immutable and carry version number.
- Event schema includes metadata (eventId, aggregateId, version, timestamp).
- Snapshot strategy defined for aggregates with many events.
Max Response Length
Per aggregate: 8 lines. Full design: 35 lines.
Architecture Decision Tree
Should I Use Event Sourcing?
Does the full history of changes matter?
├── Yes → Audit, compliance, dispute resolution → Event Sourcing candidate
└── No → Is state derivation logic complex?
├── Yes → Event Sourcing simplifies temporal queries
└── No → Are multiple projections of the same data needed?
├── Yes → Event Sourcing enables flexible projections
└── No → Simple CRUD is sufficient — skip Event Sourcing
Event Store Selection
What infrastructure is already available?
├── PostgreSQL → Great event store (JSONB for event data, reliable, transactional)
├── EventStoreDB → Purpose-built for event sourcing (projections built-in)
├── DynamoDB → Serverless, single-table design for event streams
└── Kafka → Durable log, but limited query capabilities for aggregate reconstruction
Snapshot Strategy
How many events per aggregate?
├── < 100 → No snapshots needed
├── 100-1000 → Snapshot every 50 events
├── 1000-10000 → Snapshot every 100 events
└── > 10000 → Snapshot every 500 events, consider splitting aggregate
Workflow
Step 1: Identify Event-Sourced Aggregates
Choose aggregates where:
- The full history of changes matters (audit, compliance, dispute resolution).
- The state derivation logic is complex and benefits from replay.
- Multiple projections of the same data are needed.
- Temporal queries ("what was the state at time X?") are required.
Step 2: Define Events
interface OrderPlaced {
eventType: 'OrderPlaced';
version: 1;
data: { orderId: string; customerId: string; items: OrderItem[]; total: number };
metadata: { eventId: string; aggregateId: string; version: number; timestamp: Date; correlationId: string };
}
interface PaymentReceived {
eventType: 'PaymentReceived';
version: 1;
data: { orderId: string; amount: number; paymentMethod: string; transactionId: string };
}
interface OrderShipped {
eventType: 'OrderShipped';
version: 1;
data: { orderId: string; trackingNumber: string; carrier: string };
}
Step 3: Implement Aggregate (Event Replay)
class OrderAggregate {
private state: OrderState = { status: 'pending', items: [], total: 0, payments: [] };
static loadFromHistory(events: Event[]): OrderAggregate {
const aggregate = new OrderAggregate();
for (const event of events) {
aggregate.apply(event);
}
return aggregate;
}
placeOrder(command: PlaceOrderCommand): OrderPlacedEvent {
if (this.state.status !== 'pending') throw new Error('Order already placed');
return { eventType: 'OrderPlaced', version: 1, data: { ...command }, metadata: this.createMetadata() };
}
applyEvent(event: OrderPlacedEvent): void {
this.state = { status: 'placed', items: event.data.items, total: event.data.total, payments: [] };
}
applyEvent(event: PaymentReceivedEvent): void {
this.state.payments.push({ amount: event.data.amount, method: event.data.paymentMethod });
if (this.totalPaid() >= this.state.total) {
this.state.status = 'paid';
}
}
}
class OrderAggregate:
def __init__(self):
self.state = OrderState(status="pending", items=[], total=0, payments=[])
@classmethod
def load_from_history(cls, events: list[Event]) -> "OrderAggregate":
aggregate = cls()
for event in events:
aggregate.apply(event)
return aggregate
def place_order(self, command: PlaceOrderCommand)
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/aggregate-design.md
- references/aggregate-reconstruction.md
- references/event-sourcing-advanced.md
- references/event-sourcing-fundamentals.md
- references/event-sourcing-projections.md
- references/event-sourcing-snapshots.md
- references/event-sourcing-testing.md
- references/event-store-patterns.md
- references/event-versioning.md
FAQ
Что делает скилл backend-event-sourcing?
Use when the user asks about event sourcing, storing every change as an append-only event log, event store, rehydrating aggregates, snapshots, upcasting or projection rebuilds. Produces an event-sourced aggregate and store design. Not for CQRS without event sourcing (use backend-cqrs-patterns).
Как установить скилл backend-event-sourcing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл backend-event-sourcing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
frontend-design
AnthropicGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making…
webapp-testing
AnthropicToolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing…
brand-guidelines
AnthropicApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand…
web-artifacts-builder
AnthropicSuite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use…