# Software Archaeology: Restoring Legacy Code with Generative AI

How to use Generative AI to restore legacy code?

- **Source:** [Martin Fowler](https://martinfowler.com)
- **Published:** 2026-07-16
- **Topic:** [Data & AI](https://brifing.si/c/data-ai)
- **Original article:** <https://martinfowler.com/articles/archaeologist-copilot.html>
- **On Brifing:** https://brifing.si/s/10874f5b-eb03-4e14-8212-8dc46074d62d

## The Tourist Trap

Legacy code repositories, especially those from the early 2000s, are often incompatible with modern systems. While Generative AI seems like a solution to understand and run this code, starting with a tourist approach can be misleading. This approach ignores the true state of the code.

## Misleading Optimism

Generative AI often adopts an optimistic attitude when trying to modernize code. For example, when adapting an old Java project to a modern Gradle structure, it may suggest dependencies that don't actually exist. This can prevent the code from running.

## Structural Misconceptions

AI may assume a standard Maven structure, ignoring older structures like Ant. This makes it difficult to understand the actual structure of the code and leads to misguidance. Such assumptions are particularly dangerous in legacy projects.

## Hiding Fundamental Issues

Example code generated by AI can hide fundamental issues. For instance, using a non-thread-safe class makes it harder to understand how the code actually works. This complicates the restoration process further.

## The Archaeologist Approach

Instead of the tourist approach, it's necessary to act like an archaeologist. This means understanding the true state of the code and planning the restoration process accordingly. Using AI with a critical eye is an important step in this process.

## Forensic Code Audit

Forensic Code Audit analyzes the history, structure, and health of the code. This includes evaluating which Java version the code was written in, its architectural integrity, and error management. This analysis shapes restoration decisions.

## Carbon Dating

Determining the history of the code is the first step in the restoration process. This is necessary to understand which technologies the code was written with and which era it belongs to. For example, the use of Ant indicates the project predates 2010.

## Architectural Integrity

The architectural integrity of the code is a critical factor in the restoration process. The 'Big Ball of Mud' structure, common in legacy projects, may require the code to be rewritten. This makes the code more modular and sustainable.

## Data Flow Analysis

Data flow analysis is important to understand how the code works. 'Stringly-typed' data structures, common in legacy projects, may require the code to be rewritten. This provides a safer and more consistent code structure.

## Safety Check

Error management and thread safety are important considerations in restoring legacy code. For example, swallowed exceptions or non-thread-safe classes may require the code to be rewritten. This ensures a more reliable system.

## Risk Assessment

Based on the Forensic Code Audit, it is decided whether the code needs to be restored or rewritten. This is a critical step for the future of the project. AI plays an important role in this process.

## Conclusion and Recommendations

Generative AI can be a powerful tool for restoring legacy code, but it must be used correctly. Instead of the tourist approach, the archaeologist approach should be adopted, and the true state of the code should be understood. This ensures a more robust and sustainable system.

## Sources covering this story

- https://martinfowler.com/articles/archaeologist-copilot.html — 

---

_Summary written by Brifing from the original reporting. Copyright in the original article belongs to its publisher; read the full piece at the link above._
