Understanding legacy systems with AI
Every modernization starts with the same problem: nobody fully understands the current system. The people who built it have left, the documentation is years out of date, and critical business rules live in stored procedures, batch jobs and configuration files. Recovering that knowledge used to take months of reading code with the few remaining experts.
This is one of the areas where AI changes the economics most. It can read large codebases, explain unfamiliar languages and trace how things connect, quickly. The catch: code shows what a system does, not why, and some behavior lives outside the code entirely.
Diagram
Section titled “Diagram”- AI reads everything that defines behavior, not just the application code.
- It drafts explanations, data flows, interface lists and C4 diagrams, each linked to the source files.
- People who know the system confirm intent and fill in what the code can't tell you.
- Confirmed knowledge goes into the repository, where anyone can ask questions and get answers with sources.
Workflow 1: Explain an unfamiliar component
Section titled “Workflow 1: Explain an unfamiliar component”Explain what this [language] code does for an architect who doesn'tread [language]. Cover:1. Its purpose in business terms, in two sentences.2. Inputs, outputs and side effects (database writes, files, messages, calls to other systems).3. Business rules it enforces, each with the line numbers.4. Error handling and what happens on failure.5. Anything that looks risky, dead, or surprising.Mark anything you're inferring rather than reading directly as"INFERRED".
[paste code]Verify: INFERRED items go to someone who knows the system. Business rules should be checked against real data or tests; code that looks dead is sometimes called by a nightly job you haven’t found yet.
Workflow 2: Map integrations and data flows
Section titled “Workflow 2: Map integrations and data flows”From the code and configuration below, list every external interaction:databases and tables read or written, queues and topics, files,HTTP or SOAP endpoints called or exposed, scheduled jobs.For each: direction, the system on the other side if identifiable,data involved, and file/line evidence.Then produce a Mermaid flowchart of the data flows.
[attach repository, configs, job schedules]Verify: compare with runtime evidence such as network flows, database audit logs or traces. Code can mention integrations that are switched off, and miss ones defined in deployment configuration or another repository.
Workflow 3: Extract business rules from stored procedures
Section titled “Workflow 3: Extract business rules from stored procedures”Stored procedures are often where decades of business rules live, and where modernization projects find their nastiest surprises.
Analyze this stored procedure. List each business rule as a plainEnglish statement ("If X and Y, then Z"), with line numbers.Identify all tables read and written, any transactions and locking,and any dynamic SQL. Flag rules that look like they might beexceptions for specific customers, dates or products.
[paste procedure]Verify: turn each extracted rule into a test case against a copy of real data before you reimplement it anywhere. The edge-case rules are usually the ones nobody remembers.
Workflow 4: Generate current-state documentation
Section titled “Workflow 4: Generate current-state documentation”Combine the outputs above into a C4 context and container view, an interface catalog and a list of open questions. Use the design workflow to produce diagrams as code, and keep everything in version control so it can be regenerated as you learn more.
Workflow 5: Make the repository answerable
Section titled “Workflow 5: Make the repository answerable”Once you have decision records, diagrams, interface specs and standards in one place, retrieval-augmented generation (RAG) lets people ask questions like “which systems consume customer address changes?” and get answers that cite the documents they came from. The Ask the Compass assistant on this site works the same way over these pages.
Rules for doing this well:
- Curate first. Retrieval over outdated, contradictory documents produces confident, wrong answers. Mark superseded decisions as superseded.
- Always show sources, and teach people to click them.
- Respect permissions. The assistant must not reveal documents the person asking couldn’t open.
What to watch out for
Section titled “What to watch out for”- Code shows what, not why. Ask experts about intent before preserving or removing behavior.
- Behavior outside the code: configuration, reference data, scheduler settings, firewall rules and manual operating procedures.
- Scale limits. Very large codebases need to be analyzed in pieces; AI can lose track of cross-cutting behavior. Work component by component and stitch results together.
- Intellectual property and secrets. Legacy code often contains hard-coded credentials and is covered by licensing terms. Strip secrets and use approved tools. See guardrails.
Related pages
Section titled “Related pages”- Scenario: the core system nobody dares to change
- Scenario: integration spaghetti
- Retrieval-augmented generation (RAG)
- Zero-downtime schema changes
- Prompt library
Glossary: strangler fig, technical debt
Further reading
Section titled “Further reading”- Michael Feathers, Working Effectively with Legacy Code (Prentice Hall, 2004)
- Martin Fowler, Strangler fig application (opens in a new tab)
Written and edited by Abhinav Taduka, enterprise software architect.
New pages are added regularly. Follow Abhinav on LinkedIn to see them first.