improve-codebase-architecture
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImprove Codebase Architecture
优化代码库架构
Surface architectural friction and propose deepening opportunities — refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.
This command is informed by the project's domain model and built on a shared design vocabulary:
- Run the skill for the architecture vocabulary (module, interface, depth, seam, adapter, leverage, locality) and its principles (the deletion test, "the interface is the test surface", "one adapter = hypothetical seam, two = real"). Use these terms exactly in every suggestion — don't drift into "component," "service," "API," or "boundary."
/codebase-design - The domain language in gives names to good seams; ADRs in
CONTEXT.mdrecord decisions this command should not re-litigate.docs/adr/
识别架构中的摩擦点,并提出架构深化机会——即将浅层模块重构为深层模块的方案。目标是提升可测试性与AI可导航性。
本命令基于项目领域模型,并遵循一套通用的设计术语体系:
- 运行技能以了解架构术语(module、interface、depth、seam、adapter、leverage、locality)及其原则(删除测试、“接口即测试面”、“一个adapter=假设接缝,两个adapter=真实接缝”)。在所有建议中严格使用这些术语——不要随意替换为“component”“service”“API”或“boundary”。
/codebase-design - 中的领域语言为优质接缝命名;
CONTEXT.md中的ADR记录了本命令不应重新讨论的决策。docs/adr/
Process
流程
1. Explore
1. 探索
Read the project's domain glossary () and any ADRs in the area you're touching first.
CONTEXT.mdThen use the Agent tool with to walk the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:
subagent_type=Explore- Where does understanding one concept require bouncing between many small modules?
- Where are modules shallow — interface nearly as complex as the implementation?
- Where have pure functions been extracted just for testability, but the real bugs hide in how they're called (no locality)?
- Where do tightly-coupled modules leak across their seams?
- Which parts of the codebase are untested, or hard to test through their current interface?
Apply the deletion test to anything you suspect is shallow: would deleting it concentrate complexity, or just move it? A "yes, concentrates" is the signal you want.
首先阅读项目的领域术语表()以及你所涉及领域的所有ADR。
CONTEXT.md然后使用的Agent工具遍历代码库。不要遵循僵化的规则——以自然方式探索,并记录你遇到摩擦的地方:
subagent_type=Explore- 理解某个概念需要在多个小型模块间反复跳转的位置?
- 哪些模块是浅层的——接口复杂度几乎与实现相当?
- 哪些纯函数仅为了可测试性而被提取,但真正的bug隐藏在调用逻辑中(缺乏locality)?
- 哪些紧耦合模块的实现细节跨接缝泄露?
- 代码库中哪些部分未被测试,或难以通过当前接口进行测试?
对所有你怀疑是浅层的模块应用删除测试:删除它会集中复杂度,还是只是转移复杂度?如果是“会集中复杂度”,那就是你要找的信号。
2. Present candidates as an HTML report
2. 将候选方案呈现为HTML报告
Write a self-contained HTML file to the OS temp directory so nothing lands in the repo. Resolve the temp dir from , falling back to (or on Windows), and write to so each run gets a fresh file. Open it for the user — on Linux, on macOS, on Windows — and tell them the absolute path.
$TMPDIR/tmp%TEMP%<tmpdir>/architecture-review-<timestamp>.htmlxdg-open <path>open <path>start <path>The report uses Tailwind via CDN for layout and styling, and Mermaid via CDN for diagrams where a graph/flow/sequence reliably communicates the structure. Mix Mermaid with hand-crafted CSS/SVG visuals — use Mermaid when relationships are graph-shaped (call graphs, dependencies, sequences), and hand-built divs/SVG when you want something more editorial (mass diagrams, cross-sections, collapse animations). Each candidate gets a before/after visualisation. Be visual.
For each candidate, render a card with:
- Files — which files/modules are involved
- Problem — why the current architecture is causing friction
- Solution — plain English description of what would change
- Benefits — explained in terms of locality and leverage, and how tests would improve
- Before / After diagram — side-by-side, custom-drawn, illustrating the shallowness and the deepening
- Recommendation strength — one of ,
Strong,Worth exploring, rendered as a badgeSpeculative
End the report with a Top recommendation section: which candidate you'd tackle first and why.
Use CONTEXT.md vocabulary for the domain, and the vocabulary for the architecture. If defines "Order," talk about "the Order intake module" — not "the FooBarHandler," and not "the Order service."
/codebase-designCONTEXT.mdADR conflicts: if a candidate contradicts an existing ADR, only surface it when the friction is real enough to warrant revisiting the ADR. Mark it clearly in the card (e.g. a warning callout: "contradicts ADR-0007 — but worth reopening because…"). Don't list every theoretical refactor an ADR forbids.
See HTML-REPORT.md for the full HTML scaffold, diagram patterns, and styling guidance.
Do NOT propose interfaces yet. After the file is written, ask the user: "Which of these would you like to explore?"
将一个独立的HTML文件写入操作系统临时目录,避免内容存入代码仓库。从解析临时目录,若不存在则回退到(Windows系统为),并写入,确保每次运行都生成新文件。为用户打开该文件——Linux系统使用,macOS使用,Windows使用——并告知用户文件的绝对路径。
$TMPDIR/tmp%TEMP%<tmpdir>/architecture-review-<timestamp>.htmlxdg-open <path>open <path>start <path>报告通过CDN引入Tailwind进行布局和样式设计,通过CDN引入Mermaid绘制图表,当图形/流程/序列图能清晰传达结构时使用Mermaid。将Mermaid与手工编写的CSS/SVG可视化结合——当关系为图形化(调用图、依赖图、序列图)时使用Mermaid,当需要更具编辑性的展示(规模图、剖面图、折叠动画)时使用手工构建的div/SVG。每个候选方案都配有前后对比可视化图。注重可视化效果。
每个候选方案的卡片应包含:
- 文件——涉及哪些文件/模块
- 问题——当前架构为何会产生摩擦
- 解决方案——用通俗易懂的语言描述变更内容
- 收益——从locality和leverage的角度解释收益,以及测试将如何改进
- 前后对比图——并排展示,手工绘制,说明浅层问题与深化后的效果
- 推荐强度——分为(强烈推荐)、
Strong(值得探索)、Worth exploring(推测性),以徽章形式呈现Speculative
报告末尾添加首选推荐部分:说明你认为应优先处理哪个候选方案及原因。
**领域术语使用中的词汇,架构术语使用中的词汇。**如果定义了“Order”,则使用“Order录入module”进行描述——而非“FooBarHandler”或“Order service”。
CONTEXT.md/codebase-designCONTEXT.mdADR冲突:如果候选方案与现有ADR冲突,仅当摩擦足够严重以至于需要重新审视ADR时才提出。在卡片中明确标记(例如警告提示:“与ADR-0007冲突——但因……值得重新讨论”)。不要列出ADR禁止的所有理论上的重构方案。
查看HTML-REPORT.md获取完整的HTML框架、图表模式和样式指南。
暂不要提出接口方案。文件写入完成后,询问用户:“你想深入探索哪一个方案?”
3. Grilling loop
3. 深入探讨循环
Once the user picks a candidate, run the skill to walk the design tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.
/grillingSide effects happen inline as decisions crystallize — run the skill to keep the domain model current as you go:
/domain-modeling- Naming a deepened module after a concept not in ? Add the term to
CONTEXT.md. Create the file lazily if it doesn't exist.CONTEXT.md - Sharpening a fuzzy term during the conversation? Update right there.
CONTEXT.md - User rejects the candidate with a load-bearing reason? Offer an ADR, framed as: "Want me to record this as an ADR so future architecture reviews don't re-suggest it?" Only offer when the reason would actually be needed by a future explorer to avoid re-suggesting the same thing — skip ephemeral reasons ("not worth it right now") and self-evident ones.
- Want to explore alternative interfaces for the deepened module? Run the skill and use its design-it-twice parallel sub-agent pattern.
/codebase-design
一旦用户选定某个候选方案,运行技能与用户一起梳理设计树——包括约束条件、依赖关系、深化后模块的形态、接缝背后的内容、哪些测试可以保留。
/grilling随着决策逐渐明确,同步产生附带操作——运行技能以保持领域模型的时效性:
/domain-modeling- **为深化后的模块命名了中未包含的概念?**将该术语添加到
CONTEXT.md中。若文件不存在则按需创建。CONTEXT.md - **在对话过程中明确了模糊术语的定义?**立即更新。
CONTEXT.md - **用户因关键原因拒绝了候选方案?**提议生成ADR,表述为:_“需要我将此记录为ADR,以便未来的架构评审不会再次提出相同建议吗?”_仅当该原因确实能帮助未来的探索者避免重复提出相同建议时才提议——跳过临时原因(“目前不值得做”)和不言自明的原因。
- **想要探索深化后模块的替代接口?**运行技能并使用其“两次设计”并行子代理模式。
/codebase-design