Reverse engineering an existing system: what to do when the code works but no one really understands it

Reverse engineering an existing, undocumented system begins with building control and safety around it before touching the code itself, so you can change it without breaking production and know whether you succeeded.

In short

You do not start by reading the code; you start by building a protective layer that lets you touch the system without putting production at risk. A safety net. The safety net is the ability to run the system in a separate environment on a copy of the data and compare its output one-to-one with production output for the same input. From the outside in. Mapping from the outside in means starting with everything that enters the system and everything that leaves it, because that list is finite and far shorter than the volume of code. Rules that are written nowhere. The real difficulty is not in the technical details but in the decision about those rules that are documented nowhere: for each of them you have to decide whether it is a genuine requirement or a fault the organization has learned to live with, and that decision belongs to the business.

The order of work, and why the order itself is the point

Stage What you do Why it comes before the next one
1. Safety net Build a separate environment, load a copy of the data into it, and make sure its output can be compared with production output for the same input. Without a safety net, every change to the system is a gamble, because there is no systematic way to know whether something broke. This is also the stage that gives the fastest initial sense of confidence.
2. Mapping from the outside Create a complete list of every input and every output: screens, files, interfaces, reports, messages, scheduled jobs. Every entry point and exit point. This list describes the behavior that must be preserved, and it is far shorter in scale than the size of the code.
3. Tracing the rules Work backward from the output: for each output, establish where every field came from, which data fed it, and under what conditions it changes. At this stage you do read code, but only to answer precise questions, not as open-ended reading. Open-ended code reading turns into work that never ends.
4. Business decision For every surprising rule uncovered along the way, decide whether it is a requirement that must be preserved or a fault the business has adapted to and that should be fixed. This is the one decision that cannot be made without the business, and it is the one that defines the scope of the work and where effort should be invested.
5. Partial replacement Replace one part of the mechanism at a time, run the old and the new in parallel until the outputs are identical, and only then switch off the old component. This is how change becomes safe and predictable. A full rewrite requires knowing in advance exactly what is missing, which makes it riskier.

The order of operations is the heart of the matter: almost every failure in taking control of a system comes from reversing the first two stages. People start by reading code, and after two weeks they have a partial understanding, make a first change without a safety net, and the system breaks somewhere no one connected to that change.

The rules that are not written down

The genuinely complex part of the project is identifying and managing undocumented rules, and it is not a technical challenge but a management and business one.

A system that has been running for years accumulates rules with no clear origin: a calculation that rounds in one specific way, an edge case handled once at a customer's request, a field treated as empty only if it is empty in one particular way and not another, or behavior that came from a bug and around which the business has already built its procedures.

The difficulty is not in finding the rules but in deciding what to do about them, because mapping backward from the output reveals them. Requirement or fault. For each rule, you have to decide whether it is a requirement that must be preserved or a fault that has become part of daily life, and that is a purely business decision: preserving everything automatically preserves mistakes, and fixing everything automatically breaks processes that work. Both approaches look careful, and both are wrong.

How to manage it in practice. Keep one visible list in which every surprising rule is recorded as a row with three columns: what it actually does, who is affected if it changes, and what the decision about it is. This list is the real output of the work, and sometimes it matters more than the code itself, because it is the documentation that never existed.

Why a full rewrite fails

A full rewrite of a system sounds like a clean solution: the code is old, so you write it again properly. But that logic is exactly where the failure begins.

A full rewrite requires knowing all the rules and behaviors in advance, and that is exactly the knowledge that is missing. In practice, the new version quickly reaches around eighty percent of the behavior and then gets stuck on the twenty percent made up of rules that were never written down, while the old system keeps running, and now you are maintaining two systems that both receive change requests.

Partial replacement spreads the risk: each time you take out one part, run it in parallel with the old one and prove they match before switching off. On paper the move may look slower, but it also reaches the finish line, and that is the difference that decides it.

Three measures of control

A feeling that "we understand the system" is not a management measure, so it has to be replaced with clear measures that can actually be checked.

  1. You can stand the system up from scratch in a new environment, from a proper document, without relying on one person who remembers everything. If one particular person is needed to bring the system up, there is no real control.
  2. You can release a small change and know that nothing broke. The safety net from the first stage exists precisely for this: to allow a small change to be released while systematically checking that no damage was done.
  3. There is no person without whom a release is impossible. As long as there is a single person without whom a version cannot be released, there is a risk that critical knowledge sits only with that person and nobody has written it down.

These three measures also define when you can stop: the goal is not perfect code but the ability to change it safely, and from there you move forward at a pace that suits the business. Related: Architecture review, Why an architect.

A common case: moving development to another vendor

When you move development to another vendor, you are effectively doing exactly the same work, but under time pressure and with a party that has no real interest in helping beyond what it committed to, so it is important to define what must get done. Before the relationship ends, you must secure three things, in a clear order of priority.

  • A complete copy of everything needed to set the system up. You need a complete copy of everything required to set up the system, and a practical check that the setup actually works on your side, not just confirmation that the files were handed over. Receiving a file is not the same as having a working system.
  • Permissions and accounts in your name. Permissions and accounts for every relevant service must be transferred to you in your name: cloud, repository, signing certificates, external services. This is usually the part that takes the most time, and people tend to put it off until the end.
  • One hour with the person who wrote it, recorded, in which you ask one simple question: "What is broken that we don't know about?" The answer to that question is worth more than any formal handover document.

How we work on this

Working in the field since 2004, on AI systems since 2023, and on projects for clients in fourteen countries. A significant part of that work has been exactly this situation: a system that runs, with no documentation, and the person who knew it in depth is no longer around.

A review like this produces a working safety net, a formal document of all inputs and outputs, a list of unwritten rules with an explicit decision for each one, a priority order for partial replacement based on risk, and the three measures above defined as a starting state and a target state. What it does not produce is a recommendation for a full rewrite before the first three stages have been completed.

Where to start

The starting point is identifying the critical dependency. Answer one question: if your system had to be set up from scratch on a new server tomorrow, who is the person who would have to be in the room? If there is one obvious name, that is the risk, and that is where you start.

Talk to us | Related: Architecture review, Why an architect, Custom software development

Is the system written in Magic, uniPaaS, Access or VB6? See Migrating legacy systems.

SLAtech LTD