A Two-Step AI Workflow for Legacy Code Modernization

A Reddit post on r/ClaudeAI argues against simply asking AI to 'refactor' legacy spaghetti code, noting that AI tends to preserve flawed existing structures. Instead, it proposes a two-step 'reverse engineering' workflow that leverages LLM reasoning more effectively.
The Problem with Direct Refactoring
When you paste old code into an AI agent with a request like 'Please refactor this and make it clean,' the result is often just a polished version of the same bad architecture. The AI is biased by the code you provide—it tries to preserve your structure, variable names, and logic flow, even if they were flawed from the beginning.
The Two-Step 'Reverse Engineering' Process
Step 1: Extract the Intent (The 'What')
Don't ask the AI to fix the code. Instead, ask it to ignore the code structure and extract the business logic. Specifically, have it write a high-level Business Requirement Document (BRD) based on the file. This yields the pure logic without the technical debt.
Step 2: The 'Clean Slate' Build (The 'How')
Take that fresh BRD and feed it into a 'Master Architect' prompt. Now, the AI isn't fixing old mistakes; it's building a solution from scratch using modern best practices. This approach also facilitates technology migration (e.g., from legacy Java to modern Node.js) because the intermediate BRD layer is technology-agnostic.
The post mentions that the specific 'Master Architect' prompt used for Step 2 is provided in the first comment of the Reddit thread.
📖 Read the full source: r/ClaudeAI
👀 See Also

Verification Harness Fixes Claude's Plan Execution Problem
A developer built a 30-50 line bash or Python verification layer that checks whether Claude actually executes each step of its own plans by verifying artifacts like file existence, API responses, and config changes.

Tell AI to Define Its Own Terms from First Principles for Better Outputs and Auditable Reasoning
A user on r/ClaudeAI found that adding a single instruction to break down undefined terms to atomic meaning before proceeding produces more specific outputs and enables debugging via a traceable reasoning chain.

4 Files That Made Claude Code Write Safe Prod-Database Code
A developer shares four files—CLAUDE.md, MEMORY.md, framework.md, decisions/log.md—plus a Python bridge with idempotency keys and write guards that let Claude Code safely write to a Convex prod database.

How to Fix Claude Code's CSS Guesswork with a Design System
A developer found Claude Code repeatedly regenerated misaligned HTML/CSS because it designs blind without visual feedback. The solution: provide a complete design system with spacing, colors, and type variables, then separate HTML and CSS prompts.