1. ai
  2. /building
  3. /legacy-migration

Legacy Migration with AI

AI can accelerate legacy migrations — framework upgrades, language ports, test backfill — when you constrain scope and verify every slice. Ungated agents rewrite entire repos.

Last reviewed: June 2026

Migration tooling varies by stack. Patterns apply across Cursor, Claude Code, and Amazon Q transformations.

Principles

PrincipleWhy
Incremental slicesOne module or route per PR
Characterization tests firstLock current behavior before refactor
Explicit forbidden pathsMigrations, prod configs, secrets
Human owns architectureAgent implements approved plan
Verify continuouslyCI after every slice

Workflow

  1. Inventory — list modules, dependencies, test coverage gaps (human + search)
  2. SpecSpec-Driven Development per slice with allowed files
  3. Tests — add characterization tests for behavior you're about to change
  4. Migrate — agent implements one slice; run full test suite
  5. ReviewAI Code Review + human CODEOWNER
  6. Repeat — next slice; never "finish the migration" in one prompt

Prompt template

Migration slice 3 of 12 — do not touch other modules.

Goal: Convert src/legacy/billing.js to TypeScript strict.
Allowed: src/legacy/billing.js → src/billing/index.ts, src/billing/index.test.ts
Forbidden: src/legacy/payments.js, database/**, config/**

Steps:
1. Add tests capturing current billing.js behavior
2. Port to TypeScript with same public API
3. Run npm test -- billing

Do not refactor unrelated code.

Stack-specific tools

StackTool / pattern
Java → modern JavaAmazon Q transformations; JetBrains inspections
.NET Framework → .NETMicrosoft migration analyzers + scoped agent
jQuery → ReactComponent-by-component; keep old until parity
Pages → App RouterRoute-by-route; Project Rules for conventions

Anti-patterns

Anti-patternResult
"Migrate entire repo to TypeScript"Unreviewable mega-PR
No tests before portSilent behavior change
Agent edits lockfiles freelyDependency chaos
Skip security review on auth pathsProduction vulnerability