Code Refactoring Guide
Guides AI to analyze and refactor code using clean code principles, returning improved code with detailed explanations of each change.
When to use this prompt
Use this when you have working code that needs improvement in readability, maintainability, or structure. It's designed for code that functions correctly but could benefit from applying software design principles like SRP and DRY.
You are a software architect who specializes in code refactoring and clean code principles. Refactor this code to improve maintainability: [CODE] Focus on: 1. Single Responsibility Principle 2. DRY (Don't Repeat Yourself) 3. Clear naming conventions 4. Proper abstraction levels 5. Error handling 6. Performance (where relevant) Provide: 1. Analysis of current issues 2. Refactored code with comments 3. Explanation of each change and why it improves the code 4. Before/after comparison 5. Potential further improvements 6. Any breaking changes to note Keep the refactoring pragmatic - improve clarity without over-engineering.
Free to use — the optimizer tailors this template to your exact task and target AI.
How to customize it
- [CODE] - Paste the code block you want refactored, in any programming language
- Focus areas (items 1-6) - Keep all six principles listed, or remove specific ones if you want the AI to concentrate on particular aspects like error handling or naming only
- Provide section - Adjust the six deliverables if you need fewer outputs, such as removing the before/after comparison if you only want the refactored code and explanations
What you'll get back
The AI returns a structured analysis starting with identified code issues, followed by the refactored code with inline comments, detailed explanations for each modification, a before/after comparison, suggestions for additional improvements, and notes on any changes that might break existing functionality.
Related prompts
Code Interview Question Designer
Generates structured coding interview questions with solutions, evaluation criteria, hints, and candidate assessment flags for technical hiring.
Plan a Safe Software Architecture Migration
Generates a structured migration plan covering risk assessment, phased strategy, testing, and rollback procedures for moving between software architectures.
Tech Lead's Guide to Code Migration Projects
Generates a structured migration plan covering assessment, strategy, phases, technical approach, risks, and timeline for moving codebases between technologies.
Code Reviewer
Instructs AI to perform a comprehensive code review covering bugs, security, performance, style, and best practices with severity ratings and corrections.
Database Query Optimizer
Analyzes slow database queries and returns optimized versions with index recommendations, execution plan analysis, and performance tradeoffs.
Design Production-Ready Database Schemas with Migrations
Generates complete database schemas with tables, relationships, indexes, migration scripts, and performance optimizations tailored to your application's data patterns.
Make this prompt yours
PromptWizz rewrites this template around your specific task, audience, and target AI — and shows you why each change works.
Try the Optimizer Free