home / skills / phodal / auto-dev / refactor

This skill analyzes code for smells and refactors methods to improve readability, performance, and maintainability while aligning with solid principles.

npx playbooks add skill phodal/auto-dev --skill refactor

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
702 B
---
name: refactor
description: Suggest refactoring improvements for code quality
---

# Code Refactoring

You are an expert software engineer specializing in code refactoring.

## Refactoring Request

$ARGUMENTS

## Refactoring Focus

1. **Code Smells**: Long methods, large classes, duplicate code
2. **Design**: SOLID principles, design patterns
3. **Performance**: Algorithm efficiency, resource management
4. **Maintainability**: Readability, testability, modularity

## Output Format

### Before (Current Code)
Show current implementation with issues

### After (Refactored Code)
Show improved implementation

### Improvements Made
List all improvements with explanations

Project: $PROJECT_NAME

Overview

This skill suggests refactoring improvements to raise code quality, readability, and maintainability for Kotlin projects. It targets code smells, design issues, performance bottlenecks, and testability gaps, delivering concrete Before/After examples. Use it to get actionable, pattern-driven refactoring suggestions that are easy to review and apply.

How this skill works

Provide the code or describe the problematic module and the project context; the skill inspects method length, duplication, class responsibilities, algorithmic complexity, and adherence to SOLID principles. It returns a Before (current code), an After (refactored code) and a clear list of Improvements Made with explanations and rationale. Recommendations prioritize minimal, testable changes and point out where design patterns or API-level changes are appropriate.

When to use it

  • When methods or classes have grown too large or complex
  • When multiple places duplicate the same logic
  • When code violates SOLID principles or lacks clear responsibilities
  • When performance hotspots or inefficient algorithms are suspected
  • When unit testing is hard due to tight coupling or poor modularity

Best practices

  • Start with automated tests or add characterization tests before large refactors
  • Refactor in small steps and commit frequently to keep changes reviewable
  • Prefer explicit interfaces and dependency injection for testability
  • Replace duplication with well-named abstractions or utility functions
  • Document behavioral changes and preserve external contracts unless intentionally breaking

Example use cases

  • Extract long Kotlin functions into smaller private functions and domain services
  • Replace duplicated parsing logic across modules with a single parser component
  • Introduce strategy or factory patterns to simplify conditional chains
  • Refactor synchronous blocking I/O to coroutine-based suspend functions for better throughput
  • Split large monolithic classes into focused classes following single responsibility

FAQ

What inputs does the skill need?

Provide the source code snippet and a short description of the intended behavior and constraints; include project context like threading model or performance targets if relevant.

Will the skill change public APIs?

By default it suggests refactors that preserve public contracts; if breaking changes are recommended it will call them out and explain migration steps.

Does it generate runnable code?

It produces ready-to-review Kotlin code samples, but you should run tests and integrate changes in a controlled branch before merging.