dist/codex/magento2-commerce/skills/php-patterns/SKILL.md
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.
npx skillsauth add orcaqubits/agentic-commerce-claude-plugins php-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Fetch live docs: Web-search php design patterns examples for current community patterns and best practices. For Magento-specific patterns, web-search site:developer.adobe.com commerce php development components.
Creates objects without exposing instantiation logic. In Magento, auto-generated Factory classes (SomeModelFactory) create non-injectable objects via $factory->create().
When to use: When you need new instances (entities, models) rather than shared singletons. When the caller shouldn't know the concrete class.
Constructs complex objects step by step. Magento's SearchCriteriaBuilder, FilterBuilder, SortOrderBuilder follow this pattern.
When to use: When object construction requires many optional parameters or multi-step assembly.
Single instance shared across the application. Magento's Object Manager shares instances by default. Explicit singleton is generally an anti-pattern — prefer DI container sharing.
When to use: Rarely — let the DI container manage instance sharing.
Delays instantiation of resource-intensive dependencies. Magento auto-generates Proxy classes (SomeClass\Proxy) that create the real object only when a method is called.
When to use: When a class injects a heavy dependency it doesn't always use.
Wraps an object to add behavior without modifying the original. Used in Magento composite components and cache decorators.
When to use: When you need to add behavior to an object dynamically without subclassing.
Treats individual objects and compositions uniformly. Magento's UI component tree and layout container system follow this pattern.
When to use: When you have tree-structured data or components.
Defines a family of algorithms, encapsulates each one, makes them interchangeable. Magento shipping carriers and payment methods are strategy implementations.
When to use: When you have multiple algorithms for the same task and want runtime selection.
Defines a one-to-many dependency. When one object changes state, all dependents are notified. Magento's event/observer system is a direct implementation.
When to use: When changes in one object should trigger actions in others without tight coupling.
Mediates between domain and data mapping layers. Magento's repository interfaces (ProductRepositoryInterface) centralize all data access through a clean API.
When to use: Always — for any data access beyond simple reads. It's the standard Magento pattern.
Encapsulates a request as an object. Magento's Payment Gateway Command pattern uses this — authorize, capture, refund are separate command objects.
When to use: When you need to parameterize, queue, or log requests.
Objects receive their dependencies through constructors rather than creating them. Magento's DI container (Object Manager + di.xml) is the foundation of the entire framework.
When to use: Always — it's the core pattern. Inject interfaces, not concrete classes.
Defines an application's boundary with a layer of services that encapsulates business logic. Magento's Service Contracts (interfaces in Api/) form this layer.
When to use: Always — expose module functionality through service interfaces.
Simple objects that carry data between processes. Magento's Data Interfaces (Api/Data/) are DTOs — they have getters/setters but no business logic.
When to use: When passing data across architectural boundaries (API, service layer).
new (use factories or DI)Fetch current framework documentation for exact interface signatures and implementation patterns before applying.
development
Build with Spree's headless Next.js storefront — the official `spree/storefront` repo (Next.js 16 App Router with Server Actions and Turbopack, React 19 Server Components, Tailwind CSS 4, TypeScript 5, `@spree/sdk`, Sentry), server-only auth (httpOnly JWT cookies + publishable key), MeiliSearch faceted catalog, one-page checkout with Apple/Google Pay/Klarna/Affirm/SEPA, multi-region market routing, GA4 + JSON-LD SEO, and Vercel/Docker deployment. Use when forking or customizing the storefront, or evaluating headless adoption.
tools
Build Spree extensions as Rails engines — gem scaffolding, `bin/rails g spree:extension`, mounting routes/migrations/assets, the modern `prepend` decorator pattern (`*_decorator.rb` with `self.prepended(base)`), generators (`spree:model_decorator`, `spree:controller_decorator`), the four customization surfaces in preference order (Events > Webhooks > Dependencies > Decorators), Spree::Dependencies for swapping service objects, gem release/versioning, and the deprecated Deface engine. Use when building a reusable Spree extension or adding non-trivial customization to an app.
development
Build with Spree's event bus and Webhooks 2.0 — `Spree::Events` publication, `Spree::Subscriber` DSL with `subscribes_to` and `on`, wildcard matching, lifecycle events (`{model}.created/.updated/.deleted` via `publishes_lifecycle_events`), the canonical event catalog (order.*, payment.*, shipment.*, product.*), Webhooks 2.0 endpoints, HMAC-SHA256 signing (`X-Spree-Webhook-Signature`), exponential-backoff retries, and Sidekiq job orchestration. Use when wiring event-driven business logic, building webhook consumers, or replacing ActiveSupport callback chains.
tools
Cross-cutting Spree development patterns — the customization preference hierarchy (Events > Webhooks > Dependencies > Decorators), `Spree::Dependencies` service-object swapping, the `_decorator.rb` + `prepend` + `self.prepended` idiom, idempotent subscribers and webhook receivers, multi-store scoping discipline, prefixed IDs, calculator polymorphism (shipping/promotion/tax share the base), service-object composition with `dry-monads` or simple results, why to avoid `class_eval` reopening and Deface, and Spree-on-Rails idioms (Hotwire/Turbo Stimulus, ActiveStorage, Action Cable, Sidekiq). Use when designing the architecture of a Spree extension or solving cross-cutting concerns.