Skip to content
Skills Library
Programming · Building & coding

design-patterns

/design-patterns

PHP and Laravel design pattern advisor — suggests, implements, refactors, and reviews design patterns in your codebase. Use this skill whenever the user asks about which pattern to use, wants to refactor code to follow a pattern, needs a pattern implemented, or wants a code review focused on architecture and patterns. Triggers for requests like "suggest a pattern for this", "refactor this to use repository pattern", "implement the action pattern", "review my code architecture", "which pattern should I use here", "is this a good use of singleton", "how do I decouple this", "tolong suggest patte

Repository
claude ↗
Licence
MIT
Last repository change
27.10.2026

Assessment and security

87/ 100Class: good
Format20 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability17 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
4
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 27.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

PHP and Laravel design pattern advisor — suggests, implements, refactors, and reviews design patterns in your codebase. Use this skill whenever the user asks about which pattern to use, wants to refactor code to follow a pattern, needs a pattern implemented, or wants a code review focused on architecture and patterns. Triggers for requests like "suggest a pattern for this", "refactor this to use repository pattern", "implement the action pattern", "review my code architecture", "which pattern should I use here", "is this a good use of singleton", "how do I decouple this", "tolong suggest patte

Triggers from the description

suggest a pattern for thisrefactor this to use repository patternimplement the action patternreview my code architecturewhich pattern should I use hereis this a good use of singletonhow do I decouple this
Original author description

PHP and Laravel design pattern advisor — suggests, implements, refactors, and reviews design patterns in your codebase. Use this skill whenever the user asks about which pattern to use, wants to refactor code to follow a pattern, needs a pattern implemented, or wants a code review focused on architecture and patterns. Triggers for requests like "suggest a pattern for this", "refactor this to use repository pattern", "implement the action pattern", "review my code architecture", "which pattern should I use here", "is this a good use of singleton", "how do I decouple this", "tolong suggest patte

How it works

  1. Command Reference
  2. 1. /pattern suggest — Pattern Recommendation
  3. 2. /pattern implement — Generate Pattern Code
  4. 3. /pattern refactor — Refactor Toward Pattern
  5. 4. /pattern review — Architecture Review
  6. Companion: ponytail
  7. Pattern Categories
  8. SOLID Quick Reference
  9. Reference Files
Original SKILL.md headings · 278 lines, 1,710 words
SKILL.md preview
---
name: design-patterns
metadata:
  compatible_agents: [claude-code]
  tags: [php, laravel, design-patterns, architecture, solid]
description: >
  PHP and Laravel design pattern advisor — suggests, implements, refactors, and reviews
  design patterns in your codebase. Use this skill whenever the user asks about which
  pattern to use, wants to refactor code to follow a pattern, needs a pattern implemented,
  or wants a code review focused on architecture and patterns. Triggers for requests like
  "suggest a pattern for this", "refactor this to use repository pattern", "implement the
  action pattern", "review my code architecture", "which pattern should I use here",
  "is this a good use of singleton", "how do I decouple this", "tolong suggest pattern",
  "refactor guna pattern", "review architecture code ni", "pattern mana sesuai untuk ni",
  "nak implement strategy pattern", or "code ni dah jadi god controller, macam mana nak
  fix". Covers GoF patterns adapted for PHP/Laravel, Laravel-specific patterns (Actions,
  Services, DTOs, Value Objects, Query Scopes, Form Requests, API Resources), SOLID
  principles, and anti-pattern detection. Works with cleaniquecoders/laravel-action for
  the Action pattern.
---

# Design Patterns — PHP & Laravel

Pattern advisor for PHP and Laravel projects. Suggests the right pattern for the problem,
implements it with production-ready code, refactors existing code toward better patterns,
and reviews architecture for anti-patterns.

## Command Reference

| Command | Description |
|---|---|
| `/pattern suggest` | Analyse a problem or code snippet and recommend the best pattern(s) |
| `/pattern implement` | Generate production-ready implementation of a specific pattern |
| `/pattern refactor` | Refactor existing code to follow a recommended pattern |
| `/pattern review` | Review code for anti-patterns, SOLID violations, and improvement opportunities |

---

## 1. `/pattern suggest` — Pattern Recommendation

When the user describes a problem or pastes code:

### Step 1: Identify the Problem Category

| Problem Category | Likely Patterns |
|---|---|
| Complex object creation | Factory, Builder |
| Data access / persistence | Repository |
| Cross-cutting concerns (logging, caching, auth) | Decorator, Pipeline |
| Multiple algorithms / strategies for same task | Strategy |
| Reacting to events / side effects | Observer (Event/Listener) |
| State transitions / workflows | State Machine |
| Encapsulating a business operation | Action, Command (Job) |
| Transforming data between layers | DTO, API Resource, Value Object |
| Simplifying a complex subsystem | Facade (real), Adapter |
| Validation / input processing | Form Request |
| Query composition / reuse | Query Builder Scopes |

### Step 2: Read the Decision Matrix

Read `references/decision-matrix.md` for the full mapping of problem types to patterns
with trade-offs and when-to-avoid guidance.

### Step 3: Present Recommendation

Format:

```
**Recommended:** [Pattern Name]
**Why:** [One sentence — what problem it solves in this context]
**Trade-off:** [What you give up]
**Alternative:** [Second-best option and when you'd pick it instead]
```

If multiple patterns apply (e.g., Repository + DTO), explain how they compose together.

---

## 2. `/pattern implement` — Generate Pattern Code

When the user asks to implement a specific pattern:

### Step 1: Confirm Context

Ask (only if not already clear):
- What is the domain entity / use case? (e.g., "Order processing", "User registration")
- Laravel or plain PHP?
- Any existing interfaces or base classes to follow?

### Step 2: Read Reference Files

- `references/pattern-catalog.md` — for GoF patterns adapted to PHP/Laravel
- `references/laravel-patterns.md` — for Laravel-specific patterns

### Step 3: Generate Implementation

Generate all files needed for the pattern:

| Pattern | Files Generated |
|---|---|
| Repository | Interface, Eloquent implementation, Service Provider binding |
| Action | Action class, test file (uses `cleaniquecoders/laravel-action` conventions) |
| Strategy | Interface, concrete strategies, context class |
| Observer | Event class, Listener class, EventServiceProvider registration |
| Pipeline | Pipeline stages as invokable classes, pipeline orchestrator |
| DTO | DTO class with `fromRequest()` and `fromModel()` factory methods |
| Value Object | Immutable class with validation in constructor, equality comparison |
| Factory | Interface, concrete factory, registration in Service Provider |
| Builder | Builder class with fluent API, Director class if needed |
| Decorator | Interface, base implementation, decorator(s), Provider binding |
| State Machine | State interface, concrete states, context class with transitions |

### Step 4: Show Usage

Always include a usage example showing how the pattern integrates with the rest of
the application — controller, route, test, or artisan command.

---

## 3. `/pattern refactor` — Refactor Toward Pattern

When the user pastes code that needs restructuring:

### Step 1: Analyse Current Code

Identify:
- What anti-patterns exist (God controller, fat model, etc.)
- What the code is actually doing (separate concerns)
- Which pattern(s) would improve it

### Step 2: Present Refactoring Plan

Before writing code, show the plan:

```
**Current:** [What the code does now and why it's problematic]
**Target:** [What pattern(s) to apply]
**Steps:**
1. [Extract X into Y]
2. [Create Z interface]
3. [Move logic from A to B]
**Files changed:** [List of files that will be created/modified]
```

Get confirmation before proceeding.

### Step 3: Generate Refactored Code

Show each file with clear comments marking what changed and why.
Include before/after comparison for the main file (e.g., the controller that got thinner).

### Step 4: Generate Tests

For every refactored pattern, generate a Pest test that verifies the behaviour is preserved.

---

## 4. `/pattern review` — Architecture Review

When the user asks for a code review focused on patterns and architecture:

### Step 1: Scan the Codebase

Look at:
- Controllers — are they thin? Do they delegate to actions/services?
- Models — are they doing too much? Business logic in models?
- Services — are they focused (single responsibility) or god services?
- Routes — are resources RESTful?
- Tests — do they test behaviour or implementation details?

### Step 2: Check for Anti-Patterns

| Anti-Pattern | Symptoms | Recommendation |
|---|---|---|
| God Controller | Controller > 200 lines, multiple responsibilities | Extract to Actions or Service classes |
| Fat Model | Model has business logic, query logic, and validation | Extract to Actions, Scopes, Form Requests |
| Service Locator | `app()->make()` scattered everywhere | Use constructor injection |
| Premature Abstraction | Interface with only one implementation, no plan for second | Remove interface, use concrete class |
| Anaemic Domain Model | Models are just data bags, all logic in services | Move domain logic to model methods or Value Objects |
| Leaky Abstraction | Controller knows about database columns, raw queries | Use Repository or Eloquent scopes |
| God Service | Service class > 300 lines doing everything | Split by use case into Action classes |
| Config in Code | Hardcoded values that should be configurable | Extract to config files or .env |

### Step 3: Present Review

Format as a structured report:

```
## Architecture Review — [Context]

### Score: [A/B/C/D] — [One-line summary]

### Strengths
- [What's already good]

### Issues Found
1. **[SEVERITY]** [Anti-pattern name] in [file]
   - Problem: [What's wrong]
   - Fix: [Recommended pattern/action]

### Recommended Refactors (Priority Order)
1. [Highest impact change]
2. [Second highest]
3. [Third]

### Quick Wins
- [Small changes that improve things immediately]
```

---

---

## Companion: ponytail

`ponytail` is installed by default with this toolkit and enforces a minimalism ladder on every
response: **skip it → reuse what exists → stdlib → native platform feature → an
already-installed dependency → one line → the minimum that works.** Stop at the first rung
that holds.

Apply it before proposing any structure here. The most common failure in this skill's area is
a pattern introduced for a problem that does not exist yet:

- An interface with exactly one implementation
- A factory producing one product
- A Repository wrapping Eloquent with no second data source in sight
- A DTO for three scalars that never cross a boundary
- Config for a value that has never changed

Reach for a pattern when there is a **second** case, not in anticipation of one. `/ponytail-review`
checks a diff for over-engineering; `/ponytail-audit` sweeps a whole repo. The ladder shortens
the solution — it never shortens the reading you do first.

## Pattern Categories

### Creational Patterns

| Pattern | Use When | Laravel Context |
|---|---|---|
| Factory | Need to create objects without specifying exact class | Service container bindings, notification channels |
| Builder | Complex object with many optional parameters | Query builders, mail message composition |
| Singleton | Exactly one instance needed (use sparingly) | Service container `singleton()` bindings |

### Structural Patterns

| Pattern | Use When | Laravel Context |
|---|---|---|
| Repository | Decouple data access from business logic | Eloquent repository with interface |
| Decorator | Add behaviour without modifying original class | Cache decorator around repository |
| Adapter | Make incompatible interfaces work together | Wrapping third-party APIs |
| Facade (real) | Simplify complex subsystem interface | Not Laravel's `Facade` class — actual structural pattern |

### Behavioural Patterns

| Pattern | Use When | Laravel Context |
|---|---|---|
| Strategy | Algorithm varies at runtime | Payment gateways, export formats, notification channels |
| Observer | React to events without coupling | Laravel Events + Listeners |
| Pipeline | Sequential processing with stages | Laravel Pipeline, middleware |
| Command | Encapsulate operation as object | Laravel Jobs, queued operations |
| State Machine | Object behaviour changes based on state | Order status, approval workflows |

### Laravel-Specific Patterns

| Pattern | Use When | Package/Feature |
|---|---|---|
| Action | Single-purpose business operation | `cleaniquecoders/laravel-action` |
| Service Class | Orchestrate multiple actions/repos | Plain PHP class, injected via container |
| DTO | Transfer data between layers | Plain PHP class with readonly properties |
| Value Object | Domain concept with equality by value | Immutable PHP class (Money, Email, etc.) |
| Query Scope | Reusable query constraints | Eloquent local/global scopes |
| Form Request | Validation + authorization | Laravel Form Request classes |
| API Resource | Presentation/transformation layer | Laravel API Resources + Resource Collections |

---

## SOLID Quick Reference

Apply these when suggesting or reviewing patterns:

| Principle | Check | Common Laravel Violation |
|---|---|---|
| **S** — Single Responsibility | Does this class have one reason to change? | Controller doing validation + business logic + response formatting |
| **O** — Open/Closed | Can I extend behaviour without modifying? | Switch statements that grow with new cases → use Strategy |
| **L** — Liskov Substitution | Can I swap implementations? | Repository interface methods that only work with Eloquent |
| **I** — Interface Segregation | Does the consumer use all methods? | Bloated service interface → split into focused interfaces |
| **D** — Dependency Inversion | Do I depend on abstractions? | `new ConcreteClass()` inside business logic → inject interface |

---

## Reference Files

| File | Read When |
|---|---|
| `references/pattern-catalog.md` | Implementing any GoF pattern — has full PHP/Laravel code examples |
| `references/laravel-patterns.md` | Implementing Laravel-specific patterns — Actions, Services, DTOs, etc. |
| `references/decision-matrix.md` | Deciding which pattern to use — problem-to-pattern mapping with trade-offs |
Files in this package (4)
  • SKILL.md 12 KB
  • references/decision-matrix.md 13 KB
  • references/laravel-patterns.md 28 KB
  • references/pattern-catalog.md 33 KB

Versions

RepositoryScoreLicence
This page · nasrulhazim/claude87MIT
spencerbeggs/effected100MIT
spencerbeggs/effected100MIT
joeblackwaslike/agent-skills100MIT
krzysztofsurdy/code-virtuoso100MIT
nimadorostkar/Claude-Skills-collection100MIT
andreibesleaga/gabbe100CC-BY-4.0
pantheon-org/tekhne100MIT
itzcull/software-skills100MIT

Database snapshot: 13.11.2026 · package version 30406a3f642f (SHA-256 digest of the entire package)

Downloads in the last 30 days: 3 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100pattern-finder
    Find implementation examples and design patterns in the codebase. Use when user asks "how to implement X", "how does this project do X", "show me examples of X", "where is X implemented", or needs to follow existing code conventions.
  • 100php-patterns
    Apply PHP design patterns — Repository, Factory, Strategy, Decorator, Observer, Singleton, Builder, and Dependency Injection patterns in PHP. Use when architecting PHP applications or understanding patterns used in Magento and other frameworks.
  • 100laravel-patterns
    Provides Laravel PHP patterns for Eloquent ORM, Artisan commands, queues, middleware, and API resources. Use when working with PHP Laravel files (*.php) or when the user mentions Laravel, Eloquent, or PHP framework.
  • 100design-pattern-implementation
    Reviews how design patterns are used or misused across the codebase and where patterns would help. Use when evaluating architecture, pattern fit, or over-engineering.
  • 90laravel-best-practices
    Apply this skill whenever writing, reviewing, or refactoring Laravel PHP code. This includes creating or modifying controllers, models, migrations, form requests, policies, jobs, scheduled commands, service classes, and Eloquent queries. Triggers for N+1 and query performance…
  • 100php-patterns
    Apply PHP design patterns — Singleton, Factory, Strategy, Observer, Repository, Decorator, and Dependency Injection in PHP. Use when structuring WooCommerce extension code or implementing complex business logic.

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.