acc-create-outbox-pattern

Generates Transactional Outbox pattern components for PHP 8.5. Creates OutboxMessage entity, repository, publisher, and processor with unit tests.

16 stars

Best use case

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

Generates Transactional Outbox pattern components for PHP 8.5. Creates OutboxMessage entity, repository, publisher, and processor with unit tests.

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

Manual Installation

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

How acc-create-outbox-pattern Compares

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

Frequently Asked Questions

What does this skill do?

Generates Transactional Outbox pattern components for PHP 8.5. Creates OutboxMessage entity, repository, publisher, and processor with 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

# Outbox Pattern Generator

Creates Transactional Outbox pattern infrastructure for reliable event publishing.

## When to Use

- Need reliable event publishing across transaction boundaries
- Prevent message loss if broker is down
- Ensure exactly-once or at-least-once delivery
- Maintain consistency between database and message broker

## Component Characteristics

### OutboxMessage Entity
- Immutable value object in Domain layer
- Contains: id, aggregateType, aggregateId, eventType, payload, timestamps
- Supports reconstitution for persistence
- Methods: withProcessed(), withRetryIncremented()

### OutboxRepository
- Interface in Domain layer
- Implementation in Infrastructure layer
- Methods: save, findUnprocessed, markAsProcessed, incrementRetry, delete

### OutboxProcessor
- Application layer service
- Polls for unprocessed messages
- Publishes to message broker
- Handles failures with retry and dead letter

### Console Command
- Infrastructure layer
- Runs as daemon or one-shot
- Configurable batch size and interval

---

## Generation Process

### Step 1: Generate Domain Layer

**Path:** `src/Domain/Shared/Outbox/`

1. `OutboxMessage.php` — Immutable message entity
2. `OutboxRepositoryInterface.php` — Repository contract

### Step 2: Generate Application Layer

**Path:** `src/Application/Shared/`

1. `Port/Output/MessagePublisherInterface.php` — Publisher port
2. `Port/Output/DeadLetterRepositoryInterface.php` — Dead letter port
3. `Outbox/ProcessingResult.php` — Result value object
4. `Outbox/MessageResult.php` — Result enum
5. `Outbox/OutboxProcessor.php` — Processing service

### Step 3: Generate Infrastructure Layer

**Path:** `src/Infrastructure/`

1. `Persistence/Doctrine/Repository/DoctrineOutboxRepository.php`
2. `Console/OutboxProcessCommand.php`
3. Database migration

### Step 4: Generate Tests

1. `tests/Unit/Domain/Shared/Outbox/OutboxMessageTest.php`
2. `tests/Unit/Application/Shared/Outbox/OutboxProcessorTest.php`

---

## Key Principles

### Transactional Consistency
```php
// In UseCase - save outbox message in SAME transaction
$this->connection->transactional(function () use ($order, $event) {
    $this->orderRepository->save($order);
    $this->outboxRepository->save(
        OutboxMessage::create(
            id: Uuid::uuid4()->toString(),
            aggregateType: 'Order',
            aggregateId: $order->id()->toString(),
            eventType: 'order.placed',
            payload: $event->toArray()
        )
    );
});
```

### Retry with Dead Letter
1. Retry up to MAX_RETRIES times
2. Exponential backoff between retries
3. Move to dead letter queue after max retries
4. Log all failures with context

### Message Headers
Include metadata for tracing:
- message_id, correlation_id, causation_id
- aggregate_type, aggregate_id
- created_at

---

## File Placement

| Layer | Path |
|-------|------|
| Domain Entity | `src/Domain/Shared/Outbox/` |
| Domain Interface | `src/Domain/Shared/Outbox/` |
| Application Service | `src/Application/Shared/Outbox/` |
| Application Port | `src/Application/Shared/Port/Output/` |
| Infrastructure Repo | `src/Infrastructure/Persistence/Doctrine/Repository/` |
| Infrastructure Console | `src/Infrastructure/Console/` |
| Unit Tests | `tests/Unit/{Layer}/{Path}/` |

---

## Naming Conventions

| Component | Pattern | Example |
|-----------|---------|---------|
| Entity | `{Name}` | `OutboxMessage` |
| Repository Interface | `{Name}RepositoryInterface` | `OutboxRepositoryInterface` |
| Repository Impl | `Doctrine{Name}Repository` | `DoctrineOutboxRepository` |
| Service | `{Name}Processor` | `OutboxProcessor` |
| Command | `{Name}Command` | `OutboxProcessCommand` |
| Test | `{ClassName}Test` | `OutboxMessageTest` |

---

## Quick Template Reference

### OutboxMessage

```php
final readonly class OutboxMessage
{
    public static function create(
        string $id,
        string $aggregateType,
        string $aggregateId,
        string $eventType,
        array $payload,
        ?string $correlationId = null,
        ?string $causationId = null
    ): self;

    public function isProcessed(): bool;
    public function isPoisoned(int $maxRetries): bool;
    public function payloadAsArray(): array;
    public function withProcessed(): self;
    public function withRetryIncremented(): self;
}
```

### OutboxRepositoryInterface

```php
interface OutboxRepositoryInterface
{
    public function save(OutboxMessage $message): void;
    public function findUnprocessed(int $limit = 100): array;
    public function markAsProcessed(string $id): void;
    public function incrementRetry(string $id): void;
    public function delete(string $id): void;
}
```

### OutboxProcessor

```php
final readonly class OutboxProcessor
{
    public function process(int $batchSize = 100): ProcessingResult;
}
```

---

## Usage Example

### Saving to Outbox

```php
// In UseCase
$message = OutboxMessage::create(
    id: Uuid::uuid4()->toString(),
    aggregateType: 'Order',
    aggregateId: $order->id()->toString(),
    eventType: 'order.placed',
    payload: [
        'order_id' => $order->id()->toString(),
        'customer_id' => $order->customerId()->toString(),
        'total' => $order->total()->amount(),
    ],
    correlationId: $command->correlationId
);

$this->outboxRepository->save($message);
```

### Console Command

```bash
# One-shot processing
php bin/console outbox:process --batch-size=100

# Daemon mode
php bin/console outbox:process --daemon --interval=1000
```

---

## DI Configuration

```yaml
# Symfony services.yaml
Domain\Shared\Outbox\OutboxRepositoryInterface:
    alias: Infrastructure\Persistence\Doctrine\Repository\DoctrineOutboxRepository

Application\Shared\Port\Output\MessagePublisherInterface:
    alias: Infrastructure\Messaging\RabbitMq\RabbitMqPublisher

Application\Shared\Outbox\OutboxProcessor:
    arguments:
        $maxRetries: 5
```

---

## Database Schema

```sql
CREATE TABLE outbox_messages (
    id VARCHAR(36) PRIMARY KEY,
    aggregate_type VARCHAR(255) NOT NULL,
    aggregate_id VARCHAR(255) NOT NULL,
    event_type VARCHAR(255) NOT NULL,
    payload JSONB NOT NULL,
    correlation_id VARCHAR(255),
    causation_id VARCHAR(255),
    created_at TIMESTAMP(6) NOT NULL,
    processed_at TIMESTAMP(6),
    retry_count INT NOT NULL DEFAULT 0
);

CREATE INDEX idx_outbox_unprocessed
ON outbox_messages (processed_at, created_at)
WHERE processed_at IS NULL;
```

---

## References

For complete PHP templates and test examples, see:
- `references/templates.md` — All component templates
- `references/tests.md` — Unit test examples

Related Skills

advanced-typescript-patterns

16
from diegosouzapw/awesome-omni-skill

Advanced TypeScript patterns for TMNL. Covers conditional types, mapped types, branded types, generic constraints, type inference, and utility type composition. Pure TypeScript patterns beyond Effect Schema.

Advanced GetX Patterns

16
from diegosouzapw/awesome-omni-skill

Advanced GetX features including Workers, GetxService, SmartManagement, GetConnect, GetSocket, bindings composition, and testing patterns

ActiveRecord Query Patterns

16
from diegosouzapw/awesome-omni-skill

Complete guide to ActiveRecord query optimization, associations, scopes, and PostgreSQL-specific patterns. Use this skill when writing database queries, designing model associations, creating migrations, optimizing query performance, or debugging N+1 queries and grouping errors.

actions-pattern

16
from diegosouzapw/awesome-omni-skill

Garante que novas Actions sigam o padrão de classes actions reutilizáveis do Easy Budget.

Action Pattern Conventions

16
from diegosouzapw/awesome-omni-skill

This skill should be used when the user asks about "Laravel action pattern", "action class naming", "how to structure actions", "React component patterns", "Node.js service structure", "framework-specific conventions", or discusses creating reusable, focused classes following action pattern conventions in Laravel, Symfony, React, Vue, or Node.js projects.

Action Cable & WebSocket Patterns

16
from diegosouzapw/awesome-omni-skill

Real-time WebSocket features with Action Cable in Rails. Use when: (1) Building real-time chat, (2) Live notifications/presence, (3) Broadcasting model updates, (4) WebSocket authorization. Trigger keywords: Action Cable, WebSocket, real-time, channels, broadcasting, stream, subscriptions, presence, cable

accessibility-patterns

16
from diegosouzapw/awesome-omni-skill

Build inclusive web experiences following WCAG guidelines. Covers semantic HTML, ARIA, keyboard navigation, color contrast, and testing strategies. Triggers on accessibility, a11y, WCAG, screen readers, or inclusive design requests.

acc-create-use-case

16
from diegosouzapw/awesome-omni-skill

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-state

16
from diegosouzapw/awesome-omni-skill

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-saga-pattern

16
from diegosouzapw/awesome-omni-skill

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

16
from diegosouzapw/awesome-omni-skill

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

acc-create-responder

16
from diegosouzapw/awesome-omni-skill

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