Installs: 0
Used in: 1 repos
Updated: 2d ago
$
npx ai-builder add command epastorc/refactorInstalls to .claude/commands/refactor.md
# DDD Refactoring Guide ## Refactoring Strategy ### 1. Domain Layer Refactoring - Extract business rules from services into domain entities - Create value objects for complex data types - Implement domain services for business logic that doesn't belong to entities - Define clear aggregate boundaries ### 2. Application Layer Refactoring - Move orchestration logic to use cases - Remove business logic from controllers/components - Implement command/query separation - Add proper transaction boundaries ### 3. Infrastructure Layer Refactoring - Abstract external dependencies behind interfaces - Implement repository pattern for data access - Create adapters for third-party services - Handle configuration and environment concerns ### 4. Presentation Layer Refactoring - Remove business logic from components - Implement proper state management - Use DTOs for data transfer - Handle user interaction concerns only ## Refactoring Steps 1. **Identify Violations**: Find code that violates DDD principles 2. **Extract Domain Logic**: Move business rules to domain layer 3. **Create Abstractions**: Define interfaces for external dependencies 4. **Implement Use Cases**: Create application services for workflows 5. **Update Components**: Clean up presentation layer 6. **Add Tests**: Ensure refactored code is well-tested ## Common Refactoring Patterns - **Extract Domain Service**: Move business logic from application services - **Create Value Objects**: Replace primitive types with meaningful objects - **Implement Repository**: Abstract data access behind interfaces - **Use Dependency Injection**: Inject dependencies rather than creating them - **Separate Commands from Queries**: Implement CQRS pattern ## Validation After Refactoring - All tests still pass - No new circular dependencies - Clear separation of concerns - Improved testability - Better maintainability Refactor incrementally and validate each step to ensure code quality is maintained.
Quick Install
$
npx ai-builder add command epastorc/refactorDetails
- Type
- command
- Author
- epastorc
- Slug
- epastorc/refactor
- Created
- 6d ago