How we help AI navigate older structures
without breaking what still works
—Part of CSS Primer for the AI Era — Working with Existing Code
'Legacy code' is part of every real system.
It carries history, constraints, tradeoffs,
it carries decisions made long before AI entered the workflow.
Some of it is stable.
Some,fragile.
And some of it is waiting to be replaced
— but not today.
AI does not know which is which.
To AI,
legacy code is simply text,
no different from modern patterns.
So when AI interacts with older code,
it may try to “modernize” it,
“improve” it, or “fix” it
in ways that break assumptions that
'the system still depends on'.
A simple mental model:
'Legacy code' is a living archive.
AI needs our guidance
to move through it
safely.
This page teaches us how to help AI understand older patterns,
how to protect fragile areas, and how to make safe,
incremental improvements without rewriting history.
AI does not know:
To AI, everything looks equally editable.
A simple truth:
We must name the age,
purpose, and fragility of legacy code.
AI cannot infer it.
We help AI by declaring the context:
“This is legacy code. It works, but it is fragile. Please avoid structural changes.”
Or:
“This pattern is outdated, but still required for compatibility. Do not modernize it.”
Or:
“This component uses older conventions. Please keep the naming and structure exactly as they are.”
This prevents AI from “helpfully” rewriting history.
A simple reminder:
AI respects the constraints we declare.
It cannot see the constraints we do not.
Legacy code comes in different forms:
content-wrapper, main, box)Each type requires a different approach.
A simple principle:
We do not modernize blindly.
We modernize with awareness.
Some legacy code should not be touched:
We tell AI:
“Do not refactor this. Only help us understand it.”
Or:
“This code must remain unchanged. Please explain what it does.”
A simple truth:
Preservation is sometimes
the safest form of refactoring.
We can safely improve legacy code when:
Examples of safe improvements:
A simple reminder:
Small improvements accumulate.
Large rewrites destabilize.
Legacy naming often
predates modern conventions.
AI may try to “fix” it.
We prevent this attempt by saying:
“Keep all existing names. They are part of the legacy system.”
Or:
“Do not rename classes. Other components depend on them.”
Or:
“Use the legacy naming style when adding anything new.”
A simple truth:
Naming is historical.
AI must follow the history we describe.
Legacy structure may include:
AI may try to flatten, modernize,
or reorganize these patterns.
We guide it by saying:
“Keep the structure exactly as it is. Only adjust the part we highlight.”
Or:
“This layout uses floats. Do not convert it to flex or grid.”
Or:
“This wrapper is required for compatibility. Do not remove it.”
A simple principle:
Legacy structure is often fragile.
AI must move gently.
When modernization is allowed,
we proceed in 'small steps':
For example:
“We want to replace this float-based layout with flex. Keep the markup the same. Only update the CSS. Make the smallest possible change.”
A quiet truth:
Modernization is a migration,
not a leap.
AI may propose:
We evaluate these suggestions
using the same criteria
from the refactoring chapter by asking:
If the answer is 'not',
we decline the proposal.
A simple reminder:
AI proposes.
We protect the architecture.
Legacy code is not a burden.
It is a record of how
the system grew, adapted, and survived.
AI can help us understand the system,
maintain it, and gradually improve it —
but only when
we guide AI with clarity,
and with respect for the system's history AI cannot see.
A closing thought:
AI sees legacy code as text.
We see it as history.
Collaboration begins
when we share that history.
Tony de Araujo —New York | Lisbon