The failure
Add a feature inside old, coupled code and the change does not stay where you put it. The code leans on globals and big shared classes, so everything that calls them can now behave differently. Most of those paths have no test. Unit tests are hard to write there. A reviewer has to read the classes around the diff to judge it, and the diff shows only a small part of what moved.
The simulator
Start inline, in the shared code. Switch to behind the seam, pin the legacy behaviour, then port the page.
SimulatorAdd one feature to old, coupled code
- Legacy lines touched
- 660
- Legacy nodes edited
- 5
- Nodes affected
- 8 legacy · 0 new
- Untested paths affected
- 268
- Lines to read around the diff
- 22,800
- Share of the diff an architecture test can check
- 0 %
Legacy: 46,300 lines · 275 untested paths · 20 % covered. New side: 88 % covered.
Tests that reach the change
| Level | Reaches it | Why |
|---|---|---|
| Unit tests | no | No: globals and large shared classes cannot be isolated. |
| HTTP tests | no | No: nothing pins how the old pages behave yet. |
| End-to-end tests | yes | Yes: only through the server-rendered pages, which inverts the pyramid. |
Every scenario
| Scenario | Legacy lines touched | Legacy lines removed | Nodes affected | Untested paths affected | Lines to read | Checkable share | Legacy lines left |
|---|---|---|---|---|---|---|---|
| Inline, shared code (current) | 660 | 0 | 8 legacy · 0 new | 268 | 22,800 | 0 % | 46,300 |
| Inline, independent area | 550 | 0 | 4 legacy · 0 new | 144 | 7,000 | 0 % | 46,300 |
| Behind the seam | 10 | 0 | 1 legacy · 5 new | 19 | 2,000 | 99 % | 46,300 |
| Behind the seam + port | 20 | 3,000 | 1 legacy · 6 new | 23 | 3,200 | 99 % | 43,300 |
Nodes
| Node | Side | Lines | Coverage | State in this change | Calls |
|---|---|---|---|---|---|
| Front controller and router | legacy | 600 | 20 % | affected | Page controller, Other pages using the same classes, Boot the new framework |
| Shared globals | legacy | 800 | 10 % | edited | - |
| Session | legacy | 400 | 30 % | untouched | - |
| Big shared model class | legacy | 9,000 | 15 % | edited | Shared globals |
| Big service class | legacy | 6,000 | 15 % | edited | Big shared model class, Helper functions, Shared globals |
| Helper functions | legacy | 2,500 | 30 % | affected | Shared globals |
| Page controller | legacy | 3,000 | 8 % | edited | Big shared model class, Big service class, Helper functions, Server-rendered views, Shared globals, Session |
| Server-rendered views | legacy | 4,000 | 0 % | edited | Helper functions, Shared globals |
| Other pages using the same classes | legacy | 20,000 | 30 % | affected | Big shared model class, Big service class, Helper functions, Server-rendered views, Shared globals, Session |
| Boot the new framework | new | 150 | 75 % | untouched | Read the legacy session |
| Read the legacy session | new | 80 | 100 % | untouched | Session |
| Controller with early validation | new | - | - | not built | - |
| Handler | new | - | - | not built | - |
| Repository returning DTOs | new | - | - | not built | - |
| Separate front end | new | - | - | not built | - |
Model with illustrative nodes, lines and paths, not the real codebase. Coverage levels follow the real ones roughly: about 20 % on the legacy side, about 80 % on the new side.
What’s happening
The map is a model. Its nodes, lines and paths are illustrative. What it shows is how a change spreads along calls.
Inline. One edit to the globals reaches almost every legacy node, because almost every legacy node calls them. Where the feature lands matters. In an independent area the blast radius is smaller, but it still runs through the shared pages and the classes behind them. Either way, most of the paths the change can affect have no test.
Behind the seam. The legacy side gets one small edit: a route that boots the new framework. The session is the one legacy dependency. The new code sits in layers: validation early in the controller, a specific handler, a repository that returns collections and DTOs, JSON endpoints, and a separate front end.
The diff is larger, because it is mostly new code. The code a reviewer has to read around it is much smaller, and almost all of it sits in layers with an expected shape. That is also what lets an architecture test check it.
Test levels. Inline, the change is mostly reachable end to end, through the server-rendered pages. That inverts the test pyramid. Behind the seam, unit, HTTP and end-to-end tests can all reach it.
The seam is legacy code too. It has few tests. HTTP characterisation tests pin how it behaves before you change it. In the model they pin only the code you edit. Its callers stay unpinned.
Strangler fig. Once the seam exists, the legacy page a project touches can move behind it. Its route moves, its legacy lines are retired and its coverage rises. The shared classes it used stay, because other pages still need them. Legacy code left shrinks only when something is ported. Building next to it does not shrink it. Characterisation tests written against the old page keep checking the ported one, because the URLs behave the same.
Where I hit this in production
The app was 13 years old and about 500,000 to 600,000 lines, roughly 70 % backend and 30 % front end. By the numbers above, that is roughly 350,000 to 420,000 lines of backend and 150,000 to 180,000 of front end. Two frameworks lived side by side: an old one, CodeIgniter, and Symfony. Line coverage, measured by a tool, was about 20 % on the CodeIgniter code and about 80 % on the Symfony code.
The CodeIgniter code was hard to test. It relied on many globals reused in many places, on large classes that did many things and were used in many places, and on a lot of coupling.
It was not one feature. It was many features over many years. Most took a few months, bigger ones up to a year, and there were many a year. The team rotated, so the app shows layers of how things were done over time. Some features landed in the riskier parts of the app. Others were new and independent, and easier to work with. Symfony already existed in the app, but it was not fully used.
The seam. Symfony could be booted from anywhere in the legacy app. The one remaining dependency on legacy code was the session. Everything else ran on Symfony, with its conventions and tests, modules kept reusable and inside their domain, and an expected structure. Over the years the seam touched a few thousand legacy lines in total.
The new layers. Validation came early, at the controller. Then very specific handlers with a clear structure, for both POST and GET payloads. Reading data was organised too: collections were easy to retrieve and came back as DTOs with an expected structure. Endpoints returned plain JSON instead of the old framework’s server-rendered pages, so they were much easier to test. The front end was fully separate from the back end, similar to an SPA. Tests were PHPUnit, HTTP integration tests and end-to-end tests.
What it bought. Reviews were much easier, because the structure of the code was easy to see. Legacy code was replaced piece by piece while features kept shipping. Regressions concentrated in the places with more legacy code. Every new module had about 80 % coverage. Porting was targeted by which projects were being worked on, so legacy that was not changing was not blocking.
What I’d do differently. Add HTTP characterisation tests much earlier, to pin down how the legacy code behaves before changing it. And decide the structure much earlier. The strategy itself worked. The test pyramid was partly inverted, with more end-to-end tests on the legacy part, because unit tests there were hard: the dependencies and the way the old framework works got in the way.
Why it matters more with AI
Agent-written code struggled in the parts that did not follow the standards. Specific rules and architecture tests in the harness made it much easier for agents to write code there. Given a structure, an easy way to seed data and a set shape for tests, agents also wrote many more end-to-end tests. That raised coverage a lot and raised confidence in releasing.
What worked was giving developers a high-level view of how the codebase and its architecture work, so they could give agents the right rules. The company wanted more code written in this new era without losing quality. More checks, more structure and more of the codebase written to good standards meant agents could write more code on their own.