How I Resurrected Legacy Code with AI: Building CodePhoenix for Kiroween

Published: (December 4, 2025 at 11:08 AM EST)
5 min read
Source: Dev.to

Source: Dev.to

The Problem: $85 Billion in Dying Code

Right now, at this very moment, the world’s banking systems are held together by COBOL code written in the 1970s. Government agencies run on Visual Basic 6 apps from the 90s. Scientific institutions depend on Fortran programs that nobody alive fully understands anymore.

Key statistics

  • $85 Billion in global technical debt
  • 220 Billion lines of COBOL still in production
  • 43 % of banking systems run entirely on COBOL
  • $500 k–$5 M average cost to migrate one legacy system
  • 6–18 months typical migration timeline
  • 92 % of IT leaders say technical debt slows innovation

The developers who wrote this code are retiring. The average COBOL programmer is 55 + years old. In 10 years, this knowledge will be gone. This isn’t just a technical problem; it’s an existential crisis for enterprise software.

The Idea: CodePhoenix – Resurrection Through AI

For the Kiroween hackathon’s “Resurrection” category, I needed to build something that literally brings dead code back to life. The phoenix metaphor was perfect—rising from the ashes of legacy systems. I only had 72 hours and was working solo, so I turned to Kiro AI.

CodePhoenix workflow

  1. Upload – Drop in your ancient legacy files (COBOL, VB6, Fortran, PHP, etc.)
  2. Analyze – AI deeply understands the business logic, data structures, security
  3. Transform – AI converts to modern languages (TypeScript, React, Python, Go)
  4. Export – Download as cloud‑ready, containerized, documented applications

All powered by Kiro AI to make the impossible possible.

Foundation with Kiro Specs

Architecture as Code

I started by writing specifications in .kiro/specs/architecture.md:

Core Architecture:
- Frontend: Next.js 14 App Router with TypeScript
- Backend: Next.js API Routes
- AI Engines: GPT‑4 for transformation, Claude for analysis
- Storage: Session‑based filesystem
- UI: Tailwind CSS with custom phoenix theme (orange/red gradients)
- Code Editor: Monaco Editor (VS Code engine)

Kiro read this single file and generated:

  • Complete Next.js 14 project structure
  • TypeScript configs with strict mode
  • Tailwind setup with custom phoenix color palette
  • API route templates
  • Component scaffolding

Vibe Coding the UI

Vibe 1: Main Upload Zone

Instructions in .kiro/vibe/coding-instructions.md:

VIBE 1: Create the main upload zone
- Drag‑and‑drop area with phoenix rising animation
- Support .cbl, .vb, .for, .php, .pas files
- Show file previews with syntax highlighting
- Animated fire particles on hover
- Error states for unsupported files

Kiro generated a complete React component with:

  • Framer Motion animations (phoenix rising on upload)
  • File validation and error handling
  • Syntax‑highlighted preview
  • Responsive mobile layout
  • Loading states
  • Accessibility (ARIA labels, keyboard navigation)

Vibe 2: Analysis Results Dashboard

VIBE 2: Create the analysis results dashboard
- Beautiful card grid showing AI analysis
- Complexity visualization (1‑10 scale with color coding)
- Security vulnerabilities with severity badges
- Business logic extraction display
- Migration roadmap timeline
- ROI calculator with interactive sliders

Kiro produced:

  • Six interconnected components
  • React Flow dependency‑graph visualization
  • Animated charts (Recharts integration)
  • Interactive ROI calculator
  • Smooth page transitions

API Routes with Steering

I needed three complex API endpoints:

  • /api/upload – handle file uploads
  • /api/analyze – AI code analysis
  • /api/transform – AI code transformation

Because the endpoints had to handle 64 file extensions, integrate with OpenAI and Anthropic APIs, preserve exact business logic, and generate accurate TypeScript types from COBOL PICTURE clauses, I created .kiro/steering/api-guidelines.md:

API Transformation Rules:

COBOL → TypeScript Mapping:
- IDENTIFICATION DIVISION → Module exports with metadata
- DATA DIVISION → Interface definitions
- PICTURE 9(5)V99 → number (with validation)
- PICTURE X(50) → string (max length 50)
- PICTURE S9(7)V99 COMP-3 → Decimal type
- PERFORM UNTIL → while loop with guard clause
- EVALUATE → switch statement with exhaustive checking

VB6 → React Mapping:
- Form → Functional component
- Control → React component with state
- Event handlers → onClick/onChange callbacks
- Recordset → Array of typed objects
- ADO connection → Fetch API or GraphQL

Using these steering rules, Kiro generated APIs that:

  • Correctly parse 64 legacy language file extensions
  • Map COBOL data types to TypeScript with ~95 % accuracy
  • Preserve business logic exactly (critical!)
  • Produce idiomatic modern code
  • Include comprehensive error handling

Result: a full‑stack application foundation that is ~85 % AI‑generated.

The Transformation Engine

The Challenge: Making AI Understand 50‑Year‑Old Code

Modern LLMs are trained on GitHub code from the 2010s‑2020s. They have seen millions of lines of TypeScript and Python, but COBOL, Fortran 77, RPG, etc., are rare in their training data. Consequently, GPT‑4 can convert COBOL to TypeScript but often makes subtle mistakes.

Bad transformation (without steering)

COMPUTE TAX-AMOUNT = INCOME * 0.20
// WRONG! Loses precision
const taxAmount = income * 0.2;

Good transformation (with steering)

// Correct – uses Decimal for exact arithmetic
const taxAmount = new Decimal(income).times(0.20);

The Solution: MCP Servers for Domain Expertise

I built three Model Context Protocol (MCP) servers in .kiro/mcp/ to give the AI expert‑level understanding of each legacy language.

COBOL Parser MCP (cobol-parser-mcp.ts)

/**
 * Capabilities:
 * - Tokenize COBOL divisions
 * - Parse PICTURE clauses to TypeScript types
 * - Extract PERFORM logic to function calls
 * - Map COPY books to imports
 * - Analyze COMP/COMP-3 binary fields
 * - Handle REDEFINES (union types)
 */

Fortran Analyzer MCP (fortran-analyzer-mcp.ts)

/**
 * Capabilities:
 * - Parse SUBROUTINE/FUNCTION blocks
 * - Analyze DO loops and GOTOs
 * - Map COMMON blocks to classes
 * - Convert FORMAT statements to template literals
 * - Handle IMPLICIT NONE type inference
 */

Legacy Database MCP (legacy-db-mcp.ts)

/**
 * Capabilities:
 * - Parse DB2/Oracle DDL
 * - Generate Prisma schema
 * - Suggest PostgreSQL migration
 * - Map hierarchical databases to relational
 */

These MCP servers feed structured ASTs and semantic metadata into Kiro, enabling transformations with 95 %+ accuracy.

Building the Diff Viewer

Users need to see the transformation side‑by‑side. I wrote a single vibe instruction:

Create an interactive code comparison viewer using Monaco Editor.

Left pane: original legacy code with syntax highlighting.  
Right pane: transformed modern code.

Features: line mapping, diff highlights, collapsible sections, export buttons.

Kiro generated a ~400‑line React component that provides:

  • Dual‑pane Monaco editors (original vs. transformed)
  • Syntax highlighting for 64 source languages + 40 target languages
  • Line‑by‑line diff highlighting
  • Collapsible sections for large files
  • Search/replace across both panes
  • Export functionality (PDF, Markdown, raw code)

Multi‑Language Support

Initially I targeted five languages; the platform now supports 64 source languages, including:

  • Mainframe Era: COBOL, RPG, JCL, PL/I, Assembler
  • Desktop Era: VB6, PowerBuilder, Delphi, FoxPro
  • Web 1.0: Classic ASP, ColdFusion, Perl CGI
  • Scientific: Fortran 77/90, ALGOL, APL
  • Systems: Pascal, Modula‑2, Ada

And 40+ target frameworks such as:

  • Web: TypeScript, React, Next.js, Vue, Angular, Svelte
  • Backend: Python, FastAPI, Django, Flask, Node.js, NestJS
  • Enterprise: Java Spring Boot, C# .NET Core, Kotlin
  • Mobile: React Native, Flutter, SwiftUI

The result is a versatile, AI‑driven platform that can resurrect virtually any legacy codebase and deliver modern, production‑ready applications.

Back to Blog

Related posts

Read more »

🌑 Into the Dark: Soulbound Codex

!Demo Imagehttps://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2...