From spellbook-skills
DDD(领域驱动设计)架构最佳实践指南。当用户在 Java/Spring Boot 项目中遇到分层架构、领域建模、模块边界、代码评审或测试分层问题时使用。包括:纠结是否引入 application/api/querys 模块;设计或审查实体、聚合、仓储、防腐层、领域事件;贫血模型重构(setter 全开、规则全在 Service);多入口共享用例是否补 application 层;策略模式 Map 注入、责任链、Node 流程编排的取舍;Controller 测试 @WebMvcTest vs @SpringBootTest 选型;MVC 渐进迁移 DDD;DDD 命名规范。仅适用 Java/Spring Boot 生态,Go/Python/Node 等其他语言不适用。
How this skill is triggered — by the user, by Claude, or both
Slash command
/spellbook-skills:ddd-best-practicesThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
面向 Java / Spring Boot 项目的 DDD 落地指南,提供分层决策、领域建模、代码模板、测试策略、审查清单与重构路线图。
references/boundary-smells.mdreferences/code-review-checklist.mdreferences/code-templates.mdreferences/design-patterns.mdreferences/domain-modeling.mdreferences/layering-decision-matrix.mdreferences/naming-conventions.mdreferences/project-structure.mdreferences/refactoring-guide.mdreferences/testing-strategy.md面向 Java / Spring Boot 项目的 DDD 落地指南,提供分层决策、领域建模、代码模板、测试策略、审查清单与重构路线图。
Core principle: 先判断复杂度与边界 -> 先收紧依赖与模型 -> 先补关键测试 -> 再按真实信号演进分层与模式。
Announce at start: "正在使用 ddd-best-practices skill 为你提供 DDD 架构指导。"
根据用户的问题类型,读取对应的 reference 文档:
| 用户场景 | 读取文档 |
|---|---|
| 初始化 / 新模块设计 | layering-decision-matrix.md → project-structure.md |
| 领域建模 / 聚合 / ACL 设计 | domain-modeling.md |
| 快速落地查模板 | code-templates.md(~1100 行,用顶部对照表定位) |
| 命名拿不准 | naming-conventions.md |
| 测试策略 / TDD 落地 | testing-strategy.md |
| 代码审查 / 边界收紧 | code-review-checklist.md → boundary-smells.md |
| MVC → DDD 渐进重构 | refactoring-guide.md |
| 复杂规则建模 / 流程编排 | design-patterns.md(~900 行,按目录跳转) |
在给出建议时,优先检查这 5 条基线是否满足,再考虑引入更多抽象:
domain 纯净,依赖方向正确trigger 不直接依赖 repository / mapper / 外部客户端repository 接口不暴露 refreshCache / evictCache / cacheXxx 等技术语义application / use case 只测编排、事务边界、幂等与跨聚合协调;可 mock 仓储接口、Port,不要 mock Entity / VO@WebMvcTest + MockMvc;默认 mock 应用服务 / use case@SpringBootTest 烟雾测试验证关键全链路 wiringapplication / api / querys 全预埋domain 与 application 层的保护性测试只有当出现真实信号时,再建议引入:
| 信号 | 引入 |
|---|---|
| 多入口共用同一用例编排、跨聚合编排膨胀 | application 层 |
| 需要对外发布/复用 RPC 契约 | api 模块 |
| 出现独立读模型、CQRS、报表/搜索等读侧复杂性 | querys 模块 |
| 跨聚合一致性问题已真实出现 | 领域事件 / MQ |
domain 中放 Spring / MyBatis / Redis / HTTP 客户端if-else 不值得上责任链 / 决策树@SpringBootTest 当默认:Controller 默认使用切片测试,Repository / Adapter 默认使用真实集成测试application / domain 测试必须 mock mapper,优先回看职责划分是否混乱npx claudepluginhub yyykf/spellbook-skills --plugin spellbook-skillsGuides creation, editing, and verification of skills for AI coding agents using test-driven development with subagent scenarios. Use when authoring or debugging skills.