‹ 首页

domain-driven-design

@techygarg · 收录于 1 周前

Apply DDD tactical patterns when working with domain code. Enforces aggregate design, value objects over primitives, entity identity rules, and bounded context boundaries. Use when creating or modifying domain models, designing aggregates, working in the domain layer, or when the user mentions 'domain', 'aggregate', 'value object', 'entity', 'bounded context', or 'DDD'.

适合你,如果正在用 DDD 战术模式设计或重构领域层代码

/ 下载安装
domain-driven-design.skill双击,或拖进 Claude 桌面版 / Cowork,即完成安装↓ .skill↓ .zip
用别的 agent?下载 .zip 解压,把文件夹放进它的技能目录
Claude Code~/.claude/skills/(项目级 .claude/skills/)
Codex CLI~/.codex/skills/
Cursor自动读取上面两处目录
其他工具见其文档的「skills」目录;两个下载是同一份文件,只是名字不同
/ 通过 npx 安装 校验哈希
npx oh-my-skill add techygarg/lattice/domain-driven-design
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- techygarg/lattice/domain-driven-design
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify techygarg/lattice/domain-driven-design
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
159GitHub stars
待重算上下文体积
镜像托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · e5a5a73

Domain-Driven Design

Config Resolution

Skill support project-custom. Resolution:

  1. Look .lattice/config.yaml repo root
  2. If found, check paths.ddd_principles custom doc path
  3. If custom path exist, read doc, check YAML frontmatter mode:
  4. mode: override (or no mode): Custom doc full precedence. Use instead embed default. Must comprehensive -- sole reference.
  5. mode: overlay: Read embed ./references/defaults.md first, then apply custom doc section on top. Section custom replace match section default (match by heading). New section append after default.
  6. If no config, no path, or path not found, read ./references/defaults.md
  7. Language adaptation: If paths.language_idioms exist in config, read "Type System & Object Model" section and adapt entity, value object, and aggregate implementation patterns to language constructs (e.g., struct vs class, trait vs interface, data class vs record). Language idioms take precedence over pseudocode defaults.
Self-Validation Checklist

STOP after generating each component. Verify ALL before proceeding. STOP: If any check fails, fix before presenting. If check is a judgment call with multiple valid approaches (see Ambiguity Signals), flag — present options and reasoning rather than silently choosing.

  1. ENTITY VS VALUE OBJECT: Each domain object — business track individual instance over time? Yes → entity with identity. No → value object with immutable and self-validate.
  2. AGGREGATE BOUNDARY: Transactional invariant require this object inside aggregate? If not → separate aggregate reference by ID.
  3. RICH BEHAVIOR: Entity have method enforce business rule, guard state transition, raise event? If entity just data holder → move logic from service into entity.
  4. VALUE OBJECT COVERAGE: Scan primitive type should be value object — string email, number amount, raw UUID as identifier → wrap value object with validate.
  5. AGGREGATE COHESION: List business rule root enforce. Each internal entity participate least one invariant? If not → belong own aggregate.
  6. DOMAIN EVENTS: Domain event raise for state transition other aggregate react, change trigger notification, audit/compliance requirement? Don't raise event internal change nothing react.
  7. DOMAIN SERVICE: Stateless logic span multiple entity place domain service rather than application service? Avoid I/O and infrastructure call?
  8. FACTORY: Complex aggregate creation encapsulate factory method (Order.create(...)) or standalone factory class? Initial creation and reconstitution from persistence handle separate?
Active Anti-Pattern Scan

After verify checklist above, scan output these specific anti-pattern. If find any, fix before present code.

  • [ ] Anemic Domain Model: Entity data holder only getter/setter; all logic live service → move business rule into entity and value object
  • [ ] Primitive Obsession: Raw string for email, number for money, UUID for ID → wrap value object with validate and behavior
  • [ ] God Aggregate: Aggregate many entity, slow load, high contention → decompose keep only what share transactional invariant
  • [ ] Cross-Aggregate Transaction: Service update two aggregate one transaction → use domain event eventual consistency
  • [ ] Leaking Domain Logic: Business rule in controller, application service, or infrastructure → extract domain object or domain service
  • [ ] Misidentified Entity/Value Object: Entity without lifecycle, or value object with identity track → apply identity test
Ambiguity Signals
  • Aggregate Boundary Size: Small aggregate (more event, eventual consistency) vs large aggregate (simple transaction, immediate consistency). Neither inherent correct — depend contention pattern and invariant scope.
  • Entity vs Value Object: Some concept (like Address or Money) may or may not need identity depend domain complexity. Apply identity test, but acknowledge when borderline.
  • Domain Service vs Entity Method: Logic span multiple entity could live domain service or be method on primary entity. Choice depend which entity "own" invariant.
  • Object Creation Pattern: Factory method on aggregate root, standalone factory class, builder pattern, or plain constructor — depend assembly complexity and team convention. Don't prescribe pattern; ask which approach team prefer.
Scope Statement

Skill operate within single repo, single bounded context (e.g., one API -- Order, User, Pricing). Cover tactical DDD pattern only -- not strategic DDD (no context map, no microservice topology, no bounded context integration).

If task appear span multiple bounded context (e.g., Order feature call Shipping logic), flag before proceed: "This task touches [Context A] and [Context B]. Cross-context integration is strategic DDD — outside this skill's scope. Would you like to scope to one context, or proceed knowing cross-context coordination is your responsibility?"

framework:architecture provide structural envelope -- where code live, which layer exist, which direction dependency flow. This skill define how craft domain within envelope: rich model, invariant, aggregate boundary, ubiquitous language.

See ./references/defaults.md for aggregate design rules, entity/value object/domain service/domain event/repository/creation patterns with code examples, inline anti-pattern warnings, and decomposition guide.

按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。