Improve Codebase Architecture
Find architectural friction the way a future maintainer or coding agent experiences it. Favor deep modules: a small interface hiding substantial implementation complexity.
Read $SKILL_DIR/references/deepening-guide.md before classifying dependencies, judging test strategy, or drafting the RFC.
Workflow
- Decide scope. If the user gives a path, subsystem, ticket, or architectural theme, stay inside it. Otherwise explore until you can name the highest-friction areas.
- Explore the codebase using whatever discovery tools are available.
- If subagents are available, you may run one exploration pass and 2-4 design passes in parallel.
- If subagents are unavailable, do the same work sequentially. Do not fail just because parallelism is unavailable.
- Treat friction as evidence: cross-file bouncing, redundant adapters, shallow modules, hidden orchestration, and tests that protect internals instead of behavior.
- Surface 3-5 candidate deepening opportunities. For each candidate, report:
ClusterWhy they're coupledDependency categoryTest impactExpected leverageMigration cost / riskConfidence
- If no candidate is strong enough, say so explicitly and stop. Do not invent an RFC just to satisfy the workflow.
- Ask the user which candidate to explore. If the user only wanted an architectural review, stop after the candidate list and recommendation.
- Frame the problem space for the chosen candidate before proposing an interface:
- Constraints the new interface must satisfy
- Dependencies it must rely on
- Non-goals
- Likely failure modes
- A rough illustrative code sketch that grounds the constraints without committing to a design
- Design 2-4 materially different interfaces.
- With subagents: give each one a distinct design goal.
- Without subagents: produce the same diversity of designs yourself, one by one.
- Useful design goals:
- Minimize interface surface
- Optimize for common caller ergonomics
- Maximize extension flexibility
- Isolate cross-boundary dependencies with ports and adapters
- For each design, include:
- Interface signature
- Usage example
- Complexity hidden internally
- Dependency strategy
- Trade-offs
- Failure modes
- Migration shape
- Compare the designs in prose, then give a clear recommendation. If a hybrid is best, say exactly which parts should be combined.
- Draft the RFC as Markdown using the template in
$SKILL_DIR/references/deepening-guide.md. - Save the draft locally as
./architecture-rfc-<candidate-slug>.md. - Only create a GitHub issue if all of these are true:
- The user explicitly asks for an issue
ghis installed and authenticated- The draft is already complete
Otherwise, return the Markdown draft and the suggested
gh issue createnext step without executing it.
Working heuristics
- Prefer seams where the bugs live in orchestration, not in leaf helpers.
- Prefer module boundaries that let tests assert observable behavior instead of call order or internal state.
- Prefer designs that reduce navigation cost for both humans and agents.
- Be suspicious of "extract function for testability" if the real coupling stayed in the caller.
- Do not let current file layout dictate the future interface.
Output contract
When presenting candidate opportunities, always include:
ClusterWhy they're coupledDependency categoryTest impactExpected leverageMigration cost / riskConfidence
When presenting the final recommendation, always include:
- The chosen design or hybrid
- Why it wins
- What should remain outside the module
- Which existing tests become redundant
- Which new boundary tests matter most
Failure handling
- If dependency classification is uncertain, name the uncertainty and what evidence is missing.
- If the codebase is too large, narrow scope before claiming confidence.
- If the best answer is "leave this area alone for now," say that plainly.
- Never mutate remote systems by default. Draft first, publish second.