modular-decomposition

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Modular Decomposition

模块化分解

This skill runs the Patterns 1–5 analysis pipeline before service extraction. Each pattern is plain markdown under
references/
; load the file for that step and execute it against the user’s codebase.
该Skill会在服务提取前运行Patterns 1–5分析流程。每个Pattern都是
references/
目录下的纯Markdown文件;加载对应步骤的文件并针对用户的代码库执行。

How to Use

使用方法

Quick start (what users can say)

快速入门(用户可提出的需求)

  • Full pipeline: “Run modular decomposition Patterns 1 through 5 on this repo,” “Analyze this monolith for splitting—inventory, coupling, and domain grouping.”
  • Single early step: “Identify and size components here,” “Find duplicated domain logic across modules,” “Analyze coupling between our packages.”
  • With DDD lens: “Group components into domains and check bounded contexts,” “Use DDD strategic design on this codebase before we group services.”
If the user only wants extraction order, phases, or migration roadmap after analysis exists, use decomposition-planning-roadmap instead. If they need a full legacy migration plan (strangler fig, research, multi-stack), use legacy-migration-planner as well or instead of this skill when that is the primary ask.
  • 完整流程:“对这个代码仓库运行模块化分解Patterns 1至5”、“分析这个单体应用的拆分方案——包括组件盘点、耦合度分析和领域分组”。
  • 单个前期步骤:“识别并评估此处的组件规模”、“查找跨模块的重复领域逻辑”、“分析我们各个包之间的耦合度”。
  • 结合DDD视角:“将组件按领域分组并检查bounded contexts”、“在我们分组服务前,对这个代码库使用DDD战略设计”。
如果用户在完成分析后仅需要提取顺序、阶段或迁移路线图,请改用decomposition-planning-roadmap。如果他们需要完整的遗留系统迁移方案(绞杀者模式、调研、多栈适配),当这是核心需求时,可同时或改用legacy-migration-planner

How the agent should run it

Agent执行方式

  1. Scope: Confirm the task is structural analysis (inventory → coupling → grouping), not roadmap authoring. If unclear, ask once whether they want the full ordered pipeline or a subset.
  2. Order: Run patterns 1 → 2 → 3 → 4 → 5 in that order. Do not skip a step unless the user explicitly limits scope; if they do, state which patterns were skipped and how that limits later conclusions.
  3. Load references: For each pattern, open the matching
    references/pattern-NN-*.md
    file and follow its instructions. Use the optional
    *-quick-reference.md
    for the same number when a short checklist is enough.
  4. Carry context forward: Reuse outputs from earlier patterns in later ones (e.g. component inventory from Pattern 1 informs coupling in 4 and grouping in 5). Reference concrete paths, modules, or tables from previous steps.
  5. Domain language (Pattern 5): If subdomains or bounded contexts need grounding beyond structure, read
    references/domain-analysis.md
    before or alongside Pattern 5. Optionally open
    references/domain-analysis-quick-reference.md
    or
    references/domain-analysis-examples.md
    for condensed rules or illustrations.
  6. Deliver: Produce clear, actionable findings per pattern or one consolidated report—always tied to evidence from the repository (files, dependencies, metrics), not generic advice.
  1. **范围确认:**确认任务为结构性分析(盘点→耦合→分组),而非路线图制定。若存在疑问,询问一次用户需要完整的有序流程还是其中的子集。
  2. 执行顺序:1→2→3→4→5的顺序运行Patterns。除非用户明确限定范围,否则不要跳过步骤;若用户要求跳过,需说明跳过了哪些Pattern以及这会如何限制后续结论。
  3. **加载参考文件:**针对每个Pattern,打开对应的
    references/pattern-NN-*.md
    文件并遵循其说明。若仅需要简短的检查清单,可使用对应编号的
    *-quick-reference.md
    文件。
  4. **上下文传递:**在后续步骤中复用前期Pattern的输出结果(例如,Pattern 1的组件盘点结果会为Pattern 4的耦合分析和Pattern 5的分组提供依据)。引用前期步骤中的具体路径、模块或表格。
  5. **领域语言(Pattern 5):**若子领域或bounded contexts需要超出结构层面的支撑,请在运行Pattern 5之前或同时阅读
    references/domain-analysis.md
    。可选择性打开
    references/domain-analysis-quick-reference.md
    references/domain-analysis-examples.md
    以获取精简规则或示例说明。
  6. **交付结果:**针对每个Pattern生成清晰、可落地的结论,或整合为一份报告——结论需始终与代码仓库中的证据(文件、依赖、指标)挂钩,而非泛泛的建议。

Usage examples

使用示例

Example 1 — Full pipeline
User: "We're going to split this monolith—run the full decomposition analysis (Patterns 1–5)."

Agent: Execute patterns 1→5 in order, loading each references/pattern-NN-*.md, preserving outputs between steps, then summarize cross-cutting recommendations.
Example 2 — Coupling after inventory
User: "We already have a rough module list—focus on coupling (Pattern 4) and then domain grouping (Pattern 5)."

Agent: If no prior inventory exists in the thread, either run Pattern 1 briefly or derive an explicit module list from the repo before 4 and 5. State any assumptions.
Example 3 — DDD before grouping
User: "Map bounded contexts and language, then group components into domains."

Agent: Read references/domain-analysis.md (and optional quick reference/examples) in parallel with or immediately before Pattern 5; align Pattern 5 groupings with linguistic boundaries where evidence supports it.
示例1 — 完整流程
用户:“我们要拆分这个单体应用——运行完整的分解分析(Patterns 1–5)。”

Agent:按顺序执行Patterns 1→5,加载每个references/pattern-NN-*.md文件,保留步骤间的输出结果,然后总结跨环节的建议。
示例2 — 组件盘点后的耦合分析
用户:“我们已经有一个粗略的模块列表——重点关注耦合度分析(Pattern 4)和领域分组(Pattern 5)。”

Agent:如果对话线程中没有前期的盘点结果,需先简要运行Pattern 1,或从代码仓库中推导明确的模块列表,再执行Pattern 4和5。说明所有假设前提。
示例3 — 分组前的DDD分析
用户:“映射bounded contexts和领域语言,然后将组件按领域分组。”

Agent:在运行Pattern 5的同时或之前,阅读references/domain-analysis.md(及可选的快速参考/示例文件);在有证据支持的情况下,让Pattern 5的分组与语言边界保持一致。

Prerequisites

前置条件

  • Complete Pattern N before starting Pattern N+1 unless the user explicitly narrows scope. Later patterns depend on earlier results (for example, inventory and structure inform coupling and grouping).
  • If business vocabulary, subdomains, or bounded contexts are uncertain, use
    references/domain-analysis.md
    before or alongside Pattern 5 (see Bounded contexts below).
  • 除非用户明确限定范围,否则需完成Pattern N后再启动Pattern N+1。后续Pattern依赖于前期结果(例如,组件盘点和结构信息会为耦合分析和分组提供依据)。
  • 若业务术语、子领域或bounded contexts不明确,请在运行Pattern 5之前或同时使用
    references/domain-analysis.md
    (见下文“限界上下文与DDD战略设计”部分)。

Ordered workflow (Patterns 1–5)

有序工作流(Patterns 1–5)

StepPatternPrimary reference
1Identify and size components
references/pattern-01-identify-and-size.md
(optional:
pattern-01-identify-and-size-quick-reference.md
)
2Common domain detection
references/pattern-02-common-domain.md
(optional:
pattern-02-common-domain-quick-reference.md
)
3Flattening / hierarchy
references/pattern-03-flattening.md
(optional:
pattern-03-flattening-quick-reference.md
)
4Coupling analysis
references/pattern-04-coupling.md
5Domain identification and grouping
references/pattern-05-domain-grouping.md
(optional:
pattern-05-domain-grouping-quick-reference.md
)
步骤Pattern名称主要参考文件
1组件识别与规模评估
references/pattern-01-identify-and-size.md
(可选:
pattern-01-identify-and-size-quick-reference.md
2通用领域检测
references/pattern-02-common-domain.md
(可选:
pattern-02-common-domain-quick-reference.md
3扁平化/层级优化
references/pattern-03-flattening.md
(可选:
pattern-03-flattening-quick-reference.md
4耦合度分析
references/pattern-04-coupling.md
5领域识别与分组
references/pattern-05-domain-grouping.md
(可选:
pattern-05-domain-grouping-quick-reference.md

Pattern 6 — planning and extraction

Pattern 6 — 规划与提取

Pattern 6 (create domain services / extraction) is not duplicated here. After Pattern 5, switch to decomposition-planning-roadmap for phased extraction order, milestones, and migration-style planning. For full legacy migration strategy (strangler-fig, cross-stack rewrites, research-heavy plans), optionally use legacy-migration-planner in addition.
Pattern 6(创建领域服务/提取)未在此处重复。完成Pattern 5后,请切换至decomposition-planning-roadmap进行分阶段提取顺序、里程碑和迁移方式的规划。如需完整的遗留系统迁移策略(绞杀者模式、跨栈重构、调研型方案),可额外使用legacy-migration-planner

Bounded contexts and DDD strategic design

限界上下文与DDD战略设计

  • Patterns 1–4 focus on structural inventory, duplication, hierarchy, and coupling between parts of the codebase.
  • Pattern 5 produces candidate groupings aligned with solution-space boundaries (which components belong together as services).
  • Strategic DDD (subdomains, bounded contexts, ubiquitous language) is covered in
    references/domain-analysis.md
    , with optional
    domain-analysis-quick-reference.md
    and
    domain-analysis-examples.md
    . Use it when you need to validate or refine boundaries against business language, not only folder structure.
  • Patterns 1–4聚焦于代码库各部分的结构性盘点、重复项排查、层级优化和耦合度分析。
  • Pattern 5生成与解决方案空间边界对齐的候选分组(哪些组件应归为同一服务)。
  • 战略DDD(子领域、bounded contexts、通用语言)在
    references/domain-analysis.md
    中有详细说明,同时提供可选的
    domain-analysis-quick-reference.md
    domain-analysis-examples.md
    文件。当你需要基于业务语言而非仅文件夹结构来验证或优化边界时,可使用该工具。