stoneskin (Mr. Sun)

Personal homepage of Mr Sun - AI Solutions Architect, Tech Lead & AWS Cloud Specialist: resume, selected projects, and teaching archive

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 is a survey, not a refactor. It reads the code and writes one report; it never edits the repository.

It is informed by the project’s domain language and built on a shared design vocabulary:

Where this fits

Process

1. Explore

If the repository path the user gave doesn’t exist, or it isn’t clear which repository or worktree is meant, stop and ask; don’t pick the nearest match.

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:

Read the project’s glossary (GLOSSARY.md) and any ADRs in the area you’re touching first.

Then, if you can start a sub-agent with a fresh context window, have it walk the codebase; if you can’t, do the walk yourself and keep notes short. 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 a temp directory so nothing lands in the repo. If the environment names a temp directory for you to use, use that one. Otherwise take $TMPDIR, falling back to /tmp (on Windows, $env:TEMP). Write to <tmpdir>/architecture-review-<timestamp>.html with the timestamp as yyyyMMdd-HHmmss (no colons, sorts by date), so each run gets a fresh file. Open it for the user (xdg-open <path> on Linux, open <path> on macOS, Start-Process <path> in PowerShell on Windows) and tell them the absolute path. When you run non-interactively (for example as a sub-agent), don’t open it: report the path and the candidate list, and let whoever started you decide what happens next.

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. These two scripts are the only external resources: nothing from the repo is sent anywhere, and the report must not add fonts, images, analytics or any other remote content. If the CDNs can’t be reached the page is unstyled but its text is still readable; say so rather than silently shipping a broken file. 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:

Keep the cards short: HTML-REPORT.md sets the length (one sentence per field, short bullets), and where it is stricter than the list above, it wins.

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

Names from the code: the vocabulary rules cover your own words. When a class or package is called OrderService or PipePassSvcHelper, quote that name as it is; don’t rename it, and don’t treat it as breaking the “never say service” rule.

Language: write the report’s prose in the language the user writes in (when you were started by another agent, the language of the brief you were given). Keep the architecture terms (module, interface, depth, seam, adapter, leverage, locality) in English, and when the user writes Chinese add the Chinese in brackets the first time a term appears.

Use the glossary’s words for the domain, and the CODEBASE-DESIGN.md vocabulary for the architecture. If GLOSSARY.md defines “Order,” talk about “the Order intake module,” not “the FooBarHandler,” and not “the Order service.” With no GLOSSARY.md, use the names the code itself uses.

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, load the doc-probe skill and use it to walk the decision tree with them: constraints, dependencies, the shape of the deepened module, what sits behind the seam, what tests survive. (If doc-probe isn’t available, ask the same questions yourself in rounds, each with your recommended answer, and wait for the answers before the next round.)

Things that come up along the way. Do not create or edit GLOSSARY.md or any ADR yourself. These are files in a shared repo, so ask first, and say which file and what the first entry would be:

Finish with a short summary the user can carry into a spec: the chosen candidate, the decisions made, the open questions, and the tests that would survive. Then stop. Do not start the refactor.