/ddd-skills:ddd-cqrs-architecturefrom ddd-skills
Guides CQRS adoption across L1/L2/L3 levels with Event Sourcing, idempotency, domain event lifecycle, and integration patterns for Layered/Onion/Hexagonal/Clean/COLA architectures.
Ships in ddd-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
CQRS (Command Query Responsibility Segregation) — L1/L2/L3 adoption, Event Sourcing, idempotency, integration with 5 DDD architectures.
Trigger keywords: CQRS, 读写分离, Event Sourcing, 事件溯源, Command Bus, Query Model, 领域事件, domain event, 幂等, idempotency, eventual consistency, projection, materialized view
Step 1: 判断是否需要 CQRS → 确认读写模式是否显著分化
Step 2: 选择 CQRS 级别 → L1/L2/L3
Step 3: 设计命令模型 → Command → Handler → 领域事件
Step 4: 设计查询模型 → Query → Handler → DTO
Step 5: 实现事件同步(L2/L3)→ Outbox → 发布器 → 投影
Step 6: 按架构集成 → 根据 Layered/Onion/Hexagonal/Clean/COLA
CRUD 够用(读=写) → 单模型,无需 CQRS
↓
L1 模型分离 → CommandService / QueryService 分离,共享 DB
↓
L2 数据库分离 → Command DB + Query DB,事件同步
↓
L3 Event Sourcing → EventStore + Projection
| 场景 | 替代方案 |
|---|---|
| 简单 CRUD,读=写 | 单模型,不引入 CQRS |
| 原型/一次性项目 | 跳过 CQRS |
| 团队不熟悉事件驱动 | 先用 ddd-event-storming 建立事件思维 |
| 强一致性要求极高 | 评估分布式事务成本 |
| 维度 | 命令侧(Write) | 查询侧(Read) |
|---|---|---|
| 职责 | 处理状态变更,执行业务规则 | 返回数据视图,无业务逻辑 |
| 模型 | Command Model(命令对象+聚合根) | Query Model(DTO+物化视图) |
| 存储 | Write DB (3NF, ACID) | Read DB (反范式, 查询优化) |
| 一致性 | 强一致性(聚合内) | 最终一致性(跨聚合/服务) |
| 输出 | 领域事件 | DTO / View Model |
成本最低:仅代码层分离 Command/Query Service,共享数据库。适用于读写数据结构相同但逻辑分离的场景。
参考示例: examples/06-order-l1-model-separation.md
中等成本:分离 Command DB 和 Query DB,通过领域事件同步。适用于读负载高、独立优化策略需求的场景。
参考示例: examples/07-order-l2-db-separation.md
最高成本:以事件流作为唯一真相源,通过投影重建读模型。适用于审计追踪、时间旅行查询、事件重放的场景。
参考示例: examples/08-order-l3-event-sourcing.md
领域行为 → 构建 DomainEvent → 持久化 → EventBus 发布
→ 本地处理器 (同步)
→ MQ 外发 (异步, 跨服务)
详细参考: references/02-cqrs-events.md
| 策略 | 开销 | 可靠性 | 场景 |
|---|---|---|---|
| 事件去重表 | 中 | ★★★ | 金融级关键事件 |
| 状态机守卫 | 低 | ★★★ | 状态驱动事件 |
| Redis + TTL | 低 | ★★☆ | 非关键通知 |
| 业务幂等 | 低 | ★★★ | 简单操作 |
详细参考(含代码示例): references/07-event-governance.md
| 架构 | 集成点 | 目录结构 |
|---|---|---|
| Layered | Application 层 Command/Query Service 分离 | app/service/command/ + app/service/query/ |
| Onion | Core 层 Command/Query UseCase 接口 | core/application/command/ + core/application/query/ |
| Hexagonal | Port 层 Command Port + Query Port | domain/port/command/ + domain/port/query/ |
| Clean | UseCase 层 Command Interactor + Query Interactor | usecase/interactor/command/ + usecase/interactor/query/ |
| COLA | App 层 Command + Query 子模块 | app/command/ + app/query/ |
详细参考: examples/04-multi-architecture-integration.md
| 问题 | 回答 |
|---|---|
| CQRS 一定会引入最终一致性? | L1 不需要,L2/L3 需要 |
| Event Sourcing 和 CQRS 绑定? | 否,可独立使用 |
| 何时需要 Outbox 模式? | 需要可靠事件发布时,避免双写问题 |
| CQRS 和微服务关系? | 正交,可在单体内部署或跨微服务 |
| 查询模型复杂到何种程度? | 可跨聚合/服务组装,反范式化物化视图 |
| 规则 | 说明 |
|---|---|
| Command 侧需验证权限 | 执行命令前必须鉴权 |
| 事件体不能含敏感数据 | 密码、PII 等不应出现在事件中 |
| 查询侧不能修改状态 | Query Handler/Service 不能有写操作 |
| 同一事务写业务数据 + Outbox | 避免双写问题 |
| 聚合内强一致,聚合间最终一致 | 一个事务最多改一个聚合的状态 |
ddd-event-storming 建立事件思维CQRS, 读写分离, Event Sourcing, 事件溯源, Command Bus, Query Model, Command Model, 领域事件, Domain Event, 最终一致性, Eventual Consistency, Outbox Pattern, Transactional Outbox, Materialized View, Projection, Event Store, Idempotency, 幂等, L1/L2/L3, Clean Architecture CQRS, Hexagonal CQRS, COLA CQRS
references/architecture/01-clean-ddd-hexagonal-cqrs.md — CQRS & Domain Events:Commands, Queries, Read Models, Event Dispatcher, Outboxreferences/02-cqrs-events.md — CQRS 领域事件:事件分类、事件存储、投影策略、版本管理references/03-cqrs-mindmap.md — CQRS 思维导图:适用场景、实施策略references/04-ddd4j-cqrs-mindmap.md — CQRS 思维导图:核心理念、架构模式、组件references/07-event-governance.md — 事件治理:Outbox DDL、幂等、重试/死信/补偿/对账references/domain-events/01-domain-events-deep.md — 领域事件深入:事件驱动设计原则references/06-domain-vs-integration-events.md — 领域事件 vs 集成事件:边界划分references/08-partme-06-domain-events.md — 领域事件实操:保险承保案例examples/06-order-l1-model-separation.md — L1 模型分离完整示例examples/07-order-l2-db-separation.md — L2 数据库分离 + 事件同步examples/08-order-l3-event-sourcing.md — L3 Event Sourcing 完整示例examples/04-multi-architecture-integration.md — 5 种架构 CQRS 集成对比examples/03-inventory-cqrs.md — 库存 CQRS + 幂等策略实现agents/openai.yaml (opens in a new tab)examples/01-cqrs-testing.md (opens in a new tab)examples/02-event-sourcing-bank.md (opens in a new tab)examples/03-inventory-cqrs.md (opens in a new tab)examples/04-multi-architecture-integration.md (opens in a new tab)examples/05-notification-cqrs.md (opens in a new tab)examples/06-order-l1-model-separation.md (opens in a new tab)examples/07-order-l2-db-separation.md (opens in a new tab)examples/08-order-l3-event-sourcing.md (opens in a new tab)examples/09-payment-cqrs.md (opens in a new tab)examples/10-user-command-query.md (opens in a new tab)references/01-clean-ddd-hexagonal-cqrs.md (opens in a new tab)references/02-cqrs-events.md (opens in a new tab)references/03-cqrs-mindmap.md (opens in a new tab)references/04-ddd4j-cqrs-mindmap.md (opens in a new tab)references/05-domain-events-deep.md (opens in a new tab)references/06-domain-vs-integration-events.md (opens in a new tab)references/07-event-governance.md (opens in a new tab)references/08-partme-06-domain-events.md (opens in a new tab)references/architecture/01-clean-ddd-hexagonal-cqrs.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Generated from the plugin's indexed repository (full-stack-skills/ddd-skills) — no native marketplace selected
npx claudepluginhub p/full-statck-skills-ddd-skills16 skills in this plugin
/ddd-api-designerAPI design from domain model — CQRS command/query separation, REST API endpoint design, data object conversion chain (PO→DO→DTO→VO), unified response format, OpenAPI/Swagger generation, BFF pattern, API versioning, and security design. Use when user asks about API design, REST API, OpenAPI, BFF, DTO design, 接口设计, or data object conversion./ddd-architecture-awesomeProvides comprehensive guidance for Domain-Driven Design (DDD) concepts, strategic design, tactical design, and architecture patterns. Includes DDD applicability assessment, Pattern Boundaries table (what each pattern is and is NOT), Complexity Ladder (when to adopt each level), Core Concepts quick reference with Entity/ValueObject/Aggregate patterns, full architecture landscape overview, anti-patterns with fixes, multi-language reference implementations, and complete primary source references. Use when the user asks about DDD basics, needs to understand DDD concepts, evaluates DDD applicability, or wants an introduction to domain-driven design./ddd-architecture-cleanComprehensive guidance for Clean Architecture (整洁架构) — Robert C. Martin's Clean Architecture with Enterprise Business Rules, Use Cases, Interface Adapters, and Frameworks layers. Covers core entities, use case interactors, dependency rules, and full implementation steps with Java/Spring Boot examples. Use when user asks about Clean Architecture, 整洁架构, Robert Martin, Uncle Bob, use case driven architecture, or needs to implement DDD with clean architecture.Other plugins' skills for the same job