agentsclimarketplace

Design patterns

Skill GuilhermeVozniak/refactor-pilot-framework/skills/design-patterns

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.From its SKILL.md

Install
npx -y skills add GuilhermeVozniak/refactor-pilot-framework --skill design-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 3 stars3 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

10.7 KB, as published. Nobody here has run it

Design Patterns Skill

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.

Quick Decision Tree

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

Pattern Identification Workflow

When the user wants to know which patterns fit their code:

Step 1: Identify Code Smells That Patterns Solve

Scan the target code for these smell → pattern mappings:

Code SmellSuggested Pattern(s)
Giant if/else or switch on typeStrategy, State, Command
Copy-pasted logic with minor variationsTemplate Method, Strategy
Constructor with 5+ parametersBuilder
new keyword scattered everywhereFactory Method, Abstract Factory
God class doing too many thingsFacade, Mediator, Command
Tight coupling between modulesObserver, Mediator, Bridge
Adding features requires modifying existing codeDecorator, Strategy, Visitor
Complex object creation logicBuilder, Factory Method, Prototype
Need to support undo/historyMemento, Command
Traversing complex structuresIterator, Composite, Visitor
Different behavior for different statesState
Adapting incompatible interfacesAdapter, Facade
Controlling access to expensive resourcesProxy, Flyweight
Many similar objects consuming memoryFlyweight, Prototype

Step 2: Evaluate Fit

For each candidate pattern, assess:

  1. Problem match — Does the pattern solve the actual problem, or just look similar?
  2. Complexity trade-off — Is the pattern simpler than the current code, or does it add unnecessary indirection?
  3. Team familiarity — Will the team understand and maintain this pattern?
  4. Language fit — Does the language support this pattern idiomatically? (e.g., Strategy is trivial with first-class functions)
  5. Scale appropriateness — Is the codebase large enough to justify the pattern's overhead?
  6. Module depth — Will the pattern make modules deeper (simple interface, more hidden complexity) or shallower (more files/classes that each do little)? A shallow result disqualifies the pattern. See 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.

Step 3: Recommend with Rationale

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]

Pattern Application Workflow

When the user wants to apply a specific pattern:

Step 1: Verify Prerequisites

  • Confirm safety net tests exist (or accept the risk)
  • Read the pattern reference (see references/ docs)
  • Identify all code locations that will change

Step 2: Apply Incrementally

Follow the three-pass approach from the refactor-code skill:

  1. Extract — Pull out the varying behavior or creation logic into separate units
  2. Introduce the pattern — Create the pattern's structural elements (interfaces, base classes, factories, etc.)
  3. Wire up — Replace the original code with the pattern-based implementation

Step 3: Verify Behavior Preservation

  • Run all tests after each step
  • Confirm no public API changes (unless intentional)
  • Add // PATTERN: [PatternName] comments at key structural points for documentation

Step 4: Explain the Pattern Application

After applying, document:

  • Why this pattern was chosen over alternatives
  • How to extend the pattern (e.g., "to add a new strategy, create a class implementing X")
  • Any simplifications made for the specific language/framework

Pattern Refactoring Workflow

When refactoring existing code toward a pattern:

Step 1: Map Current Structure to Pattern Roles

Identify which existing classes/functions/modules map to each role in the target pattern. For example, for Strategy:

  • Context → the class that currently contains the if/else
  • Strategy interface → the abstraction to extract
  • Concrete strategies → each branch of the conditional

Step 2: Incremental Transformation

Transform in small, testable steps:

  1. Extract the interface/protocol/trait
  2. Implement one concrete variant
  3. Verify tests pass
  4. Migrate remaining variants one at a time
  5. Remove the original conditional logic
  6. Clean up and document

Critical: Never change more than one pattern role at a time. Each step should be independently committable and testable.

Pattern Catalog Quick Reference

Creational Patterns (object creation)

PatternWhen to UseKey Benefit
Factory MethodSubclasses decide which class to instantiateOpen/Closed principle for creation
Abstract FactoryFamilies of related objectsConsistent object families
BuilderComplex objects with many optional partsReadable construction, immutable objects
PrototypeCopying existing objects is cheaper than creating new onesAvoids complex initialization
SingletonExactly one instance needed globallyControlled global access

See references/creational-patterns.md for detailed guides with code examples.

Structural Patterns (composition)

PatternWhen to UseKey Benefit
AdapterIncompatible interfaces need to work togetherIntegration without modifying source
BridgeSeparate abstraction from implementationIndependent evolution of both
CompositeTree structures with uniform treatmentSimplifies client code
DecoratorAdd behavior without subclassingFlexible runtime composition
FacadeSimplify a complex subsystemReduced coupling to internals
FlyweightMany similar objects consuming memoryShared state, lower memory
ProxyControl access to another objectLazy loading, access control, logging

See references/structural-patterns.md for detailed guides with code examples.

Behavioral Patterns (communication)

PatternWhen to UseKey Benefit
Chain of ResponsibilityMultiple handlers for a requestDecoupled sender/receiver
CommandEncapsulate actions as objectsUndo, queue, log operations
IteratorTraverse collections without exposing internalsUniform traversal interface
MediatorReduce chaotic dependencies between objectsCentralized communication
MementoCapture and restore object stateUndo without violating encapsulation
ObserverNotify dependents of state changesLoose coupling, event-driven
StateBehavior changes based on internal stateEliminates state conditionals
StrategyInterchangeable algorithmsOpen/Closed principle for behavior
Template MethodAlgorithm skeleton with customizable stepsCode reuse with variation points
VisitorAdd operations to objects without modifying themSeparation of concerns

See references/behavioral-patterns.md for detailed guides with code examples.

Integration with Refactor Pilot Phases

This skill integrates with the broader framework:

  • Phase 1 (Analyze): During codebase analysis, flag code smells that indicate pattern opportunities
  • Phase 2 (Test): Ensure safety nets cover the behavior that patterns will restructure
  • Phase 3 (Transform): Apply patterns using the three-pass approach
  • Phase 4 (Verify): Confirm pattern application didn't change behavior, check extensibility

Output

After pattern work, present:

  1. Summary of patterns identified or applied
  2. Before/after comparison of key code sections
  3. Extensibility guide (how to add new variants/behaviors using the pattern)
  4. Any // REVIEW flags where the pattern application needs human judgment

Critical Rules

  • Patterns are tools, not goals. Don't apply a pattern just because you can.
  • Deep modules beat patterns. When a pattern and a single deeper module both solve the problem, choose the deeper module. The default answer to "which pattern fits?" is often "none — collapse the layers instead."
  • Simpler is better. If a function solves the problem, don't create a class hierarchy.
  • Language idioms first. Use language-native features (closures, protocols, traits) before reaching for classical OOP patterns.
  • One pattern at a time. Apply and verify one pattern before starting the next.
  • Preserve behavior. Pattern refactoring must not change what the code does.
  • Document the "why." Every pattern application should explain the problem it solves.

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.