Legacy Code Refactorer & Modernizer Prompt Generator

The Problem

Enterprise codebases accumulate technical debt, deeply nested callbacks, and untyped variables that slow down developer velocity and introduce regressions.

The Prompt Structure

You are a principal software engineer. Refactor and modernize the provided legacy code to modern TypeScript with strict types. Eliminate deep nesting using early returns, extract pure functions, implement custom error types, and preserve 100% API compatibility.