create-idempotent-consumer

Generate an idempotent consumer component for PHP 8.4, including idempotency key management, storage backend, middleware implementation, and unit tests to support message deduplication infrastructure.

Last repository push
GitHub Stars
109
Forks
26
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "create-idempotent-consumer" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-95e2e3f84529018a7013b1487df069b4eb8d81b1668f986b4824ad86c82ae0c1. Verify the upstream source and version against https://github.com/dykyi-roman/awesome-claude-code before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Generate an idempotent consumer component for PHP 8.4, including idempotency key management, storage backend, middleware implementation, and unit tests to support message deduplication infrastructure.

0 Downloads

Introduction source: third_party · dykyi-roman · 0.0.1 Reference

SkillPi interpretation

Tasks
Generates Idempotent Consumer components for PHP 8.4. Creates message deduplication infrastructure with idempotency key management, storage backends, middleware, and unit tests.
Audience
| Scenario | Example | |----------|---------| | Payment processing | Prevent double charges on message replay | | Inventory updates | Avoid duplicate stock deductions | | Event handlers | Process domain events exactly once | | Webhook processing | Handle duplicate webhook deliveries | | Message queue consumers | Deduplicate redelivered messages |
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: create-idempotent-consumer
description: Generates Idempotent Consumer components for PHP 8.4. Creates message deduplication infrastructure with idempotency key management, storage backends, middleware, and unit tests.

Idempotent Consumer Generator

Creates Idempotent Consumer pattern infrastructure for exactly-once message processing guarantees.

When to Use

Scenario Example
Payment processing Prevent double charges on message replay
Inventory updates Avoid duplicate stock deductions
Event handlers Process domain events exactly once
Webhook processing Handle duplicate webhook deliveries
Message queue consumers Deduplicate redelivered messages

Component Characteristics

IdempotencyKey

  • Value object combining messageId + handlerName
  • Deterministic key generation
  • Immutable with toString() representation

IdempotencyStoreInterface

  • Application layer port
  • has(IdempotencyKey): bool — check if already processed
  • mark(IdempotencyKey, DateTimeImmutable ttl): void — mark as processed
  • remove(IdempotencyKey): void — remove entry (for reprocessing)

DatabaseIdempotencyStore

  • PDO-based implementation
  • TTL-based automatic cleanup
  • Unique constraint prevents race conditions

RedisIdempotencyStore

  • Redis SETNX-based implementation
  • TTL via Redis EXPIRE
  • Atomic check-and-set

IdempotentConsumerMiddleware

  • Wraps message handler
  • Checks idempotency before processing
  • Marks as processed after success
  • Returns ProcessingResult enum

ProcessingResult

  • Enum: Processed, Duplicate, Failed
  • Includes original result data on success
  • Includes reason on duplicate/failure

Generation Process

Step 1: Analyze Request

Determine:

  • Storage backend (Database, Redis, or both)
  • TTL for idempotency keys (default: 7 days)
  • Integration point (middleware, decorator, manual)

Step 2: Generate Core Components

  1. Domain Layer (src/Domain/Shared/Idempotency/)

    • IdempotencyKey.php — Key value object
    • ProcessingResult.php — Result value object with status
    • ProcessingStatus.php — Status enum (Processed/Duplicate/Failed)
  2. Application Layer (src/Application/Shared/Idempotency/)

    • IdempotencyStoreInterface.php — Storage port
    • IdempotentConsumerMiddleware.php — Middleware wrapper
  3. Infrastructure Layer (src/Infrastructure/Idempotency/)

    • DatabaseIdempotencyStore.php — PDO implementation
    • RedisIdempotencyStore.php — Redis implementation
    • Database migration
  4. Tests

    • IdempotencyKeyTest.php
    • ProcessingResultTest.php
    • IdempotentConsumerMiddlewareTest.php
    • DatabaseIdempotencyStoreTest.php

File Placement

Layer Path
Domain Types src/Domain/Shared/Idempotency/
Application Port src/Application/Shared/Idempotency/
Infrastructure src/Infrastructure/Idempotency/
Unit Tests tests/Unit/{Layer}/{Path}/

Key Principles

Idempotency Strategy

  1. Generate deterministic key from message ID + handler name
  2. Check store BEFORE processing
  3. Mark as processed AFTER successful handling
  4. Use database unique constraint as safety net
  5. TTL cleanup prevents unbounded growth

Race Condition Handling

  1. Use INSERT ... ON CONFLICT (database)
  2. Use SETNX (Redis)
  3. If duplicate detected mid-processing, return Duplicate result

TTL Management

  1. Default TTL: 7 days (configurable)
  2. Cleanup via cron/scheduled command
  3. Redis handles TTL automatically via EXPIRE

Naming Conventions

Component Pattern Example
Key VO IdempotencyKey IdempotencyKey
Result VO ProcessingResult ProcessingResult
Status Enum ProcessingStatus ProcessingStatus
Store Interface IdempotencyStoreInterface IdempotencyStoreInterface
DB Store DatabaseIdempotencyStore DatabaseIdempotencyStore
Redis Store RedisIdempotencyStore RedisIdempotencyStore
Middleware IdempotentConsumerMiddleware IdempotentConsumerMiddleware
Test {ClassName}Test IdempotencyKeyTest

Quick Template Reference

IdempotencyKey

final readonly class IdempotencyKey
{
    public function __construct(
        public string $messageId,
        public string $handlerName,
    ) {}

    public static function fromMessage(string $messageId, string $handlerName): self;
    public function toString(): string;
    public function equals(self $other): bool;
}

IdempotencyStoreInterface

interface IdempotencyStoreInterface
{
    public function has(IdempotencyKey $key): bool;
    public function mark(IdempotencyKey $key, \DateTimeImmutable $expiresAt): void;
    public function remove(IdempotencyKey $key): void;
}

Usage

$middleware = new IdempotentConsumerMiddleware($store);

$result = $middleware->process(
    key: IdempotencyKey::fromMessage($message->id, 'handle_payment'),
    handler: fn() => $paymentHandler->handle($message),
    ttl: new \DateTimeImmutable('+7 days')
);

match ($result->status) {
    ProcessingStatus::Processed => $logger->info('Processed'),
    ProcessingStatus::Duplicate => $logger->info('Skipped duplicate'),
    ProcessingStatus::Failed => $logger->error('Failed', ['error' => $result->error]),
};

Database Schema

CREATE TABLE idempotency_keys (
    key VARCHAR(255) PRIMARY KEY,
    handler_name VARCHAR(255) NOT NULL,
    processed_at TIMESTAMP(6) NOT NULL,
    expires_at TIMESTAMP(6) NOT NULL
);

CREATE INDEX idx_idempotency_expires ON idempotency_keys (expires_at);

References

For complete PHP templates and test examples, see:

  • references/templates.md — All component templates
  • references/examples.md — Payment handler example and unit tests

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • 解决消息去重、防止重复处理等实际业务痛点
  • 适用于支付、库存、事件处理等高频场景
  • 提供完整的幂等消费者基础设施
Trigger Precision88/100

Highlights

  • description 明确描述功能,关键词精准
  • 边界清晰,覆盖合理
Structure and Standards92/100

Highlights

  • 文档结构完整,章节清晰
  • 包含端到端示例和完整模板
  • frontmatter 完整,命名规范明确
Execution Reliability90/100

Highlights

  • 组件设计合理,可靠性机制完善
  • 包含 TTL 管理、竞态条件处理、数据库约束
  • 提供 Database 和 Redis 两种存储后端实现
Evidence Verifiability (mean of the first four)89/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.