From refactor-pilot
Use this skill whenever the user wants to identify, apply, or refactor toward design patterns in their codebase. Triggers include: "apply design patterns", "identify patterns", "what patterns should I use", "refactor to strategy pattern", "apply factory method", "use observer pattern", "code smells that need patterns", "which design pattern fits", "improve architecture with patterns", "decouple this code", "make this extensible", "reduce coupling", "apply SOLID principles", or any mention of a specific GoF pattern name (Factory, Singleton, Observer, Strategy, etc.). Also triggers when the user mentions "Refactoring Guru", "Gang of Four", or "GoF patterns". Works standalone or as a companion to the refactor-code skill during Phase 3 (Transform). Do NOT use for general code analysis — use analyze-codebase for that.
How this skill is triggered — by the user, by Claude, or both
Slash command
/refactor-pilot:design-patternsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
You are applying design patterns from the Refactoring Guru / Gang of Four catalog to help
You are applying design patterns from the Refactoring Guru / Gang of Four catalog to help the user improve their codebase's architecture. This skill works standalone or as part of Phase 3 (Transform) of the Refactor Pilot Framework.
What does the user need?
├── IDENTIFY which patterns to apply
│ └── Go to "Pattern Identification Workflow"
├── APPLY a specific pattern they already chose
│ └── Go to "Pattern Application Workflow"
├── LEARN about a pattern before deciding
│ └── Go to "Pattern Reference" (see references/)
└── REFACTOR existing code toward a pattern
└── Go to "Pattern Refactoring Workflow"
Does a codebase analysis exist (refactor-notes/04-project-summary.md)?
├── YES → Use it to inform pattern recommendations
└── NO → Analyze the target code area before recommending patterns
Are safety net tests in place?
├── YES → Proceed with transformation
└── NO → Recommend running generate-tests first
When the user wants to know which patterns fit their code:
Scan the target code for these smell → pattern mappings:
| Code Smell | Suggested Pattern(s) |
|---|---|
Giant if/else or switch on type | Strategy, State, Command |
| Copy-pasted logic with minor variations | Template Method, Strategy |
| Constructor with 5+ parameters | Builder |
new keyword scattered everywhere | Factory Method, Abstract Factory |
| God class doing too many things | Facade, Mediator, Command |
| Tight coupling between modules | Observer, Mediator, Bridge |
| Adding features requires modifying existing code | Decorator, Strategy, Visitor |
| Complex object creation logic | Builder, Factory Method, Prototype |
| Need to support undo/history | Memento, Command |
| Traversing complex structures | Iterator, Composite, Visitor |
| Different behavior for different states | State |
| Adapting incompatible interfaces | Adapter, Facade |
| Controlling access to expensive resources | Proxy, Flyweight |
| Many similar objects consuming memory | Flyweight, Prototype |
For each candidate pattern, assess:
skills/refactor-code/references/deep-modules.md for the Depth Test.Rule of thumb: If the pattern adds more classes/files than the problem warrants, it's over-engineering. Patterns should reduce complexity, not add it. In AI-maintained codebases the cost is concrete: every extra layer is another file in the context window, more tokens, and another hop where an agent can lose the thread.
Present recommendations as:
## Pattern Recommendation: [Pattern Name]
**Problem:** [What code smell or structural issue this solves]
**Current code:** [Brief description of what exists now]
**After applying:** [What the code will look like]
**Trade-offs:** [What you gain vs. what complexity you add]
**Confidence:** HIGH / MEDIUM / LOW
**Files affected:** [List of files that would change]
When the user wants to apply a specific pattern:
references/ docs)Follow the three-pass approach from the refactor-code skill:
// PATTERN: [PatternName] comments at key structural points for documentationAfter applying, document:
When refactoring existing code toward a pattern:
Identify which existing classes/functions/modules map to each role in the target pattern. For example, for Strategy:
if/elseTransform in small, testable steps:
Critical: Never change more than one pattern role at a time. Each step should be independently committable and testable.
| Pattern | When to Use | Key Benefit |
|---|---|---|
| Factory Method | Subclasses decide which class to instantiate | Open/Closed principle for creation |
| Abstract Factory | Families of related objects | Consistent object families |
| Builder | Complex objects with many optional parts | Readable construction, immutable objects |
| Prototype | Copying existing objects is cheaper than creating new ones | Avoids complex initialization |
| Singleton | Exactly one instance needed globally | Controlled global access |
See references/creational-patterns.md for detailed guides with code examples.
| Pattern | When to Use | Key Benefit |
|---|---|---|
| Adapter | Incompatible interfaces need to work together | Integration without modifying source |
| Bridge | Separate abstraction from implementation | Independent evolution of both |
| Composite | Tree structures with uniform treatment | Simplifies client code |
| Decorator | Add behavior without subclassing | Flexible runtime composition |
| Facade | Simplify a complex subsystem | Reduced coupling to internals |
| Flyweight | Many similar objects consuming memory | Shared state, lower memory |
| Proxy | Control access to another object | Lazy loading, access control, logging |
See references/structural-patterns.md for detailed guides with code examples.
| Pattern | When to Use | Key Benefit |
|---|---|---|
| Chain of Responsibility | Multiple handlers for a request | Decoupled sender/receiver |
| Command | Encapsulate actions as objects | Undo, queue, log operations |
| Iterator | Traverse collections without exposing internals | Uniform traversal interface |
| Mediator | Reduce chaotic dependencies between objects | Centralized communication |
| Memento | Capture and restore object state | Undo without violating encapsulation |
| Observer | Notify dependents of state changes | Loose coupling, event-driven |
| State | Behavior changes based on internal state | Eliminates state conditionals |
| Strategy | Interchangeable algorithms | Open/Closed principle for behavior |
| Template Method | Algorithm skeleton with customizable steps | Code reuse with variation points |
| Visitor | Add operations to objects without modifying them | Separation of concerns |
See references/behavioral-patterns.md for detailed guides with code examples.
This skill integrates with the broader framework:
After pattern work, present:
// REVIEW flags where the pattern application needs human judgmentnpx claudepluginhub guilhermevozniak/refactor-pilot-framework --plugin refactor-pilotProvides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.
Fetches up-to-date documentation from Context7 for libraries and frameworks like React, Next.js, Prisma. Use for setup questions, API references, and code examples.