Project 31: Codebase Migration Assistant

Project 31: Codebase Migration Assistant

Build a Kiro CLI workflow that automates codebase migrations between languages or frameworks - converting JavaScript to TypeScript, React Class components to Hooks, or even entire framework migrations.

Quick Reference

Attribute Value
Difficulty Expert (Level 4)
Time Estimate 1 month
Primary Language TypeScript
Alternative Languages Python
Prerequisites Projects 1-25, deep understanding of AST manipulation
Key Topics Semantic preservation, type inference, incremental migration, behavior equivalence
Kiro CLI Concepts Custom agents, file system operations, hooks, checkpoints, testing integration
Main Book Reference โ€œWorking Effectively with Legacy Codeโ€ by Michael Feathers

1. Learning Objectives

By completing this project, you will:

  1. Master semantic-preserving code transformations: Understand how to convert code between languages while maintaining identical behavior
  2. Implement incremental migration strategies: Learn to break large migrations into safe, reversible steps with checkpoint-based rollback
  3. Design type inference systems: Build logic that derives TypeScript types from JavaScript runtime behavior and usage patterns
  4. Create automated test validation workflows: Ensure migration correctness by running tests after each transformation
  5. Build production-grade migration tooling: Understand the patterns used by tools like jscodeshift, ts-migrate, and React codemods

2. Deep Theoretical Foundation

2.1 What Is Code Migration?

Code migration is the systematic transformation of a codebase from one form to another while preserving its semantic behavior. This is fundamentally different from rewriting - migration maintains the logical structure while changing the syntactic representation.

                    THE MIGRATION TRANSFORMATION SPECTRUM

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   SYNTACTIC                                                   SEMANTIC   โ”‚
    โ”‚   CHANGES                                                     CHANGES    โ”‚
    โ”‚   โ—€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ถ  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
    โ”‚   โ”‚ Rename   โ”‚  โ”‚ JS โ†’ TS  โ”‚  โ”‚ Class โ†’  โ”‚  โ”‚ REST โ†’   โ”‚  โ”‚ Monolith โ”‚ โ”‚
    โ”‚   โ”‚ Variable โ”‚  โ”‚ (add     โ”‚  โ”‚ Hooks    โ”‚  โ”‚ GraphQL  โ”‚  โ”‚ โ†’ Micro- โ”‚ โ”‚
    โ”‚   โ”‚          โ”‚  โ”‚ types)   โ”‚  โ”‚          โ”‚  โ”‚          โ”‚  โ”‚ services โ”‚ โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
    โ”‚        โ”‚              โ”‚             โ”‚             โ”‚             โ”‚        โ”‚
    โ”‚        โ–ผ              โ–ผ             โ–ผ             โ–ผ             โ–ผ        โ”‚
    โ”‚   Mechanical     Type         Pattern       API           Architecture  โ”‚
    โ”‚   (AST-only)     Addition     Transform     Redesign      Decomposition โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   RISK: Low      RISK: Med    RISK: High   RISK: High    RISK: V.High  โ”‚
    โ”‚   AUTOMATION:    AUTOMATION:  AUTOMATION:  AUTOMATION:   AUTOMATION:   โ”‚
    โ”‚   100%           80%          60%          40%           20%           โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key Insight: The further right you go on this spectrum, the more human judgment is required. AI can automate the mechanical parts but should defer to humans for semantic decisions.

2.2 The Three Laws of Safe Migration

From โ€œWorking Effectively with Legacy Codeโ€ (Feathers, Ch. 2):

                    THE THREE LAWS OF SAFE MIGRATION

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   LAW 1: BEHAVIOR PRESERVATION                                          โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                      โ”‚
    โ”‚   "If you can't prove the new code behaves identically,                 โ”‚
    โ”‚    you haven't migrated - you've rewritten."                            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Verification methods:                                                  โ”‚
    โ”‚   โ€ข Unit tests (before = after)                                         โ”‚
    โ”‚   โ€ข Property-based tests (random inputs, same outputs)                  โ”‚
    โ”‚   โ€ข Snapshot tests (serialized output comparison)                       โ”‚
    โ”‚   โ€ข Type checks (if adding types)                                       โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   LAW 2: INCREMENTAL TRANSFORMATION                                     โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                    โ”‚
    โ”‚   "Never migrate more than you can safely roll back."                   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Strategies:                                                            โ”‚
    โ”‚   โ€ข File-by-file migration                                              โ”‚
    โ”‚   โ€ข Function-by-function within files                                   โ”‚
    โ”‚   โ€ข Checkpoint after each successful step                               โ”‚
    โ”‚   โ€ข Keep old and new code running in parallel                           โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   LAW 3: DEPENDENCY ORDER                                               โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                             โ”‚
    โ”‚   "Migrate leaves before branches, imports before exports."             โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Order of operations:                                                   โ”‚
    โ”‚   1. Utility modules (no internal dependencies)                         โ”‚
    โ”‚   2. Data models / types                                                โ”‚
    โ”‚   3. Business logic                                                     โ”‚
    โ”‚   4. API layer                                                          โ”‚
    โ”‚   5. UI components                                                      โ”‚
    โ”‚   6. Entry points                                                       โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.3 JavaScript to TypeScript: The Canonical Migration

The JSโ†’TS migration is the most common and best-understood migration path. Understanding it deeply teaches principles applicable to all migrations.

                    JS โ†’ TS MIGRATION PIPELINE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 1: INFRASTRUCTURE                                               โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                             โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚
    โ”‚   โ”‚  1. Add tsconfig.json with permissive settings                   โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข "allowJs": true                                            โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข "noImplicitAny": false (initially)                         โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข "strict": false (initially)                                โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  2. Install TypeScript and @types/* packages                    โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข npm install --save-dev typescript                          โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข npm install --save-dev @types/node @types/react ...        โ”‚   โ”‚
    โ”‚   โ”‚                                                                  โ”‚   โ”‚
    โ”‚   โ”‚  3. Update build scripts                                         โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข tsc for type checking                                      โ”‚   โ”‚
    โ”‚   โ”‚     โ€ข ts-node for development                                    โ”‚   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 2: FILE CONVERSION (Per File)                                   โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
    โ”‚   โ”‚   helpers.js     โ”‚ โ”€โ”€โ–ถ โ”‚   helpers.ts     โ”‚ โ”€โ”€โ–ถ โ”‚  Tests Pass?   โ”‚  โ”‚
    โ”‚   โ”‚                  โ”‚     โ”‚   (renamed)      โ”‚     โ”‚                โ”‚  โ”‚
    โ”‚   โ”‚  function add(   โ”‚     โ”‚  function add(   โ”‚     โ”‚  Yes: Continue โ”‚  โ”‚
    โ”‚   โ”‚    a, b          โ”‚     โ”‚    a: number,    โ”‚     โ”‚  No: Rollback  โ”‚  โ”‚
    โ”‚   โ”‚  ) { ... }       โ”‚     โ”‚    b: number     โ”‚     โ”‚                โ”‚  โ”‚
    โ”‚   โ”‚                  โ”‚     โ”‚  ): number {...} โ”‚     โ”‚                โ”‚  โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Transformation steps:                                                  โ”‚
    โ”‚   1. Rename .js โ†’ .ts                                                   โ”‚
    โ”‚   2. Fix import extensions (.js โ†’ .ts or remove)                        โ”‚
    โ”‚   3. Add explicit types to function parameters                          โ”‚
    โ”‚   4. Add explicit return types                                          โ”‚
    โ”‚   5. Fix any type errors                                                โ”‚
    โ”‚   6. Run tests                                                          โ”‚
    โ”‚                                                                          โ”‚
    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
    โ”‚                                                                          โ”‚
    โ”‚   PHASE 3: STRICTNESS ESCALATION                                        โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                        โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Enable strict mode incrementally:                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Round 1: "noImplicitAny": true                                        โ”‚
    โ”‚            Fix all implicit any errors                                   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Round 2: "strictNullChecks": true                                     โ”‚
    โ”‚            Handle null/undefined everywhere                              โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   Round 3: "strict": true                                               โ”‚
    โ”‚            Full TypeScript strictness                                    โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.4 Type Inference Strategies

When migrating from JavaScript, types must be inferred. This is where AI provides significant value:

                    TYPE INFERENCE HIERARCHY

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   INFERENCE SOURCE                        CONFIDENCE    EXAMPLE          โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   1. JSDoc annotations                    HIGHEST       /** @param {n}  โ”‚
    โ”‚      Already documented types                           * @returns {s}  โ”‚
    โ”‚                                                         */              โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   2. TypeScript inference                 HIGH          const x = 5;    โ”‚
    โ”‚      When TS can determine type                         // number       โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   3. Usage analysis                       MEDIUM        function f(x) { โ”‚
    โ”‚      How the value is used                               return x + 1;  โ”‚
    โ”‚                                                         }               โ”‚
    โ”‚                                                         // x: number    โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   4. Test data analysis                   MEDIUM        it('test', () =>โ”‚
    โ”‚      What values are passed in tests                     f(42));        โ”‚
    โ”‚                                                         // f: (n) => ?  โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   5. AI semantic analysis                 LOWER         // variable nameโ”‚
    โ”‚      Based on naming conventions                        userId          โ”‚
    โ”‚                                                         // likely stringโ”‚
    โ”‚                                                                          โ”‚
    โ”‚   6. Fallback: explicit any               LOWEST        function f(     โ”‚
    โ”‚      When all else fails                                 x: any         โ”‚
    โ”‚                                                         )               โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                    AI-ASSISTED TYPE INFERENCE

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   INPUT (JavaScript):                                                    โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                   โ”‚
    โ”‚   function processUser(user) {                                          โ”‚
    โ”‚     const name = user.firstName + ' ' + user.lastName;                  โ”‚
    โ”‚     const age = new Date().getFullYear() - user.birthYear;              โ”‚
    โ”‚     return { name, age, email: user.email };                            โ”‚
    โ”‚   }                                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   AI ANALYSIS:                                                           โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                         โ”‚
    โ”‚   โ€ข user.firstName, user.lastName โ†’ string (concatenation)              โ”‚
    โ”‚   โ€ข user.birthYear โ†’ number (arithmetic operation)                      โ”‚
    โ”‚   โ€ข user.email โ†’ string (common pattern)                                โ”‚
    โ”‚   โ€ข Return type: { name: string, age: number, email: string }          โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   OUTPUT (TypeScript):                                                   โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                                                  โ”‚
    โ”‚   interface User {                                                       โ”‚
    โ”‚     firstName: string;                                                   โ”‚
    โ”‚     lastName: string;                                                    โ”‚
    โ”‚     birthYear: number;                                                   โ”‚
    โ”‚     email: string;                                                       โ”‚
    โ”‚   }                                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   interface ProcessedUser {                                              โ”‚
    โ”‚     name: string;                                                        โ”‚
    โ”‚     age: number;                                                         โ”‚
    โ”‚     email: string;                                                       โ”‚
    โ”‚   }                                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   function processUser(user: User): ProcessedUser {                     โ”‚
    โ”‚     const name = user.firstName + ' ' + user.lastName;                  โ”‚
    โ”‚     const age = new Date().getFullYear() - user.birthYear;              โ”‚
    โ”‚     return { name, age, email: user.email };                            โ”‚
    โ”‚   }                                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.5 React Class to Hooks Migration

This migration is more complex because it involves behavioral patterns, not just types:

                    CLASS โ†’ HOOKS TRANSFORMATION

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   CLASS COMPONENT                          HOOKS EQUIVALENT              โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€                  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€            โ”‚
    โ”‚                                                                          โ”‚
    โ”‚   class Counter extends Component {        function Counter() {         โ”‚
    โ”‚                                                                          โ”‚
    โ”‚     state = { count: 0 };           โ”€โ”€โ–ถ     const [count, setCount]     โ”‚
    โ”‚                                               = useState(0);             โ”‚
    โ”‚                                                                          โ”‚
    โ”‚     componentDidMount() {           โ”€โ”€โ–ถ     useEffect(() => {           โ”‚
    โ”‚       fetchData();                           fetchData();                โ”‚
    โ”‚     }                                       }, []);                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚     componentDidUpdate(prev) {      โ”€โ”€โ–ถ     useEffect(() => {           โ”‚
    โ”‚       if (prev.id !== this.props.id)        // runs on id change        โ”‚
    โ”‚         refetch();                          refetch();                   โ”‚
    โ”‚     }                                       }, [id]);                    โ”‚
    โ”‚                                                                          โ”‚
    โ”‚     componentWillUnmount() {        โ”€โ”€โ–ถ     useEffect(() => {           โ”‚
    โ”‚       cleanup();                             return () => cleanup();     โ”‚
    โ”‚     }                                       }, []);                      โ”‚
    โ”‚                                                                          โ”‚
    โ”‚     handleClick = () => {           โ”€โ”€โ–ถ     const handleClick = () => { โ”‚
    โ”‚       this.setState({ count:                 setCount(c => c + 1);      โ”‚
    โ”‚         this.state.count + 1                };                          โ”‚
    โ”‚       });                                                                โ”‚
    โ”‚     };                                                                   โ”‚
    โ”‚                                                                          โ”‚
    โ”‚     render() {                      โ”€โ”€โ–ถ     return (                    โ”‚
    โ”‚       return (                               <button                    โ”‚
    โ”‚         <button                               onClick={handleClick}>    โ”‚
    โ”‚           onClick={this.handleClick}>         {count}                   โ”‚
    โ”‚           {this.state.count}                 </button>                  โ”‚
    โ”‚         </button>                           );                          โ”‚
    โ”‚       );                                   }                             โ”‚
    โ”‚     }                                                                    โ”‚
    โ”‚   }                                                                      โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

                    LIFECYCLE MAPPING DIAGRAM

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   CLASS LIFECYCLE          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”          HOOKS           โ”‚
    โ”‚   โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€          โ”‚   useEffect()   โ”‚          โ”€โ”€โ”€โ”€โ”€           โ”‚
    โ”‚                            โ”‚                 โ”‚                           โ”‚
    โ”‚   componentDidMount   โ”€โ”€โ”€โ–ถ โ”‚  deps: []      โ”‚   (run once on mount)     โ”‚
    โ”‚                            โ”‚                 โ”‚                           โ”‚
    โ”‚   componentDidUpdate  โ”€โ”€โ”€โ–ถ โ”‚  deps: [x,y]   โ”‚   (run when x,y change)   โ”‚
    โ”‚                            โ”‚                 โ”‚                           โ”‚
    โ”‚   componentWillUnmountโ”€โ”€โ”€โ–ถ โ”‚  return () =>  โ”‚   (cleanup function)      โ”‚
    โ”‚                            โ”‚   cleanup()    โ”‚                           โ”‚
    โ”‚                            โ”‚                 โ”‚                           โ”‚
    โ”‚   getDerivedState    โ”€โ”€โ”€โ”€โ–ถ โ”‚  useMemo()     โ”‚   (derived calculations)  โ”‚
    โ”‚   FromProps                โ”‚                 โ”‚                           โ”‚
    โ”‚                            โ”‚                 โ”‚                           โ”‚
    โ”‚   shouldComponentUpdateโ”€โ”€โ–ถ โ”‚  React.memo()  โ”‚   (memoize component)     โ”‚
    โ”‚                            โ”‚                 โ”‚                           โ”‚
    โ”‚   getSnapshotBefore  โ”€โ”€โ”€โ”€โ–ถ โ”‚  useRef() +    โ”‚   (capture before update) โ”‚
    โ”‚   Update                   โ”‚  useLayoutEffectโ”‚                          โ”‚
    โ”‚                            โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                           โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

2.6 The Checkpoint Pattern for Safe Migration

Kiro CLIโ€™s checkpoint system is essential for migration safety:

                    CHECKPOINT-BASED MIGRATION FLOW

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   Start: migration-start                                                 โ”‚
    โ”‚          โ”‚                                                               โ”‚
    โ”‚          โ–ผ                                                               โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                                                  โ”‚
    โ”‚   โ”‚ Migrate file 1   โ”‚โ”€โ”€โ”€โ–ถ Tests pass? โ”€โ”€โ”€โ–ถ Create checkpoint-file-1   โ”‚
    โ”‚   โ”‚ helpers.js โ†’ .ts โ”‚        โ”‚                     โ”‚                   โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚                     โ–ผ                   โ”‚
    โ”‚                               โ”‚              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
    โ”‚                               โ”‚              โ”‚ Migrate file 2   โ”‚        โ”‚
    โ”‚                               โ”‚              โ”‚ utils.js โ†’ .ts   โ”‚        โ”‚
    โ”‚                               โ”‚              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
    โ”‚                               โ”‚                       โ”‚                  โ”‚
    โ”‚                               โ”‚                       โ–ผ                  โ”‚
    โ”‚                               โ”‚              Tests pass?                 โ”‚
    โ”‚                               โ”‚                  โ”‚    โ”‚                  โ”‚
    โ”‚                               โ”‚              Yes โ”‚    โ”‚ No               โ”‚
    โ”‚                               โ”‚                  โ–ผ    โ”‚                  โ”‚
    โ”‚                               โ”‚         checkpoint-   โ”‚                  โ”‚
    โ”‚                               โ”‚         file-2        โ”‚                  โ”‚
    โ”‚                               โ”‚              โ”‚        โ”‚                  โ”‚
    โ”‚                               โ”‚              โ–ผ        โ–ผ                  โ”‚
    โ”‚                               โ”‚         Continue  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
    โ”‚                               โ”‚            ...    โ”‚ ROLLBACK to       โ”‚ โ”‚
    โ”‚                               โ”‚                   โ”‚ checkpoint-file-1 โ”‚ โ”‚
    โ”‚                               โ”‚                   โ”‚                   โ”‚ โ”‚
    โ”‚                               โ”‚                   โ”‚ Analyze failure   โ”‚ โ”‚
    โ”‚                               โ”‚                   โ”‚ Fix the issue     โ”‚ โ”‚
    โ”‚                               โ”‚                   โ”‚ Retry migration   โ”‚ โ”‚
    โ”‚                               โ”‚                   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
    โ”‚                               โ”‚                                          โ”‚
    โ”‚   Tests fail during โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                                          โ”‚
    โ”‚   any migration step                                                     โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

    Checkpoint naming convention:

    migration-{timestamp}-{phase}-{file-or-step}

    Examples:
    โ€ข migration-20241222-infrastructure-tsconfig
    โ€ข migration-20241222-file-src-utils-helpers
    โ€ข migration-20241222-strictness-noImplicitAny

3. Complete Project Specification

3.1 What You Will Build

A Kiro CLI agent that:

  1. Analyzes a JavaScript/React codebase to create a migration plan
  2. Converts files incrementally with checkpoint-based safety
  3. Infers and adds TypeScript types using AI
  4. Transforms React Class components to Hooks
  5. Validates each step with tests before proceeding
  6. Provides rollback capability on failures

3.2 Functional Requirements

Requirement Description
Codebase Analysis Scan project structure, identify file types, map dependencies
Migration Planning Create ordered list of files to migrate based on dependency graph
File Transformation Convert .js to .ts, add types, update imports
Pattern Transformation Convert Class โ†’ Hooks, CommonJS โ†’ ESM
Type Inference Use AI to infer types from usage patterns
Test Validation Run tests after each file, abort on failure
Checkpoint Management Create/restore checkpoints at each step
Progress Reporting Show migration status and remaining work

3.3 Non-Functional Requirements

  • Safety: Never leave codebase in broken state
  • Reversibility: Any change can be undone
  • Idempotency: Running migration twice produces same result
  • Observability: Clear logging of all transformations

4. Solution Architecture

4.1 System Architecture Diagram

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        MIGRATION ASSISTANT ARCHITECTURE                        โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚                                                                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                           CLI INTERFACE                                  โ”‚ โ”‚
โ”‚  โ”‚   kiro-cli --agent migration-assistant                                   โ”‚ โ”‚
โ”‚  โ”‚   > "Migrate this codebase from JavaScript to TypeScript"               โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                       โ”‚                                       โ”‚
โ”‚                                       โ–ผ                                       โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                         MIGRATION ORCHESTRATOR                           โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Analyzer       โ”‚  โ”‚ Planner        โ”‚  โ”‚ Executor       โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                โ”‚  โ”‚                โ”‚  โ”‚                โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Scan files   โ”‚  โ”‚ โ€ข Order files  โ”‚  โ”‚ โ€ข Transform    โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Map deps     โ”‚  โ”‚ โ€ข Create plan  โ”‚  โ”‚ โ€ข Validate     โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Detect types โ”‚  โ”‚ โ€ข Est. effort  โ”‚  โ”‚ โ€ข Checkpoint   โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚ โ”‚
โ”‚  โ”‚          โ”‚                   โ”‚                   โ”‚                      โ”‚ โ”‚
โ”‚  โ”‚          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                      โ”‚ โ”‚
โ”‚  โ”‚                              โ”‚                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                 โ”‚                                             โ”‚
โ”‚                                 โ–ผ                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                         TRANSFORMATION ENGINE                            โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Type Inferrer  โ”‚  โ”‚ Code          โ”‚  โ”‚ Pattern        โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                โ”‚  โ”‚ Transformer   โ”‚  โ”‚ Converter      โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข JSDoc parse  โ”‚  โ”‚               โ”‚  โ”‚                โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Usage anal.  โ”‚  โ”‚ โ€ข Rename file โ”‚  โ”‚ โ€ข Classโ†’Hooks  โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข AI inference โ”‚  โ”‚ โ€ข Add types   โ”‚  โ”‚ โ€ข CJSโ†’ESM      โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚               โ”‚  โ”‚ โ€ข Fix imports โ”‚  โ”‚ โ€ข Default exp. โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                 โ”‚                                             โ”‚
โ”‚                                 โ–ผ                                             โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚  โ”‚                          SAFETY LAYER                                    โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ Test Runner    โ”‚  โ”‚ Checkpoint     โ”‚  โ”‚ Rollback       โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ (Hook)         โ”‚  โ”‚ Manager        โ”‚  โ”‚ Handler        โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚                โ”‚  โ”‚                โ”‚  โ”‚                โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Jest/Vitest  โ”‚  โ”‚ โ€ข Save state   โ”‚  โ”‚ โ€ข Detect fail  โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Validate     โ”‚  โ”‚ โ€ข Track files  โ”‚  โ”‚ โ€ข Restore      โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ”‚ โ€ข Report       โ”‚  โ”‚ โ€ข Timestamp    โ”‚  โ”‚ โ€ข Report       โ”‚            โ”‚ โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜            โ”‚ โ”‚
โ”‚  โ”‚                                                                          โ”‚ โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚
โ”‚                                                                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4.2 Data Flow Diagram

                    MIGRATION DATA FLOW

    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
    โ”‚                                                                          โ”‚
    โ”‚   USER REQUEST                                                           โ”‚
    โ”‚   "Migrate src/utils/ to TypeScript"                                     โ”‚
    โ”‚                    โ”‚                                                     โ”‚
    โ”‚                    โ–ผ                                                     โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    ANALYSIS PHASE                               โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Input: Source directory                                       โ”‚    โ”‚
    โ”‚   โ”‚   Output: FileAnalysis[]                                        โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   {                                                             โ”‚    โ”‚
    โ”‚   โ”‚     path: "src/utils/helpers.js",                              โ”‚    โ”‚
    โ”‚   โ”‚     imports: ["lodash", "./constants"],                        โ”‚    โ”‚
    โ”‚   โ”‚     exports: ["formatDate", "parseNumber"],                    โ”‚    โ”‚
    โ”‚   โ”‚     hasJSDoc: true,                                            โ”‚    โ”‚
    โ”‚   โ”‚     linesOfCode: 145,                                          โ”‚    โ”‚
    โ”‚   โ”‚     complexity: "medium"                                       โ”‚    โ”‚
    โ”‚   โ”‚   }                                                             โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                   โ”‚                                      โ”‚
    โ”‚                                   โ–ผ                                      โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    PLANNING PHASE                               โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   Input: FileAnalysis[]                                         โ”‚    โ”‚
    โ”‚   โ”‚   Output: MigrationPlan                                         โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   {                                                             โ”‚    โ”‚
    โ”‚   โ”‚     phases: [                                                   โ”‚    โ”‚
    โ”‚   โ”‚       { name: "infrastructure", files: [...] },                โ”‚    โ”‚
    โ”‚   โ”‚       { name: "utilities", files: [...] },                     โ”‚    โ”‚
    โ”‚   โ”‚       { name: "components", files: [...] }                     โ”‚    โ”‚
    โ”‚   โ”‚     ],                                                          โ”‚    โ”‚
    โ”‚   โ”‚     estimatedTime: "2 hours",                                  โ”‚    โ”‚
    โ”‚   โ”‚     totalFiles: 12                                             โ”‚    โ”‚
    โ”‚   โ”‚   }                                                             โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                   โ”‚                                      โ”‚
    โ”‚                                   โ–ผ                                      โ”‚
    โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
    โ”‚   โ”‚                    EXECUTION PHASE (Per File)                   โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”   โ”‚    โ”‚
    โ”‚   โ”‚   โ”‚ Checkpointโ”‚โ”€โ–ถโ”‚ Transform โ”‚โ”€โ–ถโ”‚ Test      โ”‚โ”€โ–ถโ”‚ Next or   โ”‚   โ”‚    โ”‚
    โ”‚   โ”‚   โ”‚ Create    โ”‚  โ”‚ File      โ”‚  โ”‚ Validate  โ”‚  โ”‚ Rollback  โ”‚   โ”‚    โ”‚
    โ”‚   โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜   โ”‚    โ”‚
    โ”‚   โ”‚                                                                 โ”‚    โ”‚
    โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ”‚
    โ”‚                                                                          โ”‚
    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

4.3 Key Data Structures

// Core types for migration assistant

interface FileAnalysis {
  path: string;
  type: 'javascript' | 'typescript' | 'jsx' | 'tsx';
  imports: ImportAnalysis[];
  exports: ExportAnalysis[];
  hasJSDoc: boolean;
  hasReactClasses: boolean;
  linesOfCode: number;
  complexity: 'low' | 'medium' | 'high';
  dependencyDepth: number;  // How many files depend on this
}

interface MigrationPlan {
  phases: MigrationPhase[];
  estimatedTime: string;
  totalFiles: number;
  warnings: string[];
}

interface MigrationPhase {
  name: string;
  description: string;
  files: FileMigration[];
  dependencies: string[];  // Phase names this depends on
}

interface FileMigration {
  sourcePath: string;
  targetPath: string;
  transformations: Transformation[];
  estimatedEffort: 'low' | 'medium' | 'high';
}

interface Transformation {
  type: 'rename' | 'addTypes' | 'classToHooks' | 'updateImports';
  description: string;
  automated: boolean;
  requiresReview: boolean;
}

interface MigrationState {
  plan: MigrationPlan;
  currentPhase: number;
  currentFile: number;
  completedFiles: string[];
  failedFiles: FileMigrationError[];
  checkpoints: Checkpoint[];
  startedAt: Date;
  status: 'planning' | 'executing' | 'paused' | 'completed' | 'failed';
}

interface Checkpoint {
  id: string;
  timestamp: Date;
  phase: string;
  file: string;
  gitCommit: string;
  description: string;
}

5. Phased Implementation Guide

Phase 1: Analysis Foundation (Days 1-7)

Goals:

  • Build file scanning and analysis
  • Create dependency graph
  • Implement basic type detection

Tasks:

  1. Create file scanner that identifies JS/TS/JSX/TSX files
  2. Parse imports/exports using AST (babel parser)
  3. Build dependency graph using topological sort
  4. Detect JSDoc annotations
  5. Identify React class components

Milestone Checkpoint:

$ kiro-cli --agent migration-assistant
> "Analyze src/ for migration"

[Analysis] Scanning src/...
โ”œโ”€โ”€ Found 156 JavaScript files
โ”œโ”€โ”€ Found 23 React class components
โ”œโ”€โ”€ Dependency depth: 5 levels
โ””โ”€โ”€ Estimated migration effort: 45 files/hour

Hint 1: Start with a simple regex-based import detector before moving to full AST parsing.

Hint 2: Use @babel/parser with { sourceType: 'module', plugins: ['jsx'] } for JavaScript files.

Phase 2: Migration Planning (Days 8-14)

Goals:

  • Create ordered migration plan
  • Estimate effort per file
  • Generate human-readable plan

Tasks:

  1. Implement topological sort for file ordering
  2. Group files into logical phases
  3. Estimate effort based on complexity metrics
  4. Generate plan preview for user approval
  5. Store plan as JSON for resumability

Milestone Checkpoint:

> "Create migration plan"

[Plan] Generated migration plan:
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Phase 1: Infrastructure (3 files)                                   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - Add tsconfig.json                                                 โ”‚
โ”‚ - Add @types packages                                               โ”‚
โ”‚ - Update build scripts                                              โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Phase 2: Utilities (12 files, ~30 min)                             โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - src/utils/helpers.js โ†’ .ts                                        โ”‚
โ”‚ - src/utils/validators.js โ†’ .ts                                     โ”‚
โ”‚ - ...                                                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Proceed with migration? [Y/n]

Hint 3: Leaf modules (no internal dependencies) should be migrated first - they are the safest starting point.

Phase 3: Type Inference Engine (Days 15-21)

Goals:

  • Extract types from JSDoc
  • Infer types from usage patterns
  • Use AI for complex inference

Tasks:

  1. Parse JSDoc comments with doctrine
  2. Build usage analyzer (track how values are used)
  3. Create AI prompts for type inference
  4. Generate TypeScript interfaces
  5. Handle common patterns (arrays, objects, callbacks)

Milestone Checkpoint:

> "Migrate src/utils/helpers.js"

[Inference] Analyzing helpers.js...
โ”œโ”€โ”€ Found 3 JSDoc annotations
โ”œโ”€โ”€ Inferred 5 types from usage
โ”œโ”€โ”€ AI suggested 2 additional types

[Types] Generated interfaces:
interface User {
  id: string;
  name: string;
  email: string;
}

Proceed with transformation? [Y/n]

Hint 4: For AI inference, provide 3-5 lines of context around each function, including any calls to it.

Phase 4: Transformation Engine (Days 22-28)

Goals:

  • Rename files safely
  • Add type annotations
  • Update imports across codebase

Tasks:

  1. Implement file renaming with git mv
  2. Build AST transformer for type insertion
  3. Update import statements project-wide
  4. Handle edge cases (re-exports, barrel files)
  5. Integrate with test runner hook

Milestone Checkpoint:

> "Start migration"

[Migration] Phase 2: Utilities
[File 1/12] helpers.js โ†’ helpers.ts
โ”œโ”€โ”€ Added 8 type annotations
โ”œโ”€โ”€ Inferred return types for 3 functions
โ”œโ”€โ”€ Updated 15 import statements in other files
โ”œโ”€โ”€ [Hook: test] Running tests... โœ“ (24/24 passing)
โ””โ”€โ”€ โœ“ Checkpoint created: migration-20241222-utils-helpers

[File 2/12] validators.js โ†’ validators.ts...

Phase 5: Pattern Transformation (Days 29-35)

Goals:

  • Convert React class components to hooks
  • Handle lifecycle methods correctly
  • Preserve component behavior

Tasks:

  1. Detect class component patterns
  2. Map lifecycle methods to hooks
  3. Convert state to useState
  4. Handle refs, context, error boundaries
  5. Validate with React-specific tests

Hint 5: Error boundaries cannot be converted to hooks - they must remain class components.


6. Testing Strategy

6.1 Unit Tests

describe('TypeInference', () => {
  it('should infer number from arithmetic usage', () => {
    const code = `
      function double(x) {
        return x * 2;
      }
    `;
    const types = inferTypes(code);
    expect(types.parameters.x).toBe('number');
    expect(types.returnType).toBe('number');
  });

  it('should extract types from JSDoc', () => {
    const code = `
      /**
       * @param {string} name
       * @returns {boolean}
       */
      function isValid(name) {
        return name.length > 0;
      }
    `;
    const types = extractJSDocTypes(code);
    expect(types.parameters.name).toBe('string');
    expect(types.returnType).toBe('boolean');
  });
});

6.2 Integration Tests

describe('FileMigration', () => {
  it('should migrate JS file to TS with types', async () => {
    const input = `
      export function add(a, b) {
        return a + b;
      }
    `;

    const output = await migrateFile(input, 'helpers.js');

    expect(output).toContain('function add(a: number, b: number): number');
    expect(output).not.toContain('any');
  });

  it('should update imports in dependent files', async () => {
    await migrateFile('helpers.js');

    const consumer = fs.readFileSync('consumer.ts', 'utf-8');
    expect(consumer).toContain("from './helpers'");
    expect(consumer).not.toContain("from './helpers.js'");
  });
});

6.3 Rollback Tests

describe('Checkpoint Rollback', () => {
  it('should restore to checkpoint on test failure', async () => {
    const checkpoint = await createCheckpoint('before-migration');

    await migrateFile('helpers.js');

    // Simulate test failure
    mockTestRunner.mockReturnValue({ passed: false });

    await runTests();

    // Should auto-rollback
    const currentFile = fs.readFileSync('helpers.js', 'utf-8');
    expect(currentFile).toBe(originalContent);
  });
});

7. Common Pitfalls and Debugging

7.1 Common Migration Failures

Pitfall Symptom Solution
Circular dependencies Migration order fails Detect cycles in dependency graph, migrate together
Dynamic imports Missed import updates Search for require() and dynamic import()
Implicit any spreading Types donโ€™t propagate Enable noImplicitAny early to catch issues
React context types Runtime errors Extract context types separately before migration
Test file migration Tests fail after migration Migrate test files with their source files

7.2 Debugging Strategies

1. Enable verbose transformation logging:

const transformer = createTransformer({
  onTransform: (node, change) => {
    console.log(`[Transform] ${node.type}: ${change.description}`);
  }
});

2. Validate AST before and after:

const beforeAST = parse(originalCode);
const afterAST = parse(transformedCode);

// Compare structure
expect(afterAST.body.length).toBe(beforeAST.body.length);

3. Use TypeScript compiler API for validation:

import * as ts from 'typescript';

function validateTypes(code: string): ts.Diagnostic[] {
  const program = ts.createProgram(['temp.ts'], {
    noEmit: true,
    strict: true
  });
  return ts.getPreEmitDiagnostics(program);
}

8. Extensions and Challenges

8.1 Beginner Extensions

  • Add support for migrating test files alongside source files
  • Generate migration report with statistics
  • Add dry-run mode that shows changes without applying

8.2 Intermediate Extensions

  • Support React Class to Hooks conversion
  • Handle monorepo structures with multiple packages
  • Add ESLint auto-fix for common issues post-migration

8.3 Advanced Extensions

  • Multi-language migration (Python 2 to 3, Vue 2 to 3)
  • Machine learning model to predict migration difficulty
  • Parallel migration with conflict resolution

9. Real-World Connections

9.1 Industry Tools Using These Patterns

Tool Pattern Used Company
ts-migrate Incremental TS migration Airbnb
jscodeshift AST transformation Facebook
react-codemod Class to Hooks React Team
flow-to-ts Type system migration Khan Academy

9.2 Production Migration Stories

  • Airbnbโ€™s TypeScript Migration: 2+ million lines over 2 years using ts-migrate
  • Stripeโ€™s React Migration: 500+ class components to hooks with automated testing
  • Microsoftโ€™s TypeScript Adoption: Gradual strictness escalation pattern

10. Self-Assessment Checklist

Understanding Verification

  • I can explain why leaf modules should be migrated first
  • I can describe the difference between syntactic and semantic migration
  • I can list at least 3 sources of type inference (JSDoc, usage, AI)
  • I can explain why checkpoints are essential for safe migration
  • I can describe the lifecycle method to hooks mapping

Implementation Verification

  • My analyzer correctly identifies file dependencies
  • My planner creates a valid topological order
  • Type inference works for simple functions
  • Checkpoints are created before each file transformation
  • Rollback works when tests fail
  • Import statements are updated across the codebase

Integration Verification

  • The full migration flow works on a sample project
  • AI inference improves type coverage beyond whatโ€™s possible with JSDoc alone
  • The migration can be paused and resumed
  • Progress is visible throughout the migration

11. Completion Criteria

Minimum Viable Completion

  • Analyzes JavaScript codebase and creates migration plan
  • Renames .js to .ts files
  • Adds explicit any types where needed
  • Creates checkpoints after each file
  • Runs tests after each transformation

Full Completion

  • Infers types from JSDoc and usage patterns
  • Uses AI for complex type inference
  • Converts React class components to hooks
  • Updates all import statements automatically
  • Provides detailed migration report

Excellence (Going Above and Beyond)

  • Handles monorepo structures
  • Parallel migration with smart ordering
  • Machine learning-based difficulty prediction
  • Visual diff tool for reviewing changes
  • Resume from any checkpoint

This guide was expanded from LEARN_KIRO_CLI_MASTERY.md. For the complete learning path, see the README.