acc-create-builder

Generates Builder pattern for PHP 8.5. Creates step-by-step object construction with fluent interface and validation. Includes unit tests.

181 stars

Best use case

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

Generates Builder pattern for PHP 8.5. Creates step-by-step object construction with fluent interface and validation. Includes unit tests.

Teams using acc-create-builder 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-builder/SKILL.md --create-dirs "https://raw.githubusercontent.com/majiayu000/claude-skill-registry/main/skills/data/acc-create-builder/SKILL.md"

Manual Installation

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

How acc-create-builder Compares

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

Frequently Asked Questions

What does this skill do?

Generates Builder pattern for PHP 8.5. Creates step-by-step object construction with fluent interface and validation. 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

# Builder Pattern Generator

Creates Builder pattern infrastructure for step-by-step construction of complex objects.

## When to Use

| Scenario | Example |
|----------|---------|
| Many constructor parameters | Order with 10+ fields |
| Optional parameters | Email with optional CC, BCC |
| Complex validation | Build-time validation |
| Step-by-step construction | Query building |
| Multiple representations | Different order types |

## Component Characteristics

### Builder Interface
- Defines building steps
- Returns self for fluent interface
- Has build() method for final product

### Concrete Builder
- Implements building steps
- Maintains product state
- Validates before building

### Director (Optional)
- Defines construction order
- Reusable build sequences
- Hides complexity from client

---

## Generation Process

### Step 1: Analyze Requirements

Determine:
- Target product class
- Required vs optional properties
- Validation rules
- Whether Director is needed

### Step 2: Generate Builder Components

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

1. `{Name}BuilderInterface.php` — Builder contract
2. `{Name}Builder.php` — Concrete builder implementation
3. `BuilderValidationException.php` — Validation exception
4. `{Name}Director.php` — Optional director for common builds

### Step 3: Generate Tests

**Path:** `tests/Unit/Domain/{BoundedContext}/Builder/`

1. `{Name}BuilderTest.php` — Builder functionality tests

---

## File Placement

| Component | Path |
|-----------|------|
| Builder Interface | `src/Domain/{BoundedContext}/Builder/` |
| Concrete Builder | `src/Domain/{BoundedContext}/Builder/` |
| Director | `src/Domain/{BoundedContext}/Builder/` |
| Exception | `src/Domain/{BoundedContext}/Builder/` |
| Unit Tests | `tests/Unit/Domain/{BoundedContext}/Builder/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| Interface | `{Name}BuilderInterface` | `OrderBuilderInterface` |
| Concrete Builder | `{Name}Builder` | `OrderBuilder` |
| Director | `{Name}Director` | `OrderDirector` |
| Exception | `BuilderValidationException` | `BuilderValidationException` |
| Test | `{ClassName}Test` | `OrderBuilderTest` |

---

## Quick Template Reference

### Builder Interface

```php
interface {Name}BuilderInterface
{
    public function with{Property1}({Type1} $value): self;
    public function with{Property2}({Type2} $value): self;
    public function build(): {Product};
    public function reset(): self;
}
```

### Concrete Builder

```php
final class {Name}Builder implements {Name}BuilderInterface
{
    private ?{Type1} ${property1} = null;
    private ?{Type2} ${property2} = null;
    private array $errors = [];

    public function with{Property1}({Type1} $value): self
    {
        $this->{property1} = $value;
        return $this;
    }

    public function build(): {Product}
    {
        $this->validate();
        if ($this->errors !== []) {
            throw new BuilderValidationException($this->errors);
        }
        return new {Product}(...);
    }

    public function reset(): self
    {
        $this->{property1} = null;
        $this->errors = [];
        return $this;
    }
}
```

### Director

```php
final readonly class {Name}Director
{
    public function __construct(private {Name}BuilderInterface $builder) {}

    public function buildMinimal{Name}(/* required params */): {Product}
    {
        return $this->builder
            ->reset()
            ->with{Required1}($value1)
            ->build();
    }

    public function buildFull{Name}(/* all params */): {Product}
    {
        return $this->builder
            ->reset()
            ->with{Property1}($value1)
            ->with{Property2}($value2)
            ->build();
    }
}
```

---

## Usage Example

```php
// Direct builder usage
$order = (new OrderBuilder())
    ->forCustomer($customerId)
    ->withShippingAddress($address)
    ->addItem($item1)
    ->addItem($item2)
    ->withDiscountCode('SAVE10')
    ->build();

// Using Director
$director = new OrderDirector(new OrderBuilder());
$minimalOrder = $director->buildMinimalOrder($customerId, $address, $item);
$giftOrder = $director->buildGiftOrder($customerId, $shipping, $billing, $items, 'Happy Birthday!');
```

---

## Anti-patterns to Avoid

| Anti-pattern | Problem | Solution |
|--------------|---------|----------|
| No Validation | Invalid objects built | Validate in build() |
| Mutable Product | Product can change after build | Return immutable objects |
| Missing Reset | Builder state persists | Add reset() method |
| Too Many Steps | Hard to use | Use Director or defaults |
| No Fluent Interface | Verbose client code | Return self from setters |

---

## References

For complete PHP templates and examples, see:
- `references/templates.md` — Builder, QueryBuilder templates
- `references/examples.md` — OrderBuilder, EmailBuilder examples and tests

Related Skills

admin-panel-builder

181
from majiayu000/claude-skill-registry

Expert assistant for creating and maintaining admin panel pages in the KR92 Bible Voice project. Use when creating admin pages, building admin components, integrating with admin navigation, or adding admin features.

adk-agent-builder

181
from majiayu000/claude-skill-registry

Build production-ready AI agents using Google's Agent Development Kit with AI assistant integration, React patterns, multi-agent orchestration, and comprehensive tool libraries. Use when appropriate context detected. Trigger with relevant phrases based on skill purpose.

adb-builder

181
from majiayu000/claude-skill-registry

No description provided.

action-builder-skill

181
from majiayu000/claude-skill-registry

Use when creating or refactoring Nango integration actions to be thin API wrappers - provides patterns for minimal transformation logic, direct proxy calls, and standardized structure

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.