acc-create-chain-of-responsibility

Generates Chain of Responsibility pattern for PHP 8.5. Creates handler chains for request processing with middleware-style composition. Includes unit tests.

181 stars

Best use case

acc-create-chain-of-responsibility is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Generates Chain of Responsibility pattern for PHP 8.5. Creates handler chains for request processing with middleware-style composition. Includes unit tests.

Teams using acc-create-chain-of-responsibility should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/acc-create-chain-of-responsibility/SKILL.md --create-dirs "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main/skills/data/acc-create-chain-of-responsibility/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/acc-create-chain-of-responsibility/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How acc-create-chain-of-responsibility Compares

Feature / Agentacc-create-chain-of-responsibilityStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Generates Chain of Responsibility pattern for PHP 8.5. Creates handler chains for request processing with middleware-style composition. Includes unit tests.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Chain of Responsibility Pattern Generator

Creates Chain of Responsibility pattern infrastructure for sequential request processing.

## When to Use

| Scenario | Example |
|----------|---------|
| Multiple processors | Validation, discounts, approvals |
| Unknown handlers | Plugin systems |
| Priority processing | First match wins |
| Middleware | HTTP pipeline, logging |

## Component Characteristics

### HandlerInterface
- Defines handle method
- Optional setNext for linking
- Returns result or delegates

### AbstractHandler
- Implements chain linking
- Provides base handle logic
- Simplifies concrete handlers

### Concrete Handlers
- Process specific requests
- Decide to handle or pass
- Can terminate or continue chain

---

## Generation Process

### Step 1: Generate Handler Interface

**Path:** `src/Domain/{BoundedContext}/Handler/`

1. `{Name}HandlerInterface.php` — Handler contract with setNext and handle methods

### Step 2: Generate Abstract Handler

**Path:** `src/Domain/{BoundedContext}/Handler/`

1. `Abstract{Name}Handler.php` — Base class with chain linking logic

### Step 3: Generate Concrete Handlers

**Path:** `src/Domain/{BoundedContext}/Handler/`

1. `{Specific}{Name}Handler.php` — Specific handler implementations

### Step 4: Generate Chain Builder (Optional)

**Path:** `src/Domain/{BoundedContext}/Handler/`

1. `{Name}ChainBuilder.php` — Fluent builder for chain construction

### Step 5: Generate Tests

1. `{Handler}Test.php` — Individual handler tests
2. `{Name}ChainTest.php` — Chain integration tests

---

## File Placement

| Component | Path |
|-----------|------|
| Handler Interface | `src/Domain/{BoundedContext}/Handler/` |
| Abstract Handler | `src/Domain/{BoundedContext}/Handler/` |
| Concrete Handlers | `src/Domain/{BoundedContext}/Handler/` |
| Chain Builder | `src/Domain/{BoundedContext}/Handler/` |
| Pipeline | `src/Application/Pipeline/` |
| Unit Tests | `tests/Unit/Domain/{BoundedContext}/Handler/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| Interface | `{Name}HandlerInterface` | `ValidationHandlerInterface` |
| Abstract | `Abstract{Name}Handler` | `AbstractValidationHandler` |
| Concrete | `{Specific}{Name}Handler` | `EmailValidationHandler` |
| Builder | `{Name}ChainBuilder` | `ValidationChainBuilder` |
| Test | `{ClassName}Test` | `EmailValidationHandlerTest` |

---

## Quick Template Reference

### Handler Interface

```php
interface {Name}HandlerInterface
{
    public function setNext(self $handler): self;
    public function handle({RequestType} $request): {ResultType};
}
```

### Abstract Handler

```php
abstract class Abstract{Name}Handler implements {Name}HandlerInterface
{
    private ?{Name}HandlerInterface $next = null;

    public function setNext({Name}HandlerInterface $handler): {Name}HandlerInterface
    {
        $this->next = $handler;
        return $handler;
    }

    public function handle({RequestType} $request): {ResultType}
    {
        if ($this->next !== null) {
            return $this->next->handle($request);
        }
        return $this->getDefaultResult();
    }

    abstract protected function getDefaultResult(): {ResultType};
}
```

### Concrete Handler

```php
final class {Specific}Handler extends Abstract{Name}Handler
{
    public function handle({RequestType} $request): {ResultType}
    {
        if ($this->canHandle($request)) {
            return $this->process($request);
        }
        return parent::handle($request);
    }

    private function canHandle({RequestType} $request): bool
    {
        return {condition};
    }
}
```

### Chain Builder

```php
final class {Name}ChainBuilder
{
    private array $handlers = [];

    public function add({Name}HandlerInterface $handler): self
    {
        $this->handlers[] = $handler;
        return $this;
    }

    public function build(): {Name}HandlerInterface
    {
        $first = $this->handlers[0];
        $current = $first;
        for ($i = 1; $i < count($this->handlers); $i++) {
            $current = $current->setNext($this->handlers[$i]);
        }
        return $first;
    }
}
```

---

## Usage Examples

### Validation Chain

```php
$chain = (new ValidationChainBuilder())
    ->add(new NotEmptyValidationHandler('email'))
    ->add(new EmailValidationHandler('email'))
    ->add(new MinLengthValidationHandler('password', 8))
    ->build();

$result = $chain->validate($request);

if ($result->hasErrors()) {
    throw new ValidationException($result->getMessage());
}
```

### Discount Chain

```php
$vipHandler = new VipDiscountHandler();
$promoHandler = new PromoCodeDiscountHandler($promoCodes);
$bulkHandler = new BulkDiscountHandler();

$vipHandler->setNext($promoHandler);
$promoHandler->setNext($bulkHandler);

$result = $vipHandler->apply($discountRequest);
```

---

## Anti-patterns to Avoid

| Anti-pattern | Problem | Solution |
|--------------|---------|----------|
| Circular Chain | Infinite loop | Validate chain structure |
| No Default | Unhandled requests | Provide fallback handler |
| Coupled Handlers | Hard to reorder | Use interface properly |
| Missing Builder | Manual chain assembly | Create ChainBuilder |
| State in Handler | Non-reentrant | Make handlers stateless |

---

## References

For complete PHP templates and examples, see:
- `references/templates.md` — Handler Interface, Abstract Handler, Concrete Handler, Chain Builder, Pipeline templates
- `references/examples.md` — Validation Chain, Discount Chain examples and tests

Related Skills

acc-create-value-object

181
from majiayu000/claude-skill-registry

Generates DDD Value Objects for PHP 8.5. Creates immutable, self-validating objects with equality comparison. Includes unit tests.

acc-create-use-case

181
from majiayu000/claude-skill-registry

Generates Application Use Cases for PHP 8.5. Creates orchestration services that coordinate domain objects, handle transactions, and dispatch events. Includes unit tests.

acc-create-unit-test

181
from majiayu000/claude-skill-registry

Generates PHPUnit unit tests for PHP 8.5. Creates isolated tests with AAA pattern, proper naming, attributes, and one behavior per test. Supports Value Objects, Entities, Services.

acc-create-test-double

181
from majiayu000/claude-skill-registry

Generates test doubles (Mocks, Stubs, Fakes, Spies) for PHP 8.5. Creates appropriate double type based on testing needs with PHPUnit MockBuilder patterns.

acc-create-test-builder

181
from majiayu000/claude-skill-registry

Generates Test Data Builder and Object Mother patterns for PHP 8.5. Creates fluent builders with sensible defaults and factory methods for test data creation.

acc-create-strategy

181
from majiayu000/claude-skill-registry

Generates Strategy pattern for PHP 8.5. Creates interchangeable algorithm families with context class, strategy interface, and concrete implementations. Includes unit tests.

acc-create-state

181
from majiayu000/claude-skill-registry

Generates State pattern for PHP 8.5. Creates state machines with context, state interface, and concrete states for behavior changes. Includes unit tests.

acc-create-specification

181
from majiayu000/claude-skill-registry

Generates DDD Specification for PHP 8.5. Creates reusable business rule objects for validation, filtering, and querying with composite pattern support. Includes unit tests.

acc-create-saga-pattern

181
from majiayu000/claude-skill-registry

Generates Saga pattern components for PHP 8.5. Creates Saga interfaces, steps, orchestrator, state management, and compensation logic with unit tests.

acc-create-retry-pattern

181
from majiayu000/claude-skill-registry

Generates Retry pattern for PHP 8.5. Creates resilience component with exponential backoff, jitter, and configurable retry strategies. Includes unit tests.

acc-create-responder

181
from majiayu000/claude-skill-registry

Generates ADR Responder classes for PHP 8.5. Creates HTTP response builders with PSR-7/PSR-17 support. Includes unit tests.

acc-create-repository

181
from majiayu000/claude-skill-registry

Generates DDD Repository interfaces and implementation stubs for PHP 8.5. Creates domain interfaces in Domain layer, implementation in Infrastructure.