Insights

AI-assisted legacy modernization: notes from our own 14-year-old codebase

Sophia, the platform we run our company on, had its first commit in March 2012. By the middle of 2026 it looked like most systems of that age. Its admin interface had been built screen by screen over a decade, it carried 889 database migration files, and it had much more code than tests.

In August 2026 we started modernizing it. AI coding agents wrote most of the changes, under rules we set and decisions we made. These are notes on what worked, what went wrong once, and what we would tell a team about to do the same with its own system.

Treat the old system as the specification

The old admin covered 159 kinds of record. Every screen held years of small decisions: which fields appear, who may change them, what a filter means. We did not redesign those screens. We ported them, and the old screen was the specification for the new one. Porting is work an agent does well when it has something exact to follow.

To know when we were done, we wrote a command that compared the old admin with the new console and listed what was still missing. That list was the plan. About five weeks after deciding to replace the admin, the only items left were ones we had chosen not to port, and we uninstalled it. The last of its code left the repository two weeks later.

A passing test suite is weak evidence in an old system

When we started, a green test run told us little. The tests covered a small part of what the system did. One automated clean-up passed all of them and still changed three behaviours that nothing tested. We found them days or weeks later.

After that we stopped applying automated rewrites in bulk. Each kind of rewrite now goes in its own change, and the reviewer reads every place it touched. The reviewer also has to say what the rewrite assumes about the code and why that holds here. Where the assumption matters and no test covers it, the same change adds the test. Each of the three failures is now pinned by a test of the behaviour itself.

The system has more than fifty times as many tests as it had then. Before you let an agent refactor an old system, find out what your tests would not notice.

Check decisions against the source

A coding agent's memory of how a framework behaves is usually right. When it is wrong, it reads the same. So every significant decision in this work was written down in a short record, with its context and its consequences, and checked against the framework's documentation or its source code. The record carries the citation. We have written a hundred of these since August.

The migrations show why it matters. With 889 files and circular dependencies between modules, the standard command for collapsing them could not do it. The plan we chose was to generate a fresh set and mark it as replacing the old one, so that the databases that already existed would have nothing to run. Whether that was safe depended on exactly how the framework records which migrations it has applied. The decision record quotes the lines of the framework's source that settle it.

Turn each rule into a check

Agents work from written rules, and a long list of rules is followed about as well by an agent as by a person. Our file of instructions for agents says of itself that every paragraph in it is paid for on every run. Once a rule is enforced by a test or a linter, its paragraph is replaced with a pointer to the check.

Outside the test suite we now have about thirty small checks of this kind. One fails the build if a background job is queued before its database transaction has committed. Another fails it if a worker service is declared without a memory limit. Each one stands for a paragraph nobody has to remember.

Retire things on purpose

An old system carries parts that nobody uses and something still depends on. Ours had a time-entry application with a single screen and its own domain. We rebuilt the screen in the console and kept the domain answering with a redirect, because bookmarks outlive applications.

One retired module left nothing behind except its migration history. Deleting its directory would have stopped the application from starting, so it stays as a marked stub until that history can be rewritten safely. An agent asked to clean up may delete it unless the reason is written next to it, so we wrote the reason down.

Leave the gaps empty

When a document had a gap, we left it empty and said why. In a codebase where agents read the documentation as fact, a plausible number written to fill a table stops being a guess the day it is saved. It becomes what the next change is measured against.

What we would tell a team starting now

Pick one part that has something exact to port from, and build the comparison before the port. Find out what your tests would not notice before any bulk change. Write decisions down with their sources. Turn rules into checks as you go. Decide what has to stay before anyone, person or agent, is asked to delete.

People made those decisions here. We chose what to port and what to leave, set the rules and answered for the code the agents wrote. The loop that queues part of that work and waits for our approval is described in what an AI agent orchestrator does.

How this article was written

An AI assistant wrote the first draft from the decision records, the instructions for agents and the commit history in Sophia's repository. One of us reviewed and approved it before it was published. This is our experience with our own system. A client's code, tests and constraints would be different.

If you are weighing how much an old system is costing you, how to measure technical debt is a place to start. If you already know which part has to change, this is how we modernize a system one part at a time.

“AI-assisted legacy modernization: notes from our own 14-year-old codebase” by Martin Prunell is licensed under CC BY SA. Source code examples are licensed under MIT. Categorized under Engineering / AI & Agents.

Related reading