Refactoring & Modernization
Target: Claude 3.7, Cursor, Windsurf, ChatGPT

Monolith to Clean / Hexagonal Architecture Refactor

Refactor tangled MVC controllers and service layers into Clean Architecture (Ports & Adapters).

Clean ArchitectureHexagonalDDDRefactoringBackend

Interactive Prompt Playground

Customize Template Fields
Live replacement
{{TIGHT_CODE}}
{{TECH_STACK}}
Rendered Prompt (Ready to paste)1335 characters
You are a Principal Software Architect specializing in Clean Architecture and Ports & Adapters (Hexagonal Architecture).

Refactor this tightly coupled service layer into Clean Architecture:

Current Code (Tightly Coupled Service):
```
@Service
public class OrderService {
    @Autowired private EntityManager em;
    @Autowired private HttpServletRequest request;

    public void checkout(OrderDto dto) {
        // Direct SQL, HTTP header parsing, and business logic all mixed together:
        String token = request.getHeader("X-Auth-Token");
        em.createNativeQuery("INSERT INTO orders ...").executeUpdate();
        // Send email via raw SMTP socket...
    }
}
```

Target Tech Stack: Java 21 / Spring Boot

Perform an architectural decoupling refactor:
1. **Core Domain Model & Entities**:
   - Extract pure domain entities containing core business logic with zero framework annotations.
2. **Ports (Interfaces)**:
   - Inbound Ports (Use Cases / Input Boundaries).
   - Outbound Ports (Repository / Notification / Payment interfaces).
3. **Adapters (Infrastructure & Delivery)**:
   - Primary Adapters (REST Controllers / CLI).
   - Secondary Adapters (JPA Repository / Stripe API / SmtpClient).
4. **Refactored Code Structure**:
   - Provide the complete code organized by Domain, Application, and Infrastructure layers.

How to Use This Prompt

  1. Paste your tightly coupled service.
  2. Get a decoupled Clean Architecture structure with Use Cases, Ports, and Adapters.

Engineering Tips & Best Practices

  • Keep domain entities free of all Jackson/Lombok/JPA annotations to ensure true framework independence.

What This Prompt Inspects

Key failure modes, design principles, and quality standards evaluated during execution.

Dependency Inversion

Domain logic depends only on abstractions (Ports), never on databases or frameworks.

Pure Domain Entities

Domain entities have zero dependencies on ORM or web annotations.

Testability without Mocks

Allows testing 100% of business logic without spinning up Spring or DB.

SprintKit Workflow Integrations

Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.

Related Prompts

Explore related developer prompts in this workflow domain.

All Prompts

God Class & Long Method Decomposition with Design Patterns

Decompose monolithic 1,000+ line classes into Single Responsibility components using SOLID design patterns.

Design PatternsSOLIDOOPRefactoring+1
3 variablesCustomize prompt

Legacy Code Safe Refactoring with Characterization Tests

Safely modernize fragile legacy codebases using Martin Fowler refactoring patterns and golden master tests.

RefactoringClean CodeDesign PatternsLegacy Code
3 variablesCustomize prompt

Spring Boot REST Service & JPA Code Review

Deep code review for Spring Boot services examining transaction boundaries, JPA N+1 queries, concurrency, and validation.

JavaSpring BootJPAHibernate+2
4 variablesCustomize prompt