Engineering
refactoring-patterns avatar

refactoring-patterns

Safely refactor code to improve structure and maintainability while preserving behavior through TDD cycles and automated test verification.

Introduction

The Refactoring Patterns skill provides a structured framework for improving existing software by addressing code smells without altering system behavior. Designed for software engineers, quality engineers, and maintainers, this skill ensures that technical debt reduction is methodical, safe, and verifiable. It centers on the principle that refactoring must always be supported by a robust test suite, advocating for a 'Red-Green-Refactor' workflow that minimizes risks during code evolution.

By leveraging this skill, users can transform complex or degraded code into clean, modular, and efficient implementations. It provides guidance on identifying common code smells—such as long methods, large classes, and nested conditionals—and maps them to proven refactoring techniques like Extract Method, Extract Class, Introduce Parameter Object, and Replacing Loops with Pipelines. This approach prioritizes small, incremental changes that are committed frequently, ensuring that every transformation maintains test integrity.

  • Automated identification and resolution of code smells: Long Method, Large Class, Magic Numbers, and Duplicated Code.

  • Enforcement of the 'Rule of Three' to prevent premature abstraction and unnecessary code complexity.

  • Integration with QE agents (qe-code-reviewer, qe-quality-analyzer, qe-test-refactorer) to validate code changes against existing test suites.

  • Safety-first lifecycle management: ENSURE tests pass, make small changes, run tests, commit progress, repeat.

  • Best practice documentation for common patterns: Extract Method, Replace Conditional with Polymorphism, and Pipeline refactoring.

  • Anti-pattern prevention: Eliminates the risks associated with 'big bang' rewrites, refactoring without tests, and perfectionist over-engineering.

  • This skill should be used when cleaning up legacy systems, reducing technical debt, or improving code maintainability during feature development.

  • It is strictly prohibited to use this skill on code without tests; users must write tests first if coverage is insufficient.

  • Ideal for use with tools like Jest, Vitest, Playwright, or standard CI/CD test runners to ensure high-confidence refactoring.

  • Typical outputs include cleaner codebase structure, reduced cyclomatic complexity, improved readability, and a higher confidence level for future feature development.

  • Users should monitor the refactoring history through the defined memory namespace (aqe/refactoring/) to track patterns and suggestions.

Repository Stats

Stars
329
Forks
65
Open Issues
4
Language
TypeScript
Default Branch
main
Sync Status
Idle
Last Synced
Apr 29, 2026, 07:07 AM
View on GitHub