跳到正文
Skillpedia
API 与服务器(后端)81k · #1616

ddd-validate

它能做什么

这项技能审核领域驱动的代码库,查找边界泄漏,即一个业务区域导入了另一个区域的内部文件。适合希望保持代码结构清晰的团队。

适用场景

  • ✓当你想审核代码库中业务区域之间的泄漏时。
  • ✓当你即将合并涉及多个区域的改动时。
  • ✓当你希望有自动检查能及早发现边界问题时。

技能链接

https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-ddd/skills/ddd-validate/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/ruvnet/ruflo/blob/main/plugins/ruflo-ddd/skills/ddd-validate/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请检查我的代码库,看看是否有代码直接访问其他区域的内部文件。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能找出每个业务区域,扫描其文件中是否有导入进入其他区域内部文件夹的情况,并检查关于实体、事件名称以及仓储位置的规则。然后报告它发现的每个问题。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Validate domain boundary integrity across all bounded contexts.

Steps

  1. Discover contexts: Scan src/*/domain/ to find all bounded contexts.

  2. Check cross-boundary violations:

    • For each context, scan all .ts files for import statements
    • Flag any import that reaches into another context's domain/ directory directly
    • Allowed: importing from another context's public index.ts (application layer)
    • Violation: importing from src/<other-context>/domain/entities/... directly
    # Find cross-boundary imports
    for ctx in $(find src -maxdepth 2 -name "domain" -type d | sed 's|src/||;s|/domain||'); do
      grep -rn "from ['\"].*src/" "src/$ctx/" --include="*.ts" | grep -v "src/$ctx/" || true
    done
    
  3. Check aggregate invariant enforcement:

    • Scan aggregate root entities for public setters that bypass validation
    • Flag mutable public properties without invariant checks
    • Verify that child entities are not directly accessible (must go through aggregate root)
  4. Check event naming conventions:

    • Domain events should be past-tense named (e.g., OrderCreated, not CreateOrder)
    • Events should be immutable (no public setters)
    • Events should carry the aggregate ID
  5. Check repository patterns:

    • Repository interfaces should exist in domain/repositories/, not infrastructure/
    • Repository implementations should exist in infrastructure/, not domain/
    • Each aggregate root should have exactly one repository
  6. Report findings:

    • Output a table of violations with file path, line number, violation type, and suggestion
    • Categorize as: BOUNDARY, INVARIANT, EVENT, REPOSITORY
    • Exit with summary: total violations, by category, severity
  7. Store results:

    npx @claude-flow/cli@latest memory store --key "ddd-validation-TIMESTAMP" --value "RESULTS_SUMMARY" --namespace tasks
    npx @claude-flow/cli@latest hooks post-task --task-id "ddd-validate" --success true --store-results true
    
常见问题

什么算是违规?

直接进入其他区域领域文件夹的导入会被标记。从其他区域的公共索引导入是允许的。

它会自己修复问题吗?

这些步骤侧重于发现并报告问题,因此请先查看报告,再决定如何修改。

事件的命名规则是什么?

领域事件应使用过去时命名,例如 OrderCreated,而不是 CreateOrder。

详情

作者的原始描述

Validate domain boundaries -- detect cross-context import violations and aggregate invariant issues. Use when auditing a DDD codebase for leaks between bounded contexts, before merging cross-cutting changes, or as a CI gate to catch boundary erosion early.

repo: ruvnet/ruflo

热度

GitHub 星标
81k
排名
#1616
许可证
MIT
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能