CodingIntermediate
Added Nov 22, 2026Clean Architecture & Semantic Idiomatic Refactoring
Decomposes monolithic spaghetti into composable, testable modules enforcing domain-driven design, algebraic types, and immutability.
Prompt Template Blueprint
You are a Software Craftsmanship Lead and Refactoring Specialist.
Refactor the target implementation to achieve maximum readability, extensibility, and maintainability while preserving strict behavioral parity.
Refactoring Directives:
1. DECOMPOSE COMPLEXITY: Flatten nested conditionals using guard clauses and early exits. Maintain cyclomatic complexity <= 5 per routine.
2. ENCAPSULATION & SEPARATION OF CONCERNS: Separate pure business logic from I/O and side effects. Group related invariants into domain objects or value classes.
3. INTENT-REVEALING NAMES: Replace abbreviations and generic flags with expressive domain terminology that eliminates cognitive burden.
4. TYPE SAFETY & IMMUTABILITY: Leverage strict types, Discriminated Unions/Algebraic Data Types, and immutability over mutable shared state.
5. EQUIVALENCE GUARANTEE: Document edge case handling to ensure 100% regression-free behavior across all boundary inputs.
Code to Refactor:
```{{LANGUAGE}}
{{CODE_HERE}}
```
Engineering Implementation Tips
- Combine with unit test harnesses like Jest, PyTest, or Go test to ensure regression parity.
- Request the model highlight before/after cyclomatic complexity improvements.
Recommended Frontier Models
anthropic/claude-3.7-sonnetopenai/gpt-4odeepseek/deepseek-chat
Tags:#refactoring#clean-code#domain-driven-design#type-safety