
Improve Codebase Architecture
FreeEnhance your codebase with actionable architectural insights.
Free · Opens the source repo
What Improve Codebase Architecture does
The Improve Codebase Architecture skill is designed to help developers identify and address architectural issues within their codebases. By scanning for deepening opportunities, this skill focuses on transforming shallow modules into deeper, more maintainable structures. The ultimate goal is to enhance testability and facilitate AI navigation, ensuring that your codebase is not only functional but also robust and adaptable to future changes.
To utilize this skill effectively, it first requires an exploration phase where users can scope their search based on recent changes in the codebase. By leveraging the project's domain model and design vocabulary, the skill encourages users to focus on areas that have shown friction or complexity. It emphasizes a thorough understanding of the codebase by suggesting users familiarize themselves with relevant documentation, such as the domain glossary and architectural decision records (ADRs), before diving into the analysis.
Once the exploration is complete, the skill generates a detailed HTML report that presents various candidates for architectural improvement. This report includes visualizations that clearly illustrate the current and proposed structures, alongside explanations of the problems and benefits associated with each suggestion. The use of Tailwind and Mermaid for styling and diagrams enhances the clarity and usability of the report, making it easier for developers to grasp the proposed changes.
After presenting the report, the skill enters a grilling loop, where users can delve deeper into the selected candidates. This interactive phase allows for discussions around constraints, dependencies, and potential tests, ensuring that any architectural changes are well-considered and documented. The skill also facilitates the updating of the domain model and ADRs as decisions are made, promoting a continuous improvement mindset within the development process.
When to use it
Use this skill when you need to analyze the architecture of a codebase and identify areas for refactoring to improve testability and clarity.
When not to use it
This skill may not be suitable for codebases that are already well-structured or for teams that prefer to handle architectural decisions without external input.
What you can build with it
Refactoring a Legacy Module
When facing challenges with a legacy module that is difficult to test, use this skill to identify refactoring opportunities.
Improving Test Coverage
If your team struggles with test coverage, this skill can highlight areas in the architecture that need deepening for better testability.
Navigating Architectural Decisions
When architectural decisions are conflicting, this skill helps surface issues and suggests revisiting ADRs based on real friction.
How to install Improve Codebase Architecture
View source1. Install with the skills CLI
npx skills add mattpocock/skills/improve-codebase-architecture --agent claude-code2. Or install it manually
Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.
Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs
Inside SKILL.md
Written by mattpocockImprove 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. Present candidates as an HTML report
Write a self-contained HTML file to the OS temp directory so nothing lands in the repo. Resolve the temp dir from $TMPDIR, falling back to /tmp (or %TEMP% on Windows), and write to <tmpdir>/architecture-review-<timestamp>.html so each run gets a fresh file. Open it for the user — xdg-open <path> on Linux, open <path> on macOS, start <path> on Windows — and tell them the absolute 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,Speculative, rendered as a badge
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 /codebase-design vocabulary for the architecture. If CONTEXT.md defines "Order," talk about "the Order intake module" — not "the FooBarHandler," and not "the Order service."
ADR 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?"
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.
Frequently asked questions about Improve Codebase Architecture
Similar skills
React Composition Patterns
Streamline your React component architecture with proven patterns.
Pester Should Migration
Easily convert Pester v5 assertions to v6 syntax.
Radix to Base UI Migration
Seamlessly migrate React components from Radix UI to Base UI.
Migrate Next.js to Vinext
Seamlessly transition your Next.js projects to Vinext.
WinUI 3 Migration Guide
Streamline your UWP to WinUI 3 migration process.
Refactor
Enhance code maintainability without altering behavior.
