Improve 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
/codebase-designskill 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." - The domain language in
CONTEXT.mdgives names to good seams; ADRs indocs/adr/record decisions this command should not re-litigate.
Process
1. Explore
Scope before you scan — YAGNI. Deepening a module pays off by making future changes to it easier, so put extra weight on the parts of the codebase that have recently changed. Decide where to look before you look:
- If the user named a direction — a module, a subsystem, a pain point — take it, and skip the inference below.
- Otherwise, walk back a good stretch of the commit history (
git log --oneline) to find the codebase's hot spots — the files and areas that keep coming up — and let those paths pull your attention first. If the changes are scattered with no clear hot spot, widen the net.
Read the project's domain glossary (CONTEXT.md) and any ADRs in the area you're touching first.
Then spawn a sub-agent to walk the codebase. Don't follow rigid heuristics — explore organically and note where you experience friction:
- 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.
2. Share findings and recommendations
Default to a concise, high-level response in chat. Lead with the change you recommend first and why it matters. For each worthwhile candidate, explain:
- Finding — where the current design causes friction, with a brief example or file link that supports it.
- Recommendation — what should change, in plain language.
- Why — the expected benefit, key tradeoffs, and why it is worth doing.
- Confidence —
Strong,Worth exploring, orSpeculative.
Use the project's domain terms and the /codebase-design vocabulary. Keep
implementation detail for the follow-up discussion. If no change is worth
recommending, say so and explain why.
If a candidate conflicts with an ADR, explain why the observed friction warrants revisiting that decision. Only include conflicts worth reopening.
Create an HTML report only when the user asks for one. For that path, read
HTML-REPORT.md for the format and diagrams. Write it to
<tmpdir>/architecture-review-<timestamp>.html, using $TMPDIR or /tmp
(%TEMP% on Windows). Open it with the platform's file opener and share its
absolute path. Include the high-level recommendation in chat too.
Ask which candidate the user wants to explore before designing interfaces.
3. Grilling loop
Once the user picks a candidate, run the /grilling skill to walk the decision tree with them — constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.
Side effects happen inline as decisions crystallize — run the /domain-modeling skill to keep the domain model current as you go:
- Naming a deepened module after a concept not in
CONTEXT.md? Add the term toCONTEXT.md. Create the file lazily if it doesn't exist. - Sharpening a fuzzy term during the conversation? Update
CONTEXT.mdright there. - 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
/codebase-designskill and use its design-it-twice parallel sub-agent pattern.