acc-cqrs-knowledge

CQRS architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Command Query Responsibility Segregation audits.

181 stars

Best use case

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

CQRS architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Command Query Responsibility Segregation audits.

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

Manual Installation

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

How acc-cqrs-knowledge Compares

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

Frequently Asked Questions

What does this skill do?

CQRS architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Command Query Responsibility Segregation audits.

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

# CQRS Knowledge Base

Quick reference for CQRS architecture patterns and PHP implementation guidelines.

## Core Principles

### Separation of Concerns

```
┌─────────────────────────────────────────────────────────────┐
│                      APPLICATION                            │
├─────────────────────────────────────────────────────────────┤
│   WRITE SIDE (Commands)     │     READ SIDE (Queries)       │
├─────────────────────────────┼───────────────────────────────┤
│ Command → Handler → Domain  │  Query → Handler → ReadModel  │
│ Changes state               │  Returns data, no side effects│
│ Uses Domain Model           │  Can bypass Domain Model      │
│ Single aggregate per cmd    │  Can join multiple sources    │
└─────────────────────────────┴───────────────────────────────┘
```

**Rule:** Commands WRITE, Queries READ. Never mix.

### CQRS Components

| Component | Purpose | Returns | Side Effects |
|-----------|---------|---------|--------------|
| **Command** | Request to change state | void or ID | Yes |
| **CommandHandler** | Executes command logic | void or ID | Yes |
| **Query** | Request for data | Data DTO | No |
| **QueryHandler** | Fetches and transforms data | Data DTO | No |
| **CommandBus** | Routes commands to handlers | Depends | N/A |
| **QueryBus** | Routes queries to handlers | Query result | N/A |

## Quick Checklists

### Command Checklist

- [ ] Named as imperative verb + noun (CreateOrder, ConfirmPayment)
- [ ] Immutable (readonly class)
- [ ] Contains only data needed for operation
- [ ] Returns void or created ID (never entities)
- [ ] One command = one aggregate affected
- [ ] Validated before dispatch

### Query Checklist

- [ ] Named as Get/Find/List + noun (GetOrderDetails, ListCustomers)
- [ ] Immutable (readonly class)
- [ ] Contains filtering/pagination params
- [ ] Handler has NO side effects
- [ ] Can use optimized read models
- [ ] Returns DTOs, not entities

### Handler Checklist

- [ ] Single `execute()` or `__invoke()` method
- [ ] One handler per command/query
- [ ] CommandHandler can dispatch domain events
- [ ] QueryHandler never dispatches events
- [ ] No cross-aggregate transactions in single handler

## Common Violations Quick Reference

| Violation | Where to Look | Severity |
|-----------|---------------|----------|
| Query with side effects | QueryHandler calling save() | Critical |
| Command returning data | CommandHandler returning entity | Critical |
| Mixed read/write in handler | Handler with both get and save | Critical |
| Business logic in handler | if/switch on domain state | Warning |
| Missing command validation | Command without invariants | Warning |
| Query using write DB | QueryHandler using EntityManager | Info |

## PHP 8.5 CQRS Patterns

### Command

```php
final readonly class CreateOrderCommand
{
    public function __construct(
        public CustomerId $customerId,
        /** @var array<OrderLineData> */
        public array $lines,
        public ?string $notes = null
    ) {
        if (empty($lines)) {
            throw new InvalidArgumentException('Order must have at least one line');
        }
    }
}
```

### Command Handler

```php
final readonly class CreateOrderHandler
{
    public function __construct(
        private OrderRepositoryInterface $orders,
        private EventDispatcherInterface $events
    ) {}

    public function __invoke(CreateOrderCommand $command): OrderId
    {
        $order = Order::create(
            id: OrderId::generate(),
            customerId: $command->customerId,
            lines: $command->lines
        );

        $this->orders->save($order);

        foreach ($order->releaseEvents() as $event) {
            $this->events->dispatch($event);
        }

        return $order->id();
    }
}
```

### Query

```php
final readonly class GetOrderDetailsQuery
{
    public function __construct(
        public OrderId $orderId
    ) {}
}
```

### Query Handler

```php
final readonly class GetOrderDetailsHandler
{
    public function __construct(
        private OrderReadModelInterface $readModel
    ) {}

    public function __invoke(GetOrderDetailsQuery $query): ?OrderDetailsDTO
    {
        return $this->readModel->findById($query->orderId);
    }
}
```

## References

For detailed information, load these reference files:

- `references/command-patterns.md` — Command structure, naming, validation
- `references/query-patterns.md` — Query structure, read models
- `references/handler-patterns.md` — Handler patterns, async/sync
- `references/bus-patterns.md` — Command/Query bus implementations
- `references/antipatterns.md` — Common violations with detection patterns

Related Skills

adr-knowledge-base

181
from majiayu000/claude-skill-registry

ADR知見の体系的参照・適用。主要ADR抜粋(ADR_010, 013, 016, 019, 020, 021)・ADR検索・参照方法・技術決定パターン集・ADR作成判断基準。Phase C以降の技術決定時に使用。

add-knowledge

181
from majiayu000/claude-skill-registry

Add notes and learnings to Tim's work knowledge base at Spotify from any Claude Code session

acc-testing-knowledge

181
from majiayu000/claude-skill-registry

Testing knowledge base for PHP 8.5 projects. Provides testing pyramid, AAA pattern, naming conventions, isolation principles, DDD testing guidelines, and PHPUnit patterns.

acc-stability-patterns-knowledge

181
from majiayu000/claude-skill-registry

Stability Patterns knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Circuit Breaker, Retry, Rate Limiter, Bulkhead, and resilience audits.

acc-solid-knowledge

181
from majiayu000/claude-skill-registry

SOLID principles knowledge base for PHP 8.5 projects. Provides quick reference for SRP, OCP, LSP, ISP, DIP with detection patterns, PHP examples, and antipattern identification. Use for architecture audits and code quality reviews.

acc-saga-pattern-knowledge

181
from majiayu000/claude-skill-registry

Saga Pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for saga orchestration, choreography, and distributed transaction audits.

acc-psr-overview-knowledge

181
from majiayu000/claude-skill-registry

PHP Standards Recommendations (PSR) overview knowledge base. Provides comprehensive reference for all accepted PSRs including PSR-1,3,4,6,7,11,12,13,14,15,16,17,18,20. Use for PSR selection decisions and compliance audits.

acc-psr-coding-style-knowledge

181
from majiayu000/claude-skill-registry

PSR-1 and PSR-12 coding standards knowledge base for PHP 8.5 projects. Provides quick reference for basic coding standard and extended coding style with detection patterns, examples, and antipattern identification. Use for code style audits and compliance reviews.

acc-psr-autoloading-knowledge

181
from majiayu000/claude-skill-registry

PSR-4 autoloading standard knowledge base for PHP 8.5 projects. Provides quick reference for namespace-to-path mapping, composer.json configuration, directory structure, and common mistakes. Use for autoloading audits and project structure reviews.

acc-outbox-pattern-knowledge

181
from majiayu000/claude-skill-registry

Outbox Pattern knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for transactional outbox, polling publisher, and reliable messaging audits.

acc-layer-arch-knowledge

181
from majiayu000/claude-skill-registry

Layered Architecture knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for traditional N-tier/Layered Architecture audits.

acc-hexagonal-knowledge

181
from majiayu000/claude-skill-registry

Hexagonal Architecture (Ports & Adapters) knowledge base. Provides patterns, antipatterns, and PHP-specific guidelines for Hexagonal Architecture audits.