Your 15-year-old codebase wasn't built for AI. It can still be saved.
We've migrated codebases written in COBOL, classic ASP, and PHP 5.2 -- systems where the original developers left the company a decade ago and the documentation consists of three outdated wiki pages. Every one of those projects is now running AI-first development. The migration wasn't painless, but it was cheaper than the alternative: letting technical debt compound at 20-30% per year until the system collapses under its own weight.
Here's the playbook that works.
Why Legacy Codebases Are Different
AI coding tools trained on GitHub's 100 million+ repositories have a blind spot. They learned from modern, well-structured code:
They struggle -- sometimes catastrophically -- with:
The good news is real. AI can still add massive value to legacy work. But you need a different approach than greenfield development.
Assessment: Know What You're Working With
Skipping assessment is the number one reason legacy migrations fail. Spend 2-3 days here before writing a single line of new code.
Technical Assessment
Language and Framework:
Code Quality:
Dependencies:
Documentation:
Business Assessment
Usage Patterns:
Risk Tolerance:
Timeline Pressure:
The Migration Strategies
Four strategies. One will fit your situation. Pick wrong, and you'll spend 6 months discovering why.
Strategy 1: The Strangler Pattern
What it is: Gradually replace legacy components with new AI-first implementations while keeping the old system running. Named after the strangler fig tree that grows around its host until the host is gone.
How it works: Identify a self-contained component Build a new version using AI-first methods Route traffic/calls to the new component Retire the old component Repeat
Best for:
AI role:
Strategy 2: The Modernization Layer
What it is: Add a modern layer on top of legacy code, using AI to build new features while legacy handles core operations.
How it works: Create a clean API layer over legacy code All new features use the API, built AI-first Gradually refactor what's behind the API Legacy becomes internal implementation detail
Best for:
AI role:
Strategy 3: The Big Bang Rewrite
What it is: Replace the entire system with a new AI-first implementation.
How it works: Document all functionality Build new system from scratch using AI-first Migrate data Switch over
Best for:
AI role:
Warning: Big bang rewrites fail more often than they succeed. Netscape tried it and nearly died. Only choose this if the existing system is genuinely beyond repair -- not just ugly.
Strategy 4: AI-Assisted Understanding
What it is: Use AI to understand, document, and incrementally improve legacy code without major restructuring. Think of it as learning to live with the legacy, not escaping it.
How it works: Use AI to analyze and document existing code Use AI to write tests for existing behavior Use AI to make targeted improvements Build institutional knowledge using AI analysis
Best for:
AI role:
Step-by-Step Migration Process
Theory is cheap. Here's the exact Strangler Pattern process we've used on 8 client migrations since 2024:
Step 1: Map the System (Days 1-3)
Use AI to build the first draft of your system map:
"Analyze this codebase and identify:
- Major components and their responsibilities
- Dependencies between components
- External integrations
- Entry points and APIs"
AI won't perfectly understand legacy code -- expect 60-70% accuracy on the first pass. But 70% is infinitely better than the blank whiteboard you're staring at now.
Step 2: Prioritize Components
Rank components by:
Start with high-value, frequently-changed, isolated components that AI handles well.
Step 3: Document Behavior
Before replacing anything, capture current behavior:
- •AI-assisted documentation: Use AI to generate documentation from code
- •Characterization tests: Use AI to write tests capturing current behavior
- •Integration mapping: Document all integration points
Step 4: Build the Replacement
Use AI-first development to build the new component:
- Define clear interfaces
- Use AI to implement functionality
- Write comprehensive tests
- Review and refine as described in AI Code Review
Step 5: Run in Parallel
Deploy both old and new, comparing results:
- •Route a percentage of traffic to new implementation
- •Compare outputs between old and new
- •Monitor for discrepancies
- •Fix issues before full cutover
Step 6: Complete Migration
Once confident:
Step 7: Repeat
Move to the next component. The first one takes 3x longer than expected. The second takes 2x. By the fourth, you're running at full speed. This acceleration is the compound interest of migration -- it rewards patience.
Common Challenges and Solutions
Challenge: AI Doesn't Understand Our Custom Framework
Solution: Context is everything. Feed AI 3-5 examples of your patterns before asking it to generate:
"Our codebase uses a custom ORM that works like this: [example]. Following this pattern, implement..."
Challenge: No Tests to Verify Behavior
Solution: Generate characterization tests using AI:
"Analyze this function and generate tests that capture its current behavior, including edge cases."
Run these tests against both old and new implementations.
Challenge: Hidden Dependencies Everywhere
Solution: Incremental interface extraction:
- Identify all callers of a component
- Create an explicit interface
- Route calls through the interface
- Replace implementation behind the interface
Challenge: Business Logic in Database Procedures
Solution: Treat procedures as another interface:
- Document procedure behavior
- Consider keeping procedures as-is
- Or extract logic to application layer gradually
Challenge: Knowledge Is in People's Heads
Solution: This is the scariest risk in legacy migration. When Bob retires, 15 years of context walks out the door. AI-assisted knowledge capture must happen before it's too late:
- Interview subject matter experts with a structured template (we use 14 questions)
- Use AI to organize, cross-reference, and structure their knowledge
- Generate documentation from interviews, validated against the actual code
- Run the documentation past 2-3 developers -- if they can onboard using it, it's good enough
Measuring Migration Success
What gets measured gets migrated. Track these across every sprint:
- •Percentage of codebase using AI-first methods (target: 5% increase per month)
- •Test coverage for migrated components (target: 80%+ from day one)
- •Deployment frequency (should increase 2-3x within 3 months)
- •Production incident rate (should decrease 30-40% within 6 months)
Technical Metrics
- •Time to implement new features (measure before and after -- the delta is your proof)
- •Bug fix turnaround time (from hours to minutes for migrated components)
- •Developer satisfaction scores (survey quarterly; migration burnout is real)
- •Onboarding time for new developers (the ultimate test of documentation quality)
Productivity Metrics
- •Feature delivery velocity (the metric your CEO actually cares about)
- •System reliability measured in nines (99.9% vs 99.99% is a 10x difference in downtime)
- •Maintenance costs as a percentage of total engineering spend
Business Metrics
When NOT to Migrate
Not every legacy system deserves rescue. Save your energy for battles you can win:
- •System is being retired within 18 months: Don't modernize what you're replacing. Just keep it alive.
- •It ain't broke: Stable, rarely-changed code that handles 0 support tickets per quarter can stay as-is. Forever.
- •Cost exceeds benefit: Run the actual numbers using our ROI framework. If migration costs 2x what it saves over 3 years, don't do it.
- •Team isn't ready: AI-first development requires cultural change. Forcing it on a resistant team doesn't produce modernization -- it produces turnover.
Frequently Asked Questions
How long does legacy migration take?
Months to years depending on system size. A 100,000-line monolith typically takes 6-9 months using the Strangler Pattern with 2-3 developers. Plan for incremental progress, not overnight transformation.
Can AI understand COBOL/Fortran/[old language]?
Partially. AI reads COBOL better than most junior developers can, but generation quality drops to 40-50% accuracy compared to 85%+ for modern languages. Focus AI on building the new code, not rewriting the old.
Should we migrate everything?
Never. Apply the 80/20 rule ruthlessly: migrate the 20% of code that delivers 80% of business value. Some legacy systems will run unchanged until the hardware dies. That's fine.
How do we convince stakeholders?
Numbers. Not slides. Run a 2-week pilot on one component. Measure time savings, bug rates, and developer satisfaction before and after. Present the delta. Executives don't argue with data.
Getting Started
Five steps. Start this week:
- Assess your situation using the technical and business criteria above (2-3 days)
- Choose a strategy that fits your risk tolerance and timeline (1 day)
- Pick a pilot component that's high-value, frequently changed, and isolated enough to migrate safely (1 day)
- Execute with AI-first methods and measure everything (2-4 weeks)
- Present results and iterate -- let the data make the case for scaling
Contact us to discuss your legacy modernization challenges. We've navigated migrations from COBOL to cloud-native, PHP 4 to modern frameworks, and monoliths to microservices -- and we can help assess your specific situation.
