Improve codebase architecture

From bendrucker/claude · View interactive version

Improve codebase architecture is an AI agent skill from the GitHub repository bendrucker/claude. Find deepening opportunities in a codebase. Use when the user wants to improve architecture, find refactoring opportunities, consolidate tightly-coupled modules, or make a codebase more testable and AI-navigable.

How to use this skill

Skill file

Improve Codebase Architecture

Surface architectural friction and propose deepening opportunities: refactors that turn shallow modules into deep ones. The aim: testability and AI-navigability.

Glossary

Use these terms exactly in every suggestion. Consistent language is the point. Don't drift into "component," "service," "API," or "boundary." Definitions in LANGUAGE.md.

Key principles (see LANGUAGE.md for the full list):

If the project has its own domain vocabulary (in code, types, or docs), use it for the domain. LANGUAGE.md vocabulary is only for the architecture layer.

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:

Then spawn a sub-agent to walk the codebase. Don't follow rigid heuristics. Explore organically and note where you experience friction:

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, the same template, but rendered as a card:

End the report with a Top recommendation section: which candidate you'd tackle first and why.

Use the project's own domain vocabulary, and LANGUAGE.md vocabulary for the architecture. If the project's code or docs name an "Order," talk about "the Order intake module," not "the FooBarHandler," and not "the Order service."

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. Refine the chosen candidate

Once the user picks a candidate, walk the decision tree with them via AskUserQuestion: constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive.

If they want to explore alternative interfaces for the deepened module, see INTERFACE-DESIGN.md.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.