Key takeaways

  • Most old systems can be improved in place, in short steps, without a rewrite.
  • Map first: find what runs, what changes most, and what business rules the code holds.
  • Tests around today's behavior come before any change, so you can prove nothing broke.
  • AI agents read and test quickly. Engineers decide what changes and approve every step.

To modernize old code safely, map it before you change it. Find what actually runs, see which parts change most, write down the business rules the code holds, and put tests around what it does today. Only then start changing it, in short steps. AI agents can do much of the reading and test writing, while people decide what matters and approve each change.

This is the order we follow in legacy modernization work, and it is why we rarely recommend a full rewrite. Your old code already does the job. A rewrite throws away years of fixes and business rules, and stops new features while it runs.

Why map before you change

Old systems fail in surprising places because nobody knows what depends on what. A change that looks tidy in one file can break a report that runs once a month. A map turns those surprises into a list you can plan around. It also tells you honestly whether a part really needs replacing, or just needs tests and some care.

Step 1: find out what runs

Start with the edges. List the ways work enters the system: web pages, API calls, scheduled jobs, imports, and anything another system calls. Then list what it talks to: databases, queues, files and third party services. An agent can read the codebase and draft this inventory in minutes. A person who knows the business should read it and correct it, because code cannot tell you which job matters to the finance team.

Step 2: read the history

Version history shows where the risk lives. Files that change often, files only one person has ever touched, and files that keep appearing in bug fixes deserve attention first. Pair that with the incidents people remember. The result is a short list of hot spots, which is far more useful than a diagram of everything.

Step 3: write down the business rules

Old code holds decisions: how a discount is rounded, who may approve a refund, what happens on a leap day. Those rules are rarely written anywhere else. Have the agent summarize what each hot spot appears to do in plain English, then ask the people who use it whether that is right. Every correction is a rule you have just saved from being lost.

Step 4: put tests around today's behavior

Before changing anything, write tests that describe what the code does now, including the odd results. The aim is not to prove the code is right. It is to notice when a change alters behavior. Agents are good at writing the missing tests quickly. Engineers should check that the tests reflect rules people agreed in step 3, not just what the code happens to do.

Step 5: agree the order of work

Now you can plan. Choose short changes that are quick to review and quick to undo, starting where risk and value meet: a release nobody wants to run, a framework that is out of date, or a page that keeps timing out. Each change ships on its own, behind the tests, so customers keep using the product the whole time.

Where AI helps and where a person decides

Agents read the codebase, write the missing tests and do repetitive changes across many files. Engineers decide what changes and approve every step. Every change passes the checks first, and nothing merges without a person saying yes. That is the loop described in from SDLC to ADLC.

We work in your repositories and your tools, and every change is reviewed and recorded there, so your code does not leave your control.

Common traps

  • Mapping everything. A map of every file is out of date before you finish. Map the hot spots and the edges first.
  • Trusting a summary unchecked. An agent's plain English summary is a draft. Someone who uses the system should confirm it.
  • Skipping the tests. Without tests around today's behavior, every change is a guess, however tidy it looks.
  • Changing too much at once. Short steps are easy to review and easy to undo. Large ones are neither.

A useful test

Ask who could explain your riskiest module today. If the answer is one person, or nobody, a map is the cheapest thing you can buy before any change.

Start with a health check

If you would like this done for your system, the first step is a delivery health check at £1,200 ex VAT. We look at the code, the tests and how you release, and write down what is risky, what is slow and what to fix first. See how legacy modernization works or tell us about the system that worries you.

Share this article

Portrait of Catalin Magirescu

About the author

Catalin Magirescu

Founder of Lucasia

I build AI-native apps, web and mobile apps, and the agent platforms behind them, including the Lucasia app and our own AI engineering platform. Before Lucasia I spent years shipping software for teams that cannot afford a bad release, in insurance, travel and other regulated work. Here I write about what actually works when you put AI into a real business: where it saves hours, where it needs a person in charge, and how to build it so it stays safe.