Generates Correlation ID propagation components for PHP 8.4. Creates PSR-15 middleware, Monolog processor, message bus header propagation, and CorrelationContext value object. Includes unit tests.
From accnpx claudepluginhub dykyi-roman/awesome-claude-code --plugin accThis skill uses the workspace's default tool permissions.
references/examples.mdreferences/templates.mdCreates Correlation ID propagation infrastructure for distributed PHP applications.
| Component | Layer | Path | Purpose |
|---|---|---|---|
CorrelationId | Domain/Shared | src/Domain/Shared/Correlation/CorrelationId.php | UUID-based Value Object |
CorrelationContext | Domain/Shared | src/Domain/Shared/Correlation/CorrelationContext.php | Immutable context holder |
CorrelationContextMiddleware | Presentation | src/Presentation/Middleware/CorrelationContextMiddleware.php | PSR-15 middleware |
CorrelationLogProcessor | Infrastructure | src/Infrastructure/Logging/CorrelationLogProcessor.php | Monolog processor |
CorrelationMessageStamp | Infrastructure | src/Infrastructure/Messaging/CorrelationMessageStamp.php | Message bus stamp |
| Unit tests | Tests | tests/Unit/... | Tests for all components |
final readonly class in Domain layergenerate()Stringable and JsonSerializableequals() methodcorrelationId, causationId, optional userIdcreate() generates new correlation IDfromRequest() extracts from PSR-7 request headerswithCausationId(), withUserId()X-Correlation-ID header from incoming request (or generates new UUID)X-Causation-ID if presentCorrelationContext as request attributeX-Correlation-ID to response headersProcessorInterfacecorrelation_id, causation_id to every log record extra fieldCorrelationContextHolder (request-scoped)StampInterface (or custom stamp interface)correlationId and causationId through message busPath: src/Domain/Shared/Correlation/
CorrelationId.php -- UUID-based Value ObjectCorrelationContext.php -- Immutable context holderUse templates from references/templates.md (Domain section).
Path: src/Presentation/Middleware/
CorrelationContextMiddleware.php -- PSR-15 middlewareUse templates from references/templates.md (Presentation section).
Path: src/Infrastructure/Logging/ and src/Infrastructure/Messaging/
CorrelationLogProcessor.php -- Monolog processorCorrelationMessageStamp.php -- Message bus stampUse templates from references/templates.md (Infrastructure section).
Path: tests/Unit/Domain/Shared/Correlation/ and tests/Unit/Presentation/Middleware/ and tests/Unit/Infrastructure/
CorrelationIdTest.phpCorrelationContextTest.phpCorrelationContextMiddlewareTest.phpCorrelationLogProcessorTest.phpUse templates from references/templates.md (Tests section).
| Component | Default Path |
|---|---|
| CorrelationId | src/Domain/Shared/Correlation/CorrelationId.php |
| CorrelationContext | src/Domain/Shared/Correlation/CorrelationContext.php |
| Middleware | src/Presentation/Middleware/CorrelationContextMiddleware.php |
| Log Processor | src/Infrastructure/Logging/CorrelationLogProcessor.php |
| Message Stamp | src/Infrastructure/Messaging/CorrelationMessageStamp.php |
| Tests | tests/Unit/{layer}/...Test.php |
Adapt paths to match existing project structure detected via:
Glob: src/Domain/**/*.php
Glob: src/Presentation/**/*.php
Glob: src/Infrastructure/**/*.php
final readonly class CorrelationId implements \Stringable, \JsonSerializable
{
public function __construct(public string $value) {}
public static function generate(): self { /* UUID v4 */ }
public function equals(self $other): bool { /* comparison */ }
}
final readonly class CorrelationContext
{
public function __construct(
public CorrelationId $correlationId,
public ?string $causationId = null,
public ?string $userId = null,
) {}
public static function create(): self { /* new with generated ID */ }
public static function fromRequest(ServerRequestInterface $request): self { /* extract headers */ }
}
final readonly class CorrelationContextMiddleware implements MiddlewareInterface
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$context = CorrelationContext::fromRequest($request);
$request = $request->withAttribute(CorrelationContext::class, $context);
$response = $handler->handle($request);
return $response->withHeader('X-Correlation-ID', $context->correlationId->value);
}
}
See references/templates.md for complete implementations and references/examples.md for integration examples.
$app->add(new CorrelationContextMiddleware());
return [
CorrelationContextMiddleware::class => autowire(),
CorrelationLogProcessor::class => autowire(),
];
$context = $request->getAttribute(CorrelationContext::class);
$this->logger->info('Processing order', ['orderId' => $orderId]);
// Log automatically includes correlation_id via processor
See references/examples.md for Symfony, Laravel, and message bus integration.
Provides UI/UX resources: 50+ styles, color palettes, font pairings, guidelines, charts for web/mobile across React, Next.js, Vue, Svelte, Tailwind, React Native, Flutter. Aids planning, building, reviewing interfaces.