refactor
Guides the surgical refactoring of monolithic classes into modular, enterprise-grade service components.
Install
mkdir -p .claude/skills/refactor-jgreen021 && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/19289" && unzip -o skill.zip -d .claude/skills/refactor-jgreen021 && rm skill.zipInstalls to .claude/skills/refactor-jgreen021
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
This standard governs the modernization of legacy code and the surgical decomposition of high-complexity monolithic structures.Key capabilities
- →Decompose monolithic services into triad layers
- →Convert mutable POJOs to Java Records
- →Enforce package-private visibility for controllers
- →Validate logic preservation via Gradle
How it works
The skill applies a Clean Chain strategy to separate concerns by splitting monolithic classes into controllers, service interfaces, and repositories while enforcing immutability with Java Records.
Inputs & outputs
When to use refactor
- →Decompose a monolithic service
- →Refactor legacy classes to Java Records
- →Apply single responsibility principle
- →Clean up service visibility
About this skill
Skill: Architectural Refactor & Decomposition
This standard governs the modernization of legacy code and the surgical decomposition of high-complexity monolithic structures.
1. The "Clean Chain" Strategy
When refactoring, the intent is never "lean" or "minimum viable." We refactor to achieve Strict Concern Separation following the chain:
Controller (Package-Private) -> Service (Interface) -> [Client | Repository].
Core Standards
- Single Responsibility (SRP): Any service handling Business Logic AND Data Access MUST be split.
- Immutability Mandate: All legacy POJOs or mutable DTOs must be decomposed into Java Records.
- Visibility Discipline: Move all controllers to package-private visibility during the refactoring process.
2. Golden Sample: Monolithic Service Decomposition
This reference demonstrates the surgical transformation of a "Multifaceted Legacy Class" into an enterprise-grade service triad.
🚫 The "Monolithic" Legacy (300+ Lines)
// Legacy: Handles Validation, DB and API Calls in one file
public class LegacyMonitorService {
@Autowired private Repos repo;
public void process(Data d) {
if (d.getVal() == null) { throw new Err(); } // Inline validation
repo.save(d); // Direct persistence
// 50 more lines of logic...
}
}
✅ The Enterprise "Masterpiece" (Decomposed)
Step 1: The Immutable Schema (Record)
public record ReadingRequest(
@NotNull Instant timestamp,
@Positive Double magnitude
) {}
Step 2: The Focused Domain Service
@Service
final class AnomalyService implements MonitorUseCase {
private final TelemetryRepository repository;
AnomalyService(TelemetryRepository repository) {
this.repository = repository;
}
@Override
public void process(ReadingRequest request) {
// Pure domain logic; Persistence delegated to repository
repository.saveReading(request);
}
}
3. Refactoring Workflow (Gradle)
To ensure that refactoring does not introduce regressions, the agent must follow this Gradle-centric loop:
- Audit: Read the target file and identify SRP violations.
- Decompose: Create the new Records and Services in their respective domain packages.
- Validate: Run the static analysis suite.
./gradlew checkstyleMain # Enforce style boundaries ./gradlew test # Verify logic preservation - Polish: Perform a final Code Review to ensure no "legacy drift" remains.
4. Resource Resolution
- Java Conventions: Consult Java Standard for records/functional logic.
- Build Logic: Consult Build System for Gradle task definitions.
- Quality Gate: Consult QA Standard for Checkstyle thresholds.
When not to use it
- →Refactoring for lean or minimum viable intent
- →Services where business logic and data access are already separated
Prerequisites
Limitations
- →Service handling business logic and data access must be split
How it compares
It mandates surgical decomposition into a specific service triad rather than generic code cleanup.
Compared to similar skills
refactor side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| refactor (this skill) | 0 | 3mo | No flags | Advanced |
| spring-boot-config-refactor | 0 | 4mo | No flags | Advanced |
| java-pro | 34 | 3mo | No flags | Advanced |
| backend-microservice-development | 2 | 2mo | No flags | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by jgreen021
View all by jgreen021 →You might also like
spring-boot-config-refactor
sklintyg
Refactor a Spring Boot application's configuration from legacy application.properties and scattered @Value usage to structured YAML and immutable @ConfigurationProperties records. Use this when migrating messy configuration, standardizing property naming, introducing app-prefixed custom properties,
java-pro
sickn33
Master Java 21+ with modern features like virtual threads, pattern matching, and Spring Boot 3.x. Expert in the latest Java ecosystem including GraalVM, Project Loom, and cloud-native patterns. Use PROACTIVELY for Java development, microservices architecture, or performance optimization.
backend-microservice-development
TencentBlueKing
后端微服务开发规范,涵盖目录结构、分层架构(API/Service/DAO)、依赖注入、配置管理、Spring Boot 最佳实践。当用户进行后端开发、创建新微服务、编写 Kotlin/Java 代码或设计服务架构时使用。
microservice-infrastructure
TencentBlueKing
微服务基础设施指南,涵盖条件配置、事件驱动架构、服务间通信、国际化与日志等微服务架构的核心基础设施。当用户实现服务间调用、配置多环境、实现异步通信、处理国际化或规范日志输出时使用。
common-technical-practices
TencentBlueKing
通用技术实践指南,涵盖 AOP 切面、分布式锁、重试机制、参数校验、性能监控、定时任务、审计日志等后端开发中的常见技术实践。当用户需要实现横切关注点、处理并发控制、配置重试策略、添加性能监控或实现审计功能时使用。
jakarta-namespace
benchflow-ai
Migrate Java EE javax.* imports to Jakarta EE jakarta.* namespace. Use when upgrading to Spring Boot 3.x, migrating javax.persistence, javax.validation, javax.servlet imports, or fixing compilation errors after Jakarta EE transition. Covers package mappings, batch sed commands, and verification steps.