---
title: Improve Codebase Architecture Skill by Matt Pocock
canonical: https://skillselion.com/skills/mattpocock/skills/improve-codebase-architecture
content_type: text/markdown
description: "improve-codebase-architecture is a Claude Code skill that scans a codebase for shallow modules and friction, presents deepening refactor candidates in an HTML."
---

# Improve Codebase Architecture Skill by Matt Pocock

> improve-codebase-architecture is a Claude Code skill that scans a codebase for shallow modules and friction, presents deepening refactor candidates in an HTML.

Canonical: https://skillselion.com/skills/mattpocock/skills/improve-codebase-architecture

Improve Codebase Architecture analyzes a repository for shallow modules and produces a ranked HTML report of deepening opportunities. It reads existing context and ADRs, uses git history to find frequently changed areas, and explains each candidate with affected files, friction, a proposed fix, diagrams, confidence and one recommended place to start.

improve-codebase-architecture is a Claude Code skill that scans a codebase for shallow modules and friction, presents deepening refactor candidates in an HTML report, then designs the chosen one via grilling.

## Key facts

- Installs: 1,272,121
- GitHub stars: 326,014
- Author: mattpocock
- Repository: mattpocock/skills
- Works in Grok Bot: yes
- Install command: `npx skills add https://github.com/mattpocock/skills --skill improve-codebase-architecture`
- Last updated: November 13, 2026

## What Improve Codebase Architecture does

Find shallow modules and architectural friction in an existing codebase, review candidates in a visual HTML report, then design the chosen refactor through a grilling loop.

Where is my codebase architecture causing friction, and which refactors would concentrate complexity into deep modules instead of just moving it around?

An HTML architecture report with ranked deepening candidates and before/after diagrams, plus, after the grilling loop, an agreed module design with CONTEXT.md and ADR updates recorded inline.

Best for: Developers maintaining a codebase that has grown hard to navigate or test, who want ranked, visually explained refactor candidates grounded in their domain model before committing to a redesign.

Not for: Skip it on greenfield code with no friction yet, or when you already know the exact refactor and just need it implemented; it is an exploration and design tool, not an executor.

- Explores the codebase via an Explore subagent, applying the deletion test to suspected shallow modules
- Writes a self-contained HTML report to the OS temp directory with Tailwind and Mermaid via CDN
- Each candidate card has files, problem, solution, benefits, before/after diagrams, and a Strong / Worth exploring / Spec
- Uses the /codebase-design vocabulary (module, interface, depth, seam, adapter, leverage, locality) exactly
- After the user picks a candidate, runs the /grilling skill and updates CONTEXT.md and ADRs as decisions crystallize

## SKILL.md

## 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:

- Call the Skill tool with "codebase-design" 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, and don't drift into "component," "service," "API," or "boundary."
- The domain language in `GLOSSARY.md` gives names to good seams; ADRs in `docs/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 (`GLOSSARY.md`) and any ADRs in the area you're touching first.

Then spawn a sub-agent with a fresh context window 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**, with an 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 GLOSSARY.md vocabulary for the domain, and the `/codebase-design` vocabulary for the architecture.** If `GLOSSARY.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](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, call the Skill tool with "grilling" 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; call the Skill tool with "domain-modeling" to keep the domain model current as you go:

- **Naming a deepened module after a concept not in `GLOSSARY.md`?** Add the term to `GLOSSARY.md`. Create the file lazily if it doesn't exist.
- **Sharpening a fuzzy term during the conversation?** Update `GLOSSARY.md` right 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?** Call the Skill tool with "codebase-design" and use its design-it-twice parallel sub-agent pattern.

## Deep dive: how does improve-codebase-architecture actually work?

We read the file and its HTML-report reference at commit `5863806` of mattpocock/skills on November 14, 2026, and every quote below comes from GitHub at that commit. We first published this dive against commit `885e2ca`. The quoted lines are unchanged since then. Two other changes touch this dive: a rename across the repo made the project glossary `GLOSSARY.md` instead of `CONTEXT.md`, and the codebase walk now runs in "a sub-agent with a fresh context window" rather than a plain sub-agent.

## improve-codebase-architecture at a glance

1. **It hunts one specific defect**, shallow modules, and gives the agent a falsifiable test for them.
2. **It reads your git history before your code**, scoping the audit to where change actually lands.
3. **The report goes to a temp directory**, never into your repo.
4. **The vocabulary is enforced**, with four common words explicitly banned.
5. **It refuses to propose solutions early**, stopping to ask which candidate you want.
6. **It composes three sibling skills** to do the work.

## 1. It hunts shallow modules, and it has a test for them

The goal is stated in the file's own vocabulary:

> Surface architectural friction and propose **deepening opportunities**: refactors that turn shallow modules into deep ones. The aim is testability and AI-navigability.
> Source: SKILL.md, [opening](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L9)

A shallow module is one whose interface is nearly as complex as the implementation it hides, so it costs about as much to use as it saves. Rather than leaving "shallow" to taste, the file hands the agent a decision procedure:

> 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.
> Source: SKILL.md, ["Explore"](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L35)

That test is falsifiable in about five seconds, and it catches the specific failure mode of over-refactored codebases: a pure function extracted for testability while, as the file puts it, the real bugs hide in how it is called.

## 2. It scopes before it scans

The instruction that keeps this from becoming a boil-the-ocean audit comes first:

> **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.
> Source: SKILL.md, ["Explore"](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L20)

The method is `git log --oneline` over a stretch of history, looking for hot spots, the files that keep coming up. If you named a direction it takes yours and skips the inference. Refactoring value is a function of how often a module changes again, and commit history is the cheapest proxy available.

The honest limit is in the file too: when changes are scattered with no clear hot spot, the instruction is to widen the net. On a codebase with diffuse history that is the wide audit the rule was meant to avoid, so point it at a subsystem yourself when you can.

## 3. The report goes to a temp directory

This is the part that makes the skill distinctive:

> Write a self-contained HTML file to the OS temp directory so nothing lands in the repo.
> Source: SKILL.md, ["Present candidates as an HTML report"](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L39)

The temp-directory rule matters more than it sounds. An architecture review is a throwaway artifact, and a skill that dropped `architecture-review.html` into your working tree would leave litter in every repo it touched. It resolves `$TMPDIR` with a `/tmp` or `%TEMP%` fallback, timestamps each run, opens it with the platform's opener, and prints the absolute path.

Each candidate becomes a card with files, problem, solution, benefits, a before/after diagram, and a strength badge of `Strong`, `Worth exploring` or `Speculative`. The report closes by naming the one to tackle first, which is the commitment most audit tools avoid.

One caveat the file does not flag: it calls that HTML self-contained while specifying Tailwind and Mermaid over CDN. Open the report offline, or behind a proxy that blocks `cdn.tailwindcss.com` and `cdn.jsdelivr.net`, and you get an unstyled document with every diagram missing. The diagrams are the deliverable.

## 4. The vocabulary is enforced

Most design skills suggest terminology. This one bans the alternatives:

> Use these terms exactly in every suggestion, and don't drift into "component," "service," "API," or "boundary."
> Source: SKILL.md, [vocabulary rule](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L13)

The approved set is module, interface, depth, seam, adapter, leverage and locality, loaded from a sibling skill, [codebase-design](/skills/mattpocock/skills/codebase-design). Those four banned words are exactly the ones that let an architecture discussion sound rigorous while committing to nothing, and an agent reaches for them by default. Naming them is worth more than the seven approved terms.

The same discipline extends to your domain: if `GLOSSARY.md` defines "Order", the report says "the Order intake module", not "the FooBarHandler" and pointedly not "the Order service". Without a `GLOSSARY.md` the architecture vocabulary still applies, but the domain half of the rule has nothing to bind to.

## 5. It refuses to propose solutions early

One line does a lot of work:

> Do NOT propose interfaces yet. After the file is written, ask the user: "Which of these would you like to explore?"
> Source: SKILL.md, ["Present candidates"](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L60)

Survey first, design second, and only on the candidate you chose. It is the same decisions-belong-to-the-user principle running through this author's other work, applied here to stop the agent spending a thousand tokens designing an interface for a refactor you were never going to do.

## 6. It composes three sibling skills

The file is an orchestrator. It calls [codebase-design](/skills/mattpocock/skills/codebase-design) for the architecture vocabulary, [grilling](/skills/mattpocock/skills/grilling) for the interview once you pick a candidate, and [domain-modeling](/skills/mattpocock/skills/domain-modeling) to keep `GLOSSARY.md` current as decisions crystallize. Readers of our [grill-with-docs dive](/skills/mattpocock/skills/grill-with-docs#deep-dive) will recognize the last two: this repo builds capabilities as small skills and composes them.

The composition has a memory in both directions. Existing ADRs record decisions the review should not re-litigate, and a rejection becomes durable:

> **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?"_
> Source: SKILL.md, ["Grilling loop"](https://github.com/mattpocock/skills/blob/5863806dd4e15c63174bee4e7515a4256792ecfa/skills/engineering/improve-codebase-architecture/SKILL.md#L70)

**Tools it drives:** `git log` for hot-spot inference, a sub-agent with a fresh context window for the codebase walk, a file write to the OS temp directory, and the platform's file opener. Three sibling skills load through the Skill tool.

**Behavior change, before and after:**

| You ask | Without the skill | With the skill |
|---|---|---|
| "Where should I refactor?" | Generic smells, scattered across the repo | Candidates from your commit hot spots, each passing the deletion test, with one top pick |
| "Improve this module" | An immediate rewrite | A before/after visual, then a question about which candidate you actually want |

**The fine print worth knowing:**

- The report's HTML depends on two CDNs at open time. No network, no diagrams.
- It sets `disable-model-invocation: true`, so your agent can never start a review on its own.
- Three sibling skills are required: codebase-design, grilling, domain-modeling. Install the set.

## Should you install improve-codebase-architecture?

Install it if your codebase is big enough that structural arguments go in circles. The deletion test and the four banned words are what make those arguments converge, and an HTML report is a better artifact than chat for a decision you will revisit. Skip it on a young codebase, where the honest answer to "where should I refactor" is usually nowhere yet. Point it at a subsystem rather than letting it infer, unless your commit history has obvious hot spots.

```
npx skills add https://github.com/mattpocock/skills --skill improve-codebase-architecture
```

## Improve Codebase Architecture FAQ

### What counts as a "shallow" module here?

One whose interface is nearly as complex as the implementation behind it, so it costs about as much to use as it saves. The skill separates shallow from deep with the deletion test: if removing the module would concentrate complexity it is worth deepening, and if it would merely move complexity elsewhere it is not.

### Does improve-codebase-architecture change any code?

Not on its own. It produces a report and a conversation. Code changes happen after you pick a candidate and work through the design interview, and the only files it writes unprompted are the temp-directory HTML and, during that interview, updates to `GLOSSARY.md` and `docs/adr/`.

### Where does improve-codebase-architecture write its report?

Into your operating system temp directory, so nothing lands in the repository. It resolves $TMPDIR and falls back to /tmp, or %TEMP% on Windows, writes architecture-review-<timestamp>.html so each run gets its own file, opens it with open, xdg-open or start, and prints the absolute path. The report styles itself with Tailwind and draws graph-shaped relationships with Mermaid, both from a CDN.

### Does improve-codebase-architecture do the refactor?

No. It stops at candidates and refuses to propose interfaces at that stage, then asks which one you want to explore. Pick one and it runs /grilling to walk the design with you, updating CONTEXT.md as terms firm up, and if you reject a candidate for a reason a future reviewer would need, it offers to record an ADR so the next scan leaves it alone. The README calls it a survey and says that on an old codebase it finds real candidates and will not untangle the mud for you.

### What does improve-codebase-architecture actually produce?

A self-contained HTML report in the OS temp directory (Tailwind + Mermaid) with one card per refactor candidate: files, problem, solution, benefits, before/after diagrams, and a Strong / Worth exploring / Speculative badge, plus a top recommendation.

### When should I run this skill?

When understanding one concept means bouncing between many small modules, when modules are shallow (interface nearly as complex as the implementation), or when parts of the codebase are untested or hard to test through their current interface.

### Does it refactor the code for me?

Not directly. It explicitly does not propose interfaces in the report; after you pick a candidate it runs the /grilling skill to design the deepened module with you, updating CONTEXT.md and ADRs as decisions crystallize.

### How do I install Improve Codebase Architecture Skill by Matt Pocock?

npx skills add https://github.com/mattpocock/skills --skill improve-codebase-architecture

## Machine access

- [Sitemap](https://skillselion.com/sitemap.xml)
- [llms.txt](https://skillselion.com/llms.txt)
- [llms-full.txt](https://skillselion.com/llms-full.txt)
- [Developer resources](https://skillselion.com/developers)
- [OpenAPI spec](https://skillselion.com/openapi.json)
- [MCP handshake](https://skillselion.com/.well-known/mcp)
- [API catalog](https://skillselion.com/.well-known/api-catalog)
- [AI catalog](https://skillselion.com/.well-known/ai-catalog.json)
- [Pricing](https://skillselion.com/pricing.md)
- [Auth](https://skillselion.com/auth.md)
- [AGENTS.md](https://skillselion.com/AGENTS.md)
- [Contact](https://skillselion.com/contact)
- [Home](https://skillselion.com/)
