tactical-ddd
Skill này làm gì
Skill này để AI xem xét các mô hình phần mềm để tìm quy tắc nghiệp vụ bị thiếu hoặc rải rác, rồi tái cấu trúc để các quy tắc nằm bên trong đối tượng. Phù hợp với lập trình viên muốn mã miền của họ tự bảo vệ các quy tắc của mình.
Khi nào nên dùng
- ✓Khi bạn yêu cầu AI xem xét hoặc kiểm tra các mô hình miền để tìm thiết kế yếu.
- ✓Khi các đối tượng miền chỉ là nơi chứa dữ liệu và các quy tắc nằm ở service khác.
- ✓Khi bạn muốn tái cấu trúc mã thành entity, value object hoặc aggregate.
Liên kết skill
https://github.com/tech-leads-club/agent-skills/blob/main/packages/skills-catalog/skills/(architecture)/tactical-ddd/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Kiểm tra các lớp đơn hàng và hóa đơn của chúng tôi, cho tôi biết chúng có chỉ là túi dữ liệu không, và nên làm gì với chúng.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI trước hết phát hiện các mô hình yếu và chấm điểm chúng, rồi quyết định mẫu thiết kế nào phù hợp với mỗi lớp, và tái cấu trúc từng bước nếu bạn yêu cầu.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Tactical DDD — Rich Domain Modeling
Workflow
Determine the user's intent first:
| Intent | Phases to run |
|---|---|
| "validate / review / check / is this correct?" | Phase 1 + 2 only → report findings, ask before refactoring |
| "fix / refactor / improve / clean up" | Phase 1 + 2 + 3 |
| "how should I design / model this?" | Load reference.md directly |
Phase 1 — Detect
Load detection.md and scan the target code for anemia signals. Produce a severity score and list of affected classes.
Phase 2 — Assess
For each affected class, determine the correct building block:
| Has unique identity tracked over time? | Has invariants tying multiple objects? | → Building Block |
|---|---|---|
| Yes | — | Entity |
| No | — | Value Object |
| Yes (root) + children with shared invariants | Yes | Aggregate |
| Operation spans multiple Aggregates/doesn't belong to any | — | Domain Service |
Prefer Value Objects over Entities. Prefer small Aggregates over large ones.
If intent was validate/review: stop here. Report findings using the output format below. Ask "Would you like me to apply these fixes?" before proceeding.
Phase 3 — Refactor
Load refactoring.md for step-by-step moves. Apply in this order:
- Replace setter chains with a single expressive method
- Move service logic into the Aggregate that owns it
- Add business guards at the top of each method
- Publish a Domain Event after each successful state change
- Replace primitive types with Value Objects
For deep pattern questions (boundary design, event modeling, service vs. entity decision), load reference.md.
Quick Anemia Signals (scan first)
public setX() / public setY() → behaviour should be encapsulated
service.doX(entity, ...) → logic likely belongs in entity
entity.setA(); entity.setB(); ... → setter chain = missing intent method
no domain methods beyond getters → pure data bag
Golden Rules
- Behaviour with data — Objects own both state and the operations that change it
- Ubiquitous Language — Method names come from the domain, not CRUD (
commitTo, notsetStatus) - Small Aggregates — Root + Value Objects by default; add child Entities only for true invariants
- One transaction = one Aggregate — Cross-Aggregate rules use eventual consistency via Domain Events
- Reference by ID — Never hold object references to other Aggregates
- Value Objects first — Use Entities only when individual identity is essential
- Domain Services sparingly — Excessive services → anemic model
- Protect invariants — The Aggregate is the last line of defence; never trust the caller
Output Format
When reviewing code, report:
## Anemia Diagnosis: <ClassName>
Severity: [None | Mild | Moderate | Severe]
Issues:
- <description of problem>
Recommended refactoring:
- <specific move from refactoring.md>
When refactoring, show a before/after diff for each class touched.
Câu hỏi thường gặp
Nó có thay đổi mã mà không hỏi không?
Không. Nếu bạn yêu cầu xem xét, nó báo cáo phát hiện và chờ trước khi thay đổi bất kỳ điều gì.
Mô hình thiếu sức sống là gì?
Đó là lớp chỉ chứa dữ liệu nhưng để mọi quy tắc nghiệp vụ ở nơi khác.
Value object là gì?
Các đối tượng nhỏ không có danh tính riêng, như một số tiền hoặc một địa chỉ.
Chi tiết
Mô tả gốc của tác giả
Detects anemic domain models, validates and refactors them into rich domain models, and enforces tactical DDD patterns (Entities, Value Objects, Aggregates, Domain Services, Domain Events). Use when the user asks to validate, review, or check domain models or DDD code; detect anemia; refactor domain objects; improve encapsulation; or mentions terms like "anemic model", "rich domain", "aggregate", "value object", "domain event", "ubiquitous language", "is this good DDD", "does this follow DDD", or "check my domain". Do NOT use for module or service boundary design, architectural decomposition,
Độ phổ biến
- Sao GitHub
- 7.1k
- Vị trí xếp hạng
- #13512
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
component-common-domain-detection
7.1kGiúp agent của bạn tìm logic nghiệp vụ bị lặp lại ở nhiều phần của codebase và gợi ý cách gộp nó lại.
component-flattening-analysis
7.1kGiúp agent của bạn tìm mã nằm sai chỗ và làm phẳng các cấu trúc thư mục component lộn xộn, để mỗi phần nằm đúng vị trí.
component-identification-sizing
7.1kGiúp agent của bạn lập bản đồ các phần của codebase và đo kích thước của chúng, để tìm module nên tách trước.
coupling-analysis
7.1kGiúp agent của bạn kiểm tra mức độ phụ thuộc chặt chẽ giữa các phần của codebase, và nên nới lỏng những kết nối nào trước.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.