Inspiration

Every developer has encountered legacy code — those sprawling functions filled with magic numbers, nested conditionals, and cryptic variable names that everyone's afraid to touch. Refactoring such code is risky, time-consuming, and often avoided until it becomes a critical problem.

We asked: What if AI could safely refactor legacy code automatically?

What it does

Legacy Architect is an autonomous AI agent that transforms messy legacy code into clean, modern, tested software — completely automatically. It uses a 9-step workflow:

  1. Scans the codebase for target function usage
  2. Builds an impact map of affected files
  3. Generates characterization tests to lock in behavior
  4. Runs tests to verify baseline
  5. Calls Gemini 3 to analyze and plan refactoring
  6. Generates clean, refactored code
  7. Applies changes behind feature flag (zero risk!)
  8. Runs tests in BOTH modes (old + new)
  9. Generates an evidence report for code review

How we built it

Gemini 3 Flash Preview — Core AI engine for code analysis, test generation, and refactoring

  • Python — Agent implementation
  • pytest — Test execution framework
  • Streamlit — Beautiful interactive dashboard
  • Feature Flags — Safe rollout with BILLING_V2 environment variable

Challenges we ran into

  • Getting Gemini 3 to generate syntactically correct Python code consistently
  • Building a self-healing loop that automatically fixes failing tests
  • Ensuring the refactored code maintains 100% behavioral compatibility

Accomplishments that we're proud of

  • 24/24 tests pass in both default and feature flag modes
  • Fully autonomous — zero human intervention required
  • Production-ready — feature flag enables safe A/B testing
  • Beautiful dashboard with sparkly UI and comprehensive evidence reports

What we learned

  • Gemini 3's code understanding capabilities are remarkably powerful
  • Characterization tests are essential for safe refactoring
  • Feature flags transform risky changes into safe experiments

What's next for Legacy Architect

  • Support for multiple programming languages
  • Integration with CI/CD pipelines
  • VS Code extension for one-click refactoring

Built With

Share this project:

Updates