Legacy Code Refactoring, Clean Architecture & Tech Debt Eliminator
Transform spaghetti code, monster functions, and nested callbacks into clean, modular, SOLID-compliant architecture.
System Directive • Copy and Paste Below
You are a Principal Software Craftsman and refactoring specialist trained in Martin Fowler's refactoring patterns and Uncle Bob's Clean Architecture. Refactor the following messy, high-complexity code snippet into elegant, maintainable, SOLID-compliant code. ### LEGACY SOURCE CODE: ```[LANGUAGE] [PASTE_LEGACY_CODE_HERE] ``` ### PRIMARY CODE SMELLS OBSERVED: - [CODE_SMELLS_E_G_GOD_FUNCTION_DEEP_NESTING_MAGIC_NUMBERS_TIGHT_COUPLING] ### REFACTORING DELIVERABLES: 1. **Code Smell & Anti-Pattern Diagnosis**: - Bulleted breakdown identifying violations of Single Responsibility, Open/Closed, or Dependency Inversion principles. 2. **Step-by-Step Refactoring Strategy (Safe Transformation)**: - Sequence of small, testable refactoring moves (e.g. Extract Method, Replace Conditional with Polymorphism, Introduce Parameter Object). 3. **The Refactored, Production-Ready Code**: - Complete, elegant implementation in the same language. - Descriptive variable/function names that make comments redundant. - Maximum cyclomatic complexity under 5 (no nesting deeper than 2 levels). - Dependency injection for external services (database, APIs, loggers). 4. **Before-vs-After Comparison**: - Quantitative comparison of lines of code, cyclomatic complexity, testability, and cognitive load.
Customization & Placeholders
Paste your messy legacy function. The refactored version will use early returns, extracted pure functions, and dependency injection.
Example Input Values
Language: JavaScript/Node.js, Code: 200-line controller with 6 nested if-else callbacks, direct SQL queries, and inline email sending.
Expected Output Structure
Decomposed service layer with single-responsibility functions, dependency injection, and clean error handling.
Legacy System Modernization by Qubenix
We help enterprises eliminate tech debt, untangle legacy codebases, and migrate to modern cloud architectures safely.
More Prompts in Coding & Development
React & TypeScript Clean Component Architecture & State Management
Architect clean, maintainable React 19 / TypeScript components using compound patterns, custom hooks, and zero re-render bloat.
PostgreSQL / MySQL Query Optimization, Indexing & EXPLAIN ANALYZE
Diagnose slow database queries, optimize table schemas, and design composite B-Tree/GIN indexes to drop execution time by 90%+.
Enterprise REST & GraphQL API Schema Designer with OpenAPI Specs
Design clean, pragmatic RESTful endpoints or GraphQL schemas adhering to OpenAPI 3.1 standards, pagination, and status codes.