/devkit.java.refactor-class
Provides intelligent refactoring for complex Java classes with architectural analysis and Spring Boot patterns. Use when refactoring large or complex Java classes.
$ npx -y skills add giuseppe-trisciuoglio/developer-kit --agent claude-codeHow it fires
How this command gets triggered: by you, by Claude, or both.
- Fires itselfClaude auto-loads it when your prompt matches the work.
- You can call itInvoke it directly when you want it.
- Slash command
/devkit.java.refactor-class
Context preview
What this command does when you run it.
Provides intelligent refactoring for complex Java classes with architectural analysis and Spring Boot patterns. Use when refactoring large or complex Java classes.
Command definition
devkit.java.refactor-class.mdallowed-tools: Read, Write, Bash, Edit, Grep, Glob
argument-hint: "[class-file-path] [refactoring-scope] [options]"
description: Provides intelligent refactoring for complex Java classes with architectural analysis and Spring Boot patterns. Use when refactoring large or complex Java classes.
model: inherit
Java Class Refactoring Assistant
Overview
Intelligently refactor complex Java classes following Clean Architecture, DDD patterns, and Spring Boot best practices.
Provides intelligent refactoring for complex Java classes with architectural analysis and Spring Boot patterns. Use when refactoring large or complex Java classes.
Usage
/devkit.java.refactor-class $ARGUMENTS
Arguments
| Argument | Description | |--------------|------------------------------------------| | `$ARGUMENTS` | Combined arguments passed to the command |
Current Context
- **Current Git Branch**: !`git branch --show-current`
- **Git Status**: !`git status --porcelain`
- **Recent Commits**: !`git log --oneline -5`
- **Test Coverage**: !`find . -name "*Test.java" -type f | wc -l` test files found
Execution Instructions
**Agent Selection**: To execute this task, use the following agent with fallback:
- Primary: `developer-kit-java:java-refactor-expert`
- If not available: Use `developer-kit-java:java-refactor-expert` or fallback to `general-purpose` agent with
`spring-boot-crud-patterns` skill
Refactoring Configuration
Analyzing: **$ARGUMENTS**
**Parameters:**
- `$1` - Class file path (required): Path to Java class to refactor
- `$2` - Refactoring scope (optional):
- `cleanup` - Code cleanup and style improvements (default)
- `architecture` - Architectural pattern improvements
- `performance` - Performance optimizations
- `security` - Security enhancements
- `testing` - Testability improvements
- `comprehensive` - All improvements (full refactor)
- `$3` - Options (optional): `dry-run`, `backup`, `validate-only`
Pre-Refactoring Analysis
1. Class Identification and Context
IF "$1" is empty OR not provided THEN Analyze the most complex class in the codebase automatically ELSE Analyze specific class: $1 ENDIF
2. Architecture Pattern Detection
Expected Clean Architecture Structure:
feature/
├── domain/
│ ├── model/ # Domain entities (Spring-free)
│ ├── repository/ # Domain ports (interfaces)
│ └── service/ # Domain services
├── application/
│ ├── service/ # Use cases (@Service beans)
│ └── dto/ # Immutable DTOs/records
├── presentation/
│ └── rest/ # Controllers and mappers
└── infrastructure/
└── persistence/ # JPA adaptersRefactoring Strategy by Scope
Cleanup Refactoring ($2 = "cleanup")
- **Code Style**: Apply consistent formatting, naming conventions
- **Dead Code**: Remove unused imports, methods, variables
- **Complexity**: Simplify complex methods (< 10 cyclomatic complexity)
- **Documentation**: Add missing JavaDoc and inline comments
- **Immutability**: Convert to immutable structures where possible
Architecture Refactoring ($2 = "architecture")
- **Layer Separation**: Ensure proper dependency direction
- **DDD Patterns**: Apply aggregates, value objects, domain events
- **Spring Patterns**: Constructor injection, proper bean scoping
- **Repository Pattern**: Domain interfaces + infrastructure adapters
- **DTO Pattern**: Replace JPA entities with records in APIs
Performance Refactoring ($2 = "performance")
- **Database Queries**: Optimize JPA queries, eliminate N+1 problems
- **Caching**: Add @Cacheable, @CachePut, @CacheEvict where appropriate
- **Async Processing**: Convert blocking operations to @Async
- **Memory Management**: Identify and fix memory leaks
- **Algorithm Optimization**: Improve computational complexity
Security Refactoring ($2 = "security")
- **Input Validation**: Add Jakarta Bean Validation
- **Authentication**: Ensure proper @PreAuthorize usage
- **Data Exposure**: Prevent sensitive data leakage in DTOs
- **SQL Injection**: Verify safe JPA usage
- **XSS Prevention**: Input sanitization and output encoding
Testing Refactoring ($2 = "testing")
- **Testability**: Extract dependencies for better mocking
- **Test Coverage**: Add missing unit/integration tests
- **Test Structure**: Apply AAA pattern (Arrange, Act, Assert)
- **Mocking**: Proper Mockito usage without static mocks
- **Testcontainers**: Real database testing for persistence layer
Refactoring Process
Phase 1: Analysis and Planning
1. **Read and analyze target class** for current patterns and violations 2. **Identify dependencies** and usage patterns across codebase 3. **Assess test coverage** - if missing, create tests BEFORE refactoring 4. **Create refactoring plan** based on selected scope 5. **Backup strategy** - create branch if not `dry-run`
Phase 2: Safety Checks
# Run existing tests
./gradlew test || mvn test
# Create backup branch if not dry-run
if [ "$3" != "dry-run" ]; then
git checkout -b refactor/$(basename "$1" .java)-$(date +%Y%m%d-%H%M%S)
fi
Phase 3: Incremental Refactoring
For each refactoring step:
1. **Make small, focused change** 2. **Run tests** to verify no regressions 3. **Commit change** with descriptive message 4. **Document improvement** and rationale
Phase 4: Validation
# Full test suite
./gradlew test || mvn test
# Static analysis
./gradlew spotbugsMain || ./gradlew checkstyleMain
# Performance validation
./gradlew bench || echo "No performance tests configured"
Common Refactoring Patterns
Extract Method/Service
// Before: Complex method doing too much
@Service
@RequiredArgsConstructor
public class OrderService {
public OrderDto createOrder(CreateOrderRequest request) {
// Validation logic (20+ lines)
// Business logic (30+ lines)
// Notification logic (15+ lines)Read more
allowed-tools: Read, Write, Bash, Edit, Grep, Glob argument-hint: "[class-file-path] [refactoring-scope] [options]" description: Provides intelligent refactoring for complex Java classes with architectural analysis and Spring Boot patterns. Use when refactoring large or complex Java classes. model: inherit
Java Class Refactoring Assistant
Overview
Intelligently refactor complex Java classes following Clean Architecture, DDD patterns, and Spring Boot best practices.
Provides intelligent refactoring for complex Java classes with architectural analysis and Spring Boot patterns. Use when refactoring large or complex Java classes.
Usage
/devkit.java.refactor-class $ARGUMENTS
Arguments
| Argument | Description | |--------------|------------------------------------------| | `$ARGUMENTS` | Combined arguments passed to the command |
Current Context
- **Current Git Branch**: !`git branch --show-current`
- **Git Status**: !`git status --porcelain`
- **Recent Commits**: !`git log --oneline -5`
- **Test Coverage**: !`find . -name "*Test.java" -type f | wc -l` test files found
Execution Instructions
**Agent Selection**: To execute this task, use the following agent with fallback:
- Primary: `developer-kit-java:java-refactor-expert`
- If not available: Use `developer-kit-java:java-refactor-expert` or fallback to `general-purpose` agent with
`spring-boot-crud-patterns` skill
Refactoring Configuration
Analyzing: **$ARGUMENTS**
**Parameters:**
- `$1` - Class file path (required): Path to Java class to refactor
- `$2` - Refactoring scope (optional):
- `cleanup` - Code cleanup and style improvements (default)
- `architecture` - Architectural pattern improvements
- `performance` - Performance optimizations
- `security` - Security enhancements
- `testing` - Testability improvements
- `comprehensive` - All improvements (full refactor)
- `$3` - Options (optional): `dry-run`, `backup`, `validate-only`
Pre-Refactoring Analysis
1. Class Identification and Context
IF "$1" is empty OR not provided THEN Analyze the most complex class in the codebase automatically ELSE Analyze specific class: $1 ENDIF
2. Architecture Pattern Detection
Expected Clean Architecture Structure:
feature/
├── domain/
│ ├── model/ # Domain entities (Spring-free)
│ ├── repository/ # Domain ports (interfaces)
│ └── service/ # Domain services
├── application/
│ ├── service/ # Use cases (@Service beans)
│ └── dto/ # Immutable DTOs/records
├── presentation/
│ └── rest/ # Controllers and mappers
└── infrastructure/
└── persistence/ # JPA adaptersRefactoring Strategy by Scope
Cleanup Refactoring ($2 = "cleanup")
- **Code Style**: Apply consistent formatting, naming conventions
- **Dead Code**: Remove unused imports, methods, variables
- **Complexity**: Simplify complex methods (< 10 cyclomatic complexity)
- **Documentation**: Add missing JavaDoc and inline comments
- **Immutability**: Convert to immutable structures where possible
Architecture Refactoring ($2 = "architecture")
- **Layer Separation**: Ensure proper dependency direction
- **DDD Patterns**: Apply aggregates, value objects, domain events
- **Spring Patterns**: Constructor injection, proper bean scoping
- **Repository Pattern**: Domain interfaces + infrastructure adapters
- **DTO Pattern**: Replace JPA entities with records in APIs
Performance Refactoring ($2 = "performance")
- **Database Queries**: Optimize JPA queries, eliminate N+1 problems
- **Caching**: Add @Cacheable, @CachePut, @CacheEvict where appropriate
- **Async Processing**: Convert blocking operations to @Async
- **Memory Management**: Identify and fix memory leaks
- **Algorithm Optimization**: Improve computational complexity
Security Refactoring ($2 = "security")
- **Input Validation**: Add Jakarta Bean Validation
- **Authentication**: Ensure proper @PreAuthorize usage
- **Data Exposure**: Prevent sensitive data leakage in DTOs
- **SQL Injection**: Verify safe JPA usage
- **XSS Prevention**: Input sanitization and output encoding
Testing Refactoring ($2 = "testing")
- **Testability**: Extract dependencies for better mocking
- **Test Coverage**: Add missing unit/integration tests
- **Test Structure**: Apply AAA pattern (Arrange, Act, Assert)
- **Mocking**: Proper Mockito usage without static mocks
- **Testcontainers**: Real database testing for persistence layer
Refactoring Process
Phase 1: Analysis and Planning
1. **Read and analyze target class** for current patterns and violations 2. **Identify dependencies** and usage patterns across codebase 3. **Assess test coverage** - if missing, create tests BEFORE refactoring 4. **Create refactoring plan** based on selected scope 5. **Backup strategy** - create branch if not `dry-run`
Phase 2: Safety Checks
# Run existing tests ./gradlew test || mvn test # Create backup branch if not dry-run if [ "$3" != "dry-run" ]; then git checkout -b refactor/$(basename "$1" .java)-$(date +%Y%m%d-%H%M%S) fi
Phase 3: Incremental Refactoring
For each refactoring step:
1. **Make small, focused change** 2. **Run tests** to verify no regressions 3. **Commit change** with descriptive message 4. **Document improvement** and rationale
Phase 4: Validation
# Full test suite ./gradlew test || mvn test # Static analysis ./gradlew spotbugsMain || ./gradlew checkstyleMain # Performance validation ./gradlew bench || echo "No performance tests configured"
Common Refactoring Patterns
Extract Method/Service
// Before: Complex method doing too much
@Service
@RequiredArgsConstructor
public class OrderService {
public OrderDto createOrder(CreateOrderRequest request) {
// Validation logic (20+ lines)
// Business logic (30+ lines)
// Notification logic (15+ lines)Modular plugin marketplace for Claude Code and agentic CLIs, with validated, spec-driven skills, agents, commands, and workflows for Java, TypeScript, Python, PHP, AWS, and AI.
Repo: giuseppe-trisciuoglio/developer-kit
Other commands on developer-kit.
- /devkit.prompt-optimize
Provides expert prompt optimization using advanced techniques (CoT, few-shot, constitutional AI) for LLM performance enhancement. Use when you need to improve prompt quality or optimize LLM interactions.
Open command - /devkit.feature-development
Provides guided feature development capability with codebase understanding and architecture focus. Use when implementing a new feature from scratch.
Open command - /devkit.fix-debugging
Provides guided bug fixing and debugging capability with systematic root cause analysis. Use when encountering bugs, errors, or unexpected behavior.
Open command - /devkit.github.create-pr
Creates a GitHub pull request with branch creation, commits, and detailed description. Use when you need to submit changes for review.
Open command - /devkit.github.review-pr
Provides comprehensive GitHub pull request review with code quality, security, and best practices analysis. Use when reviewing a PR before merging.
Open command - /devkit.refactor
Provides guided code refactoring capability with deep codebase understanding, compatibility options, and comprehensive verification. Use when restructuring or improving existing code.
Open command

