home / skills / shotaiuchi / dotclaude / refactor-pattern

refactor-pattern skill

/dotclaude/skills/refactor-pattern

This skill analyzes current design patterns and anti-patterns, recommends target patterns, and guides pattern migration to align with codebase conventions.

npx playbooks add skill shotaiuchi/dotclaude --skill refactor-pattern

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

Files (1)
SKILL.md
2.1 KB
---
name: refactor-pattern
description: >-
  Design pattern analysis for refactoring. Apply when identifying current
  patterns, anti-patterns, recommending target patterns, and evaluating
  pattern fit with codebase conventions.
user-invocable: false
---

# Pattern Analyst Analysis

Identify current design patterns and anti-patterns, and recommend target patterns for the refactoring.

## Analysis Checklist

### Current Pattern Identification
- Classify design patterns in use (creational, structural, behavioral)
- Map how patterns interact across module boundaries
- Identify implicit patterns not formally documented
- Check pattern consistency across similar components

### Anti-Pattern Detection
- Detect god classes or functions with too many responsibilities
- Find feature envy (methods using other class data excessively)
- Identify shotgun surgery (changes requiring edits in many places)
- Look for primitive obsession and data clumps

### Target Pattern Selection
- Recommend patterns that match the refactoring goal
- Evaluate pattern fit with existing codebase conventions
- Consider team familiarity and learning curve
- Assess pattern complexity vs benefit tradeoff

### Pattern Migration Path
- Define steps to transform current pattern to target pattern
- Identify intermediate states that remain functional
- Check for pattern conflicts during transition
- Verify the target pattern supports future extensibility

### Codebase Convention Alignment
- Check consistency with patterns used elsewhere in the project
- Verify naming conventions match the target pattern idioms
- Ensure error handling style aligns with project standards
- Validate that the target pattern fits the project's testing approach

## Output Format

Report findings with impact ratings:

| Impact | Description |
|--------|-------------|
| Breaking | Anti-pattern causing active defects or blocking changes |
| High | Pattern mismatch creating significant maintenance burden |
| Medium | Suboptimal pattern that should improve with migration |
| Low | Minor pattern inconsistency, cosmetic improvement |

Overview

This skill analyzes existing code to identify design patterns, anti-patterns, and recommended target patterns for refactoring. It produces a prioritized, impact-rated report and a practical migration path aligned with codebase conventions and team constraints. The goal is to reduce maintenance cost and enable safer, incremental refactors.

How this skill works

The skill scans modules to classify creational, structural, and behavioral patterns and maps their interactions across boundaries. It detects anti-patterns like god classes, feature envy, shotgun surgery, primitive obsession, and data clumps. For each finding it assigns an impact rating and recommends target patterns, evaluates fit with conventions, and outlines stepwise migration paths and intermediate safe states.

When to use it

  • Before large refactors to choose safe, compatible patterns
  • When maintenance is slowing due to tangled responsibilities
  • To resolve recurring bugs caused by pattern misuse or conflicts
  • When onboarding new architecture or enforcing consistency
  • During code reviews for architectural debt prioritization

Best practices

  • Prioritize fixes by impact (Breaking > High > Medium > Low)
  • Prefer incremental migrations with working intermediate states
  • Align target patterns with existing naming, error handling, and tests
  • Choose patterns familiar to the team unless long-term benefit justifies learning cost
  • Document pattern intent and anti-patterns in code comments and design notes

Example use cases

  • Identify a god class and recommend decomposition into strategy and factory patterns with a migration plan
  • Detect feature envy and suggest moving behavior plus introducing facade or adapter layers
  • Find shotgun surgery hotspots and propose event-driven or observer pattern refactors
  • Resolve primitive obsession by introducing value objects and consistent validation rules
  • Evaluate whether applying repository or service patterns fits existing persistence conventions

FAQ

How are impact ratings determined?

Ratings reflect urgency and scope: Breaking indicates active defects or blockers; High signals major maintenance burden; Medium suggests meaningful improvement; Low is cosmetic or stylistic.

Will the migration plan break the build?

No. Plans emphasize incremental, backward-compatible steps and highlight intermediate states that remain functional while changes roll out.