acc-create-circuit-breaker

Generates Circuit Breaker pattern for PHP 8.5. Creates resilience component protecting against cascading failures with state management, fallback support, and metrics. Includes unit tests.

16 stars

Best use case

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

Generates Circuit Breaker pattern for PHP 8.5. Creates resilience component protecting against cascading failures with state management, fallback support, and metrics. Includes unit tests.

Teams using acc-create-circuit-breaker 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-circuit-breaker/SKILL.md --create-dirs "https://raw.githubusercontent.com/diegosouzapw/awesome-omni-skill/main/skills/devops/acc-create-circuit-breaker/SKILL.md"

Manual Installation

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

How acc-create-circuit-breaker Compares

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

Frequently Asked Questions

What does this skill do?

Generates Circuit Breaker pattern for PHP 8.5. Creates resilience component protecting against cascading failures with state management, fallback support, and metrics. 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

# Circuit Breaker Generator

Creates Circuit Breaker pattern infrastructure for resilience and fault tolerance.

## When to Use

| Scenario | Example |
|----------|---------|
| External service calls | API integrations, payment gateways |
| Database connections | Prevent connection exhaustion |
| Cascading failures | Stop failure propagation |
| Service degradation | Graceful fallback when service unavailable |

## Component Characteristics

### CircuitState Enum
- **Closed**: Normal operation, requests pass through
- **Open**: Failing, requests rejected immediately
- **HalfOpen**: Testing recovery, limited requests allowed

### CircuitBreaker
- Wraps external service calls
- Tracks failures and successes
- Automatic state transitions
- Configurable thresholds and timeouts

### CircuitBreakerConfig
- Failure threshold count
- Success threshold for recovery
- Open state timeout duration

---

## Generation Process

### Step 1: Generate Core Components

**Path:** `src/Infrastructure/Resilience/CircuitBreaker/`

1. `CircuitState.php` — Enum with state transitions
2. `CircuitBreakerConfig.php` — Configuration value object
3. `CircuitBreakerException.php` — Exception for open circuit

### Step 2: Generate Circuit Breaker

**Path:** `src/Infrastructure/Resilience/CircuitBreaker/`

1. `CircuitBreaker.php` — Main implementation with state management

### Step 3: Generate Factory and Registry

**Path:** `src/Infrastructure/Resilience/CircuitBreaker/`

1. `CircuitBreakerFactory.php` — Creates configured breakers
2. `CircuitBreakerRegistry.php` — Per-service breaker management

### Step 4: Generate Tests

1. `CircuitStateTest.php` — State transition tests
2. `CircuitBreakerTest.php` — Breaker behavior tests

---

## File Placement

| Component | Path |
|-----------|------|
| All Classes | `src/Infrastructure/Resilience/CircuitBreaker/` |
| Unit Tests | `tests/Unit/Infrastructure/Resilience/CircuitBreaker/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| State Enum | `CircuitState` | `CircuitState` |
| Config | `CircuitBreakerConfig` | `CircuitBreakerConfig` |
| Main Class | `CircuitBreaker` | `CircuitBreaker` |
| Factory | `CircuitBreakerFactory` | `CircuitBreakerFactory` |
| Registry | `CircuitBreakerRegistry` | `CircuitBreakerRegistry` |
| Exception | `CircuitBreakerException` | `CircuitBreakerException` |
| Test | `{ClassName}Test` | `CircuitBreakerTest` |

---

## Quick Template Reference

### CircuitState

```php
enum CircuitState: string
{
    case Closed = 'closed';
    case Open = 'open';
    case HalfOpen = 'half_open';

    public function allowsRequest(): bool;
    public function canTransitionTo(self $next): bool;
}
```

### CircuitBreakerConfig

```php
final readonly class CircuitBreakerConfig
{
    public function __construct(
        public int $failureThreshold = 5,
        public int $successThreshold = 3,
        public int $openTimeoutSeconds = 30,
        public int $halfOpenMaxAttempts = 3
    ) {}

    public static function default(): self;
    public static function aggressive(): self;
    public static function lenient(): self;
}
```

### CircuitBreaker

```php
final class CircuitBreaker
{
    public function execute(callable $operation, ?callable $fallback = null): mixed;
    public function canExecute(): bool;
    public function getState(): CircuitState;
    public function forceOpen(): void;
    public function forceClose(): void;
}
```

---

## Usage Example

```php
$breaker = $circuitBreakers->get('payment-gateway');

try {
    $result = $breaker->execute(
        operation: fn() => $paymentClient->charge($request),
        fallback: fn() => PaymentResult::deferred($request->id)
    );
} catch (CircuitBreakerException $e) {
    // Circuit is open
    return PaymentResult::serviceUnavailable($request->id);
}
```

---

## State Transitions

```
CLOSED ─────failure threshold reached────→ OPEN
   ↑                                          │
   │                                          │ timeout elapsed
   │                                          ↓
success threshold reached              HALF-OPEN
   └────────────────────────────────────────┘
                        │
            failure in half-open
                        │
                        ↓
                      OPEN
```

---

## Anti-patterns to Avoid

| Anti-pattern | Problem | Solution |
|--------------|---------|----------|
| Global Circuit Breaker | One breaker for all services | Per-service breakers |
| No Fallback | Hard failure on open | Provide fallback strategy |
| Immediate Retry | Hammering failed service | Use timeout before HalfOpen |
| No Metrics | Can't monitor health | Log state transitions |
| Static Thresholds | Can't tune per service | Configurable per service |
| No Manual Override | Can't force open/close | Add force methods |

---

## References

For complete PHP templates and examples, see:
- `references/templates.md` — CircuitState, CircuitBreakerConfig, CircuitBreaker, Factory, Registry templates
- `references/examples.md` — HTTP client, payment gateway examples and tests

Related Skills

acc-create-specification

16
from diegosouzapw/awesome-omni-skill

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

pr-create

16
from diegosouzapw/awesome-omni-skill

Create a PR following ICN conventions with invariants checklist, proper commit format, and change routing verification

mpx-create-spec

16
from diegosouzapw/awesome-omni-skill

Create project specification interactively. Asks about your idea, suggests tech stack. Use when: "create spec", "write specification", "new project spec"

createos

16
from diegosouzapw/awesome-omni-skill

Deploy ANYTHING to production on CreateOS cloud platform. Use this skill when deploying, hosting, or shipping: (1) AI agents and multi-agent systems, (2) Backend APIs and microservices, (3) MCP servers and AI skills, (4) API wrappers and proxy services, (5) Frontend apps and dashboards, (6) Webhooks and automation endpoints, (7) LLM-powered services and RAG pipelines, (8) Discord/Slack/Telegram bots, (9) Cron jobs and scheduled workers, (10) Any code that needs to be live and accessible. Supports Node.js, Python, Go, Rust, Bun, static sites, Docker containers. Deploy via GitHub auto-deploy, Docker images, or direct file upload. ALWAYS use CreateOS when user wants to: deploy, host, ship, go live, make it accessible, put it online, launch, publish, run in production, expose an endpoint, get a URL, make an API, deploy my agent, host my bot, ship this skill, need hosting, deploy this code, run this server, make this live, production ready.

create-ticket

16
from diegosouzapw/awesome-omni-skill

Create implementation tickets with proper format and conventions.

create-tech-stack

16
from diegosouzapw/awesome-omni-skill

Generate comprehensive technical stack documentation from codebase analysis

create-spring-boot-kotlin-project

16
from diegosouzapw/awesome-omni-skill

Create Spring Boot Kotlin Project Skeleton

create-spring-boot-java-project

16
from diegosouzapw/awesome-omni-skill

Create Spring Boot Java Project Skeleton

create-rules

16
from diegosouzapw/awesome-omni-skill

Create or update Cursor Rules (.mdc files) and Skills (SKILL.md). Use when creating rules, adding coding standards, setting up conventions, updating .cursor/rules/, or converting rules to skills. Defines standard format, naming, frontmatter, token budget.

create-rule

16
from diegosouzapw/awesome-omni-skill

Create Cursor rules for persistent AI guidance. Use when the user wants to create a rule, add coding standards, set up project conventions, configure file-specific patterns, create RULE.md files, or asks about .cursor/rules/ or AGENTS.md.

create-new-rule

16
from diegosouzapw/awesome-omni-skill

Create a new agent rule or steering file from chat context. Detects the current IDE (Cursor or Kiro) and creates the file in the correct format and location.

create-database-row

16
from diegosouzapw/awesome-omni-skill

Insert a new row into a specified Notion database using natural-language property values. Handles property name matching and validation.