event-driven
CQRS and Event Sourcing for Spring Boot 4.x - command and query handlers, read models updated from domain events, transactional outbox with Apache Kafka or in-process events with Spring Modulith, an append-only PostgreSQL event store with aggregates rebuilt from events, upcasting and rebuildable projections, or Axon Framework, as separate command and query services or a single service. Use when the architecture block in the project's CLAUDE.md or AGENTS.md names the cqrs or cqrs-event-sourcing style, or when the user asks for CQRS, Event Sourcing, an event store, an outbox, projections or read models.
- Star
- 1,473
- 分类
- 数据
- 许可证
- Apache-2.0
- 最近提交
- 2026年11月27日
skills/event-driven/SKILL.md
在 GitHub 上查看Event-Driven Skill
CQRS for Spring Boot 4.x: the write side and the read side are separate models, and the read side is updated from domain events. With Event Sourcing the write side stores those events instead of the current state.
When to Use
Load this skill only when the architecture decision (conventions skill, "Architecture Decision") is not layered CRUD:
- The project's
CLAUDE.md(AGENTS.mdin Codex and OpenCode) hasstyle: cqrsorstyle: cqrs-event-sourcingin its## Architectureblock. - The user asks for CQRS, Event Sourcing, an event store, a transactional outbox, projections or read models.
A project without the block is layered CRUD: do not apply this skill to it, and do not start the dialog here. The dialog and the block belong to conventions.
What Is Supported
| Style | Status |
|---|---|
| Layered CRUD | Default; this skill does not apply |
| CQRS (no event sourcing) | Supported: references/cqrs.md |
| CQRS + Event Sourcing (PostgreSQL event store) | Supported: references/event-sourcing.md |
| CQRS + Event Sourcing (Axon Framework) | Supported as a procedure: references/axon.md. The code comes from the Axon reference of the version selected for the project |
CQRS or Event Sourcing for an API built for a UI (spring-boot skill, references/ui-contract.md) | Not yet supported |
For a style that is not yet supported, say so and stop. Do not approximate it with another style, and never use Kafka as an event store.
Core Workflow
- Read the decision -
style,scope,topology,transport,read-storeand, for Event Sourcing,event-storefrom the architecture block. Aggregates outsidescopestay layered CRUD. - Lay out the project - modules or packages from
references/topology.md. - Write side - entity, migration, command records, one handler per command, command controller (
references/cqrs.md). - Events - one sealed interface per aggregate, records that carry the new state and the
version. - Transport - the outbox and its relay for Kafka (
references/kafka.md), or the Spring Modulith event publication registry for in-process events (references/cqrs.md). - Read side - read-model table and migration, projection, query records, one handler per query, query controller.
- Test -
references/testing.md; run./mvnw clean verifyand confirm the integration tests ran. - Tell the user what eventual consistency means for their API: a query right after a command may return the old state.
With style: cqrs-event-sourcing, steps 3 to 6 follow references/event-sourcing.md: event store and migration, events, a plain aggregate that returns events, handlers that load, decide and append, then projections with a checkpoint. With event-store: axon, follow references/axon.md from its first step, before any code.
Reference Guide
| Topic | Reference | When to Load |
|---|---|---|
| Topology | references/topology.md | Always: modules, packages, databases, Compose, deployment, CI |
| CQRS rules | references/cqrs.md | Always: commands, queries, handlers, read models; for style: cqrs also events, projections, in-process events; review signals |
| Event Sourcing | references/event-sourcing.md | style: cqrs-event-sourcing: event store, events and upcasting, aggregates, handlers, projections with checkpoints, snapshots, personal data, review signals |
| Axon Framework | references/axon.md | event-store: axon: version selection, event store question, what Axon replaces, what still applies |
| Kafka | references/kafka.md | transport: kafka: outbox, relay, topics, consumers, dead-letter topic; relay from the event store for Event Sourcing |
| Testing | references/testing.md | Always: handler, outbox, projection and end-to-end tests; aggregate, event store and upcaster tests for Event Sourcing |
Constraints
MUST DO
- Commands and queries are records; one handler class per command or query
- Events are immutable records under one sealed interface per aggregate, named in the past tense
- CQRS: the write side keeps JPA,
@Versionand 409 on a staleversion(jpa-patternsskill, Optimistic Locking); every event carries the aggregate id, the aggregate'sversionand its state after the change - Event Sourcing: aggregates have no JPA mapping, are rebuilt from their events, and return new events from a command; a version conflict on append is 409
- Projections are idempotent: by the event's version (CQRS) or by a checkpoint moved in the read model's transaction (Event Sourcing), and they can be rebuilt
- With Kafka, events leave the write side only through the transactional outbox, or through the relay of the event store
- Query endpoints return
<Resource>Responserecords in aPagedModel, with theversiona client sends back on an update - Flyway owns every table, including the outbox, the event store and the Spring Modulith event publication table
- All rules of the
conventionsskill that the architecture decision does not replace
MUST NOT DO
- Publish to Kafka from a command handler, a controller or any class other than the relay
- Let
queryorprojectioncode depend oncommandcode or on the write-side entities - Let the query service call the command service, or depend on its module
- Return a JPA entity, a
Pageor a read model from a command endpoint - Change or remove a field of an event that is already published; Event Sourcing evolves events with a new type and an upcaster
- Update or delete a row of the event store
- Put personal data into an event payload without an erasure strategy documented in the README
- Add snapshots without a measured load problem
- Update a read model in the command's transaction
- Use Kafka as the source of truth: the write database is, and the topic only replays events for projections
相似的 Skill
health
GAgarrytan/gstack143k近 7 天新增 524 个 star
deprecation-and-migration
ADaddyosmani/agent-skills122k近 7 天新增 1,421 个 star
ccs-align
THthedotmack/claude-mem121k近 7 天新增 1,354 个 star
handoff
THthedotmack/claude-mem121k近 7 天新增 1,354 个 star
knowledge-agent
THthedotmack/claude-mem121k近 7 天新增 1,354 个 star