Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
dauquangthanh avatar

Code Refactoring

  • 27 installs
  • 14 repo stars
  • Updated January 23, 2026
  • dauquangthanh/hanoi-rainbow

Code Refactoring is an agent skill that identifies code smells and applies incremental refactoring patterns so developers can improve design without breaking behavior.

About

Code Refactoring is a Hanoi Rainbow skill that enforces a safe, test-first refactoring loop with named patterns for smells like long methods and duplicated logic. Use it when cleaning up legacy modules, reducing complexity before new features, or responding to quality-review findings. It preserves functionality through incremental steps rather than sweeping rewrites without coverage.

  • Safe workflow: tests before each change
  • Catalog of extract, move, and rename patterns
  • Code smell identification checklist
  • Incremental commit-friendly steps

Code Refactoring by the numbers

  • 27 all-time installs (skills.sh)
  • Ranked #684 of 1,352 Code Review & Quality skills by installs in the Skillselion catalog
  • Data as of Jul 29, 2026 (Skillselion catalog sync)
npx skills add https://github.com/dauquangthanh/hanoi-rainbow --skill code-refactoring

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs27
repo stars14
Last updatedJanuary 23, 2026
Repositorydauquangthanh/hanoi-rainbow

How do you improve messy or debt-laden code safely without introducing regressions?

Guides safe, test-backed refactoring with smell identification and incremental pattern application.

Who is it for?

Developers with existing or newly added tests who need guided, incremental refactors on backend or shared logic.

Skip if: Greenfield projects with no code to refactor, or teams unwilling to add tests before structural changes.

When should I use this skill?

You are addressing code smells, technical debt, or pre-feature cleanup and need a step-by-step refactoring workflow.

What you get

Cleaner structure through applied patterns, with tests run after each incremental change and documented technique choices.

Files

SKILL.mdMarkdownGitHub ↗

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:

1. Check existing test coverage for the code to be refactored 2. If tests are missing or inadequate, write tests FIRST 3. Run all tests to establish baseline (all should pass) 4. 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:

1. Apply a single refactoring technique 2. Run all tests immediately after the change 3. If tests pass, commit the change 4. If tests fail, revert and try a different approach 5. 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:

1. Run full test suite to ensure all tests pass 2. Check that code quality metrics improved 3. Review code to confirm readability enhanced 4. Document significant architectural changes if needed 5. 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:

1. Identify the code smell or quality issue 2. Explain why it's problematic 3. Propose specific refactoring approach 4. Show before/after code examples 5. List tests to verify behavior preservation

For detailed output templates: See output-format.md

Related skills

FAQ

Must tests exist before refactoring?

The skill requires adequate coverage first and instructs writing tests if they are missing.

Can I apply multiple patterns at once?

It recommends one small change per iteration with tests run immediately after each step.

Does it cover framework-specific UI refactors?

Patterns are general; pair with frontend-coding or frontend-code-review for UI-heavy refactors.

Code Review & Qualitybackendtesting

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.