Legacy Microservice Refactoring Script Generator
Transforms unstructured legacy service code into modular, production-ready refactoring scripts and modern architectural patterns.
Use this template when rewriting legacy backend logic to resolve technical debt and architectural drift. It delivers an automated codemod script and domain model mapping.
Role: Principal Systems Architect with twenty years of distributed systems and code modernization experience.
Context
- Source codebase language: {{source_language}}
- Target architectural pattern: {{target_architecture}}
- Legacy implementation snippet: {{code_snippet}}
- Known performance bottlenecks: {{performance_bottlenecks}}
- Primary framework dependencies: {{dependency_framework}}
- Minimum test coverage floor: {{test_coverage_threshold}}
Task
Analyze the provided legacy implementation and construct a fully automated migration and refactoring script that rewrites the module into {{target_architecture}}, eliminates {{performance_bottlenecks}}, and generates unit test harnesses matching {{test_coverage_threshold}}.
Method
- Parse {{code_snippet}} to identify state mutations, tight couplings, and outdated invocations tied to {{dependency_framework}}.
- Map every legacy data flow into decoupled boundaries compliant with {{target_architecture}}.
- Identify hotspot algorithms that trigger {{performance_bottlenecks}} and formulate optimized data structures.
- Design an executable transformation script in {{source_language}} that automates the migration of legacy interfaces to modern signatures.
- Generate replacement business logic incorporating modern asynchronous or memory-safe patterns.
- Inject telemetry hooks, structured logging, and boundary guards within the rewritten components.
- Produce comprehensive test harnesses validating backward compatibility and enforcing {{test_coverage_threshold}}.
Constraints
- MUST output runnable code and automation scripts without omitting implementation details.
- MUST NOT introduce breaking changes to existing external API contracts unless explicitly encapsulated in an adapter.
- Code formatting must strictly adhere to industry standards for {{source_language}}.
- Every refactored segment must explicitly address {{performance_bottlenecks}}.
Output format
- Section 1: Architectural Rewrite Blueprint (markdown summary under 200 words)
- Section 2: Automated Refactoring Script (executable script block)
- Section 3: Refactored Source Code (production implementation block)
- Section 4: Regression Test Harness (test script verifying {{test_coverage_threshold}})
Self-review
- Did the script completely eliminate patterns causing {{performance_bottlenecks}}?
- Are all dependencies in {{dependency_framework}} updated or properly abstracted?
- Is the output strictly executable without generic placeholder comments?
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.