code-refactoring
Code Refactoring
Overview
This skill guides systematic code refactoring to improve code quality, maintainability, and design while preserving functionality. Follow the safe refactoring workflow with comprehensive test coverage and incremental changes.
Refactoring Workflow
Step 1: Analyze Code and Identify Issues
Examine the codebase to identify code smells and quality issues:
- Long methods (>20-30 lines) or large classes (>300-500 lines)
- Duplicated code blocks or similar logic in multiple places
- Unclear or misleading names for variables, methods, or classes
- Complex conditional logic or deeply nested structures
- Poor separation of concerns or tight coupling between components
For detailed code smell catalog: See code-smells.md
Step 2: Verify Test Coverage
Before refactoring ANY code:
- Check existing test coverage for the code to be refactored
- If tests are missing or inadequate, write tests FIRST
- Run all tests to establish baseline (all should pass)
- Never proceed without adequate test coverage
For test coverage strategies: See testing-strategies.md
Step 3: Choose Refactoring Technique
Select the appropriate refactoring pattern based on the issue:
- Extract Method/Function: Break down long methods into smaller, focused ones
- Extract Class: Split large classes with multiple responsibilities
- Rename: Improve clarity with better names
- Move Method/Field: Relocate functionality to more appropriate classes
- Replace Conditional with Polymorphism: Simplify complex conditionals
- Introduce Parameter Object: Group related parameters
- Inline Method/Variable: Remove unnecessary indirection
For complete pattern catalog: See refactoring-patterns.md
Step 4: Apply Refactoring Incrementally
Make ONE small change at a time:
- Apply a single refactoring technique
- Run all tests immediately after the change
- If tests pass, commit the change
- If tests fail, revert and try a different approach
- Repeat for each refactoring needed
Critical Rules:
- Never change behavior while refactoring
- Never refactor and add features simultaneously
- Use IDE automated refactoring tools when available
- Keep each refactoring commit small and focused
For detailed process guidance: See refactoring-process.md
Step 5: Verify and Document
After completing refactorings:
- Run full test suite to ensure all tests pass
- Check that code quality metrics improved
- Review code to confirm readability enhanced
- Document significant architectural changes if needed
- Create clear commit messages describing refactorings
Common Refactoring Scenarios
Scenario-specific guidance is available for:
- Legacy code modernization
- Preparing code for new features
- Performance optimization through refactoring
- Reducing technical debt systematically
- Extracting reusable components
See common-refactoring-scenarios.md for detailed examples and approaches.
Best Practices and Quality Guidelines
Follow established principles for high-quality refactoring:
- Apply SOLID principles (Single Responsibility, Open/Closed, etc.)
- Reduce coupling between components
- Increase cohesion within components
- Eliminate duplication (DRY principle)
- Maintain consistent coding standards
For comprehensive best practices: See refactoring-best-practices.md
Tools and Automation
Modern IDEs and tools can automate many refactorings safely:
- IDE refactoring features (IntelliJ, VS Code, Visual Studio)
- Static analysis tools for code smell detection
- Test coverage tools
- Automated code formatting and linting
For tool recommendations and usage: See tools-and-automation.md
Output Format
When presenting refactoring recommendations:
- Identify the code smell or quality issue
- Explain why it's problematic
- Propose specific refactoring approach
- Show before/after code examples
- List tests to verify behavior preservation
For detailed output templates: See output-format.md
More from dauquangthanh/hanoi-rainbow
frontend-design-review
Conducts comprehensive frontend design reviews covering UI/UX design quality, design system validation, accessibility compliance, responsive design patterns, component library architecture, and visual design consistency. Evaluates design specifications, Figma/Sketch files, design tokens, interaction patterns, and user experience flows. Identifies usability issues, accessibility violations, design system deviations, and provides actionable recommendations for improvement. Produces detailed design review reports with severity-rated findings, visual examples, and implementation guidelines. Use when reviewing frontend designs, validating design systems, ensuring accessibility compliance, evaluating component libraries, assessing responsive designs, or when users mention design review, UI/UX review, Figma review, design system validation, accessibility audit, or frontend design quality.
276keycloak-administration
Provides comprehensive KeyCloak administration guidance including realm management, user/group administration, client configuration, authentication flows, identity brokering, authorization policies, security hardening, and troubleshooting. Covers SSO configuration, SAML/OIDC setup, role-based access control (RBAC), user federation (LDAP/AD), social login integration, multi-factor authentication (MFA), and high availability deployments. Use when configuring KeyCloak, setting up SSO, managing realms and clients, troubleshooting authentication issues, implementing RBAC, or when users mention "KeyCloak", "SSO", "OIDC", "SAML", "identity provider", "IAM", "authentication flow", "user federation", "realm configuration", or "access management".
165frontend-ui-ux-design
Creates comprehensive frontend UI/UX designs including user interfaces, design systems, component libraries, responsive layouts, and accessibility implementations. Produces wireframes, mockups, design specifications, and implementation guidelines. Use when designing user interfaces, creating design systems, building component libraries, implementing responsive designs, ensuring accessibility compliance, or when users mention UI design, UX design, interface design, design systems, user experience, or frontend design patterns.
165oracle-cloud
Provides comprehensive Oracle Cloud Infrastructure (OCI) guidance including compute instances, networking (VCN, load balancers, VPN), storage (block, object, file), database services (Autonomous Database, MySQL, NoSQL), container orchestration (OKE), identity and access management (IAM), resource management, cost optimization, and infrastructure as code (Terraform OCI provider, Resource Manager). Produces infrastructure code, deployment scripts, configuration guides, and architectural diagrams. Use when designing OCI architecture, provisioning cloud resources, migrating to Oracle Cloud, implementing OCI security, setting up OCI databases, deploying containerized applications on OKE, managing OCI resources, or when users mention "Oracle Cloud", "OCI", "Autonomous Database", "VCN", "OKE", "OCI Terraform", "Resource Manager", "Oracle Cloud Infrastructure", or "OCI migration".
82backend-design
Designs comprehensive backend systems including RESTful APIs, microservices, database architecture, authentication/authorization, caching strategies, message queues, and scalability patterns. Produces API specifications, database schemas, architecture diagrams, and implementation guides. Use when designing backend services, APIs, data models, distributed systems, authentication flows, or when users mention backend architecture, API design, database design, microservices, or server-side development.
55requirement-review
Conducts comprehensive requirements review including completeness validation, clarity assessment, consistency checking, testability evaluation, and standards compliance. Produces detailed review reports with findings, gaps, conflicts, and improvement recommendations. Use when reviewing requirements documents (BRD, SRS, user stories), validating acceptance criteria, assessing requirements quality, identifying gaps and conflicts, or ensuring standards compliance (IEEE 830, INVEST criteria). Trigger when users mention "review requirements", "validate requirements", "check requirements quality", "find requirement issues", or "assess BRD/SRS quality".
52