Map it first: architecture review
6 min read
By the end you can produce a corrected architecture map of a codebase nobody remembers, and use the run as an initial diagnostic before choosing a bounded next task.
TL;DR
- Use a scoped investigation to draft
docs/architecture.md, then review it against the code and business reality. - In the case below, agent work took 18 minutes and expert correction about 45. Accuracy and review time depend on access, scope and domain knowledge.
- The same run is an initial diagnostic. An incoherent map means pause autonomous changes and investigate the model, access, context and codebase (Chapter 8).
The workflow
Make the agent read the code first, then correct what it wrote and commit the result.
Many teams own a codebase that fits one description: the author left, the README describes a build that no longer works, the code earns money and nobody wants to touch it. An agent can shorten the first investigation, but producing a map is not the same as becoming productive or understanding the business. The case below took minutes of agent work and a domain expert's review; other repositories take longer.
The prompt asks for nine sections, from purpose and data model to risks and unknowns, with file-and-line citations throughout; the full text is Appendix B.1. Choose the sections and depth the investigation needs. A document can look complete while its central business interpretation is wrong. If the codebase outgrows one context window, independent module investigations can justify subagents, with the orchestrator assembling the parts and checking their shared boundaries.
The case
The agent did not decide the rewrite was unnecessary. It gave the domain experts enough structure to decide faster.
A banking team owned a customer onboarding system: about sixty thousand lines of Java, written between 2018 and 2024 by a rotating cast of contractors. The team had been assembled in 2024 from three acquisitions, and nobody had been there for the original build. The README described a 2020 architecture, and the documentation listed two of the build's three steps. They were weighing a complete rewrite, estimated at eighteen months, because "nobody understands it well enough to maintain it confidently."
I asked for fifteen minutes and a terminal. I pasted the review prompt with two additions: the domain (customer onboarding, regulated banking) and a request to flag anything that looked compliance-sensitive. Eighteen minutes later there was a thirteen-page document, wrong in three places:
- It called the deduplication service a "search service" because the implementation used the search infrastructure. Its business purpose was preventing double-creation of customer records.
- It described a scheduled job in confident detail. On inspection it was commented-out code that had not run in production for three years.
- It missed that a third-party dependency was deprecated and carried a security advisory. The agent had no access to the advisory database, so I added that myself.
The corrected document went into the repository, and the team chose targeted work instead of the broad rewrite proposal. They replaced two modules the following quarter, including the deprecated dependency. The eighteen-month proposal and three-month replacement describe elapsed schedules, not comparable labor totals. Without the original staffing assumptions and a credible counterfactual, this account does not establish person-months saved or isolate the agent's effect from the experts' judgment.
| Case note | What this account establishes |
|---|---|
| Provenance | Author-reported, anonymized banking engagement |
| Evidence | The account, its three corrected mistakes and reported investigation times; original artifacts are not published |
| Comparison | An estimated broad rewrite schedule versus the targeted work the team chose; staffing is unspecified |
| Limitations | Avoided effort is an unmeasured counterfactual; experts corrected the map and chose the alternative |
| Transfer | Use a reviewed map to challenge scope, then estimate the alternatives explicitly |
Correct it
The agent's map is a draft, and the 45-minute estimate assumes a reviewer who knows the domain.
I had never seen that codebase, but I had built onboarding systems before, so I knew what a deduplication service and a regulated-banking compliance path usually look like. The agent's mistakes looked wrong to me. A reviewer new to both the codebase and the domain has no such prior: the misidentifications still look plausible, they cannot tell which to flag, and the correction takes hours, not 45 minutes. The workflow still works; the human side of it costs more.
Check the map against five things:
- Module purposes against business reality, not implementation infrastructure.
- Anything described as live that may be dead or commented out.
- Dependency and advisory facts the agent cannot see.
- The compliance-sensitive paths.
- Every ambiguity the agent itself flagged.
Commit it
The corrected document is the entry point for all later work.
Put it at docs/architecture.md. New hires read it first, senior engineers consult it before touching an unfamiliar part, and the agent opens it on demand, when a task touches a module it has not seen, instead of re-deriving the architecture. AGENTS.md holds a pointer to the file, not the layout (Chapter 6).
Delete with evidence¶
A removal is a claim; prove it before the agent deletes anything.
The map also makes cleanup safer, the work the Prologue's Slopfix sells. For each candidate, gather static references, runtime use (logs, metrics, flags, scheduled jobs), any fallback kept for incidents, and the owner's confirmation. Then open one small pull request per removal with the evidence linked, reviewed by the team that owns the code. OpenAI's account of its own cleanup with GPT-6 models, over 1,400 merged pull requests deleting more than 800,000 lines, names the traps: reflection that defeats static analysis, an unused path kept to mitigate future incidents, and proposals that added more complexity than they removed.
Review as diagnostic
An incoherent map is a reason to pause autonomous changes and investigate the cause. The run is an initial diagnostic, not a verdict on the codebase.
- Coherent map, reasonable correction: useful evidence for a bounded next task. It does not establish behavioral understanding or production readiness.
- Incoherent map: check missing access, incomplete context, investigation scope and model fit before attributing the failure to tangled code. If the team still cannot evaluate the result, keep the relevant work human-led and use Chapter 8's rubric.
Time-box the first investigation, then decide whether another pass is likely to resolve a specific gap. Chapter 8's kill signals are the systematic rubric; a single map does not replace it.
When it breaks
- Unreviewed output. Citations and a polished structure do not make a draft correct documentation.
- A reviewer with no domain knowledge cannot tell which plausible mistakes to flag. Budget hours.
- The map goes stale. Re-run the review whenever the codebase changes substantially.
Do this Monday
- [ ] On a poorly understood codebase, choose the relevant parts of Appendix B.1, name the domain and time-box the first pass.
- [ ] Correct the output against the five checks above.
- [ ] Save it as
docs/architecture.md, commit it, and add one pointer line to AGENTS.md. Do not paste the layout in. - [ ] Judge the evidence: choose a bounded next task, or investigate why the map failed. Use Chapter 8 before expanding scope.
- [ ] Record investigation and correction time before repeating the exercise elsewhere.
Go deeper
- Template: Appendix B.1, the architecture review prompt.
- Deep dive: Appendix D, Chapter 7 - why plain code search beats a vector index here, and Understand Anything, the visual alternative.
- Sources: Appendix C.