Symfony Cqrs Handlers logo

Symfony Cqrs Handlers

Community
aligundogdu
symfony-cqrs-handlers

Symfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp

Overview

Publisheraligundogdu
Repositorysymfony-hexagonal-skill
Skill namesymfony-cqrs-handlers
Stars
35
Forks
4
Bundled files
3
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 3 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by aligundogdu on GitHub. Read the source before you install it.

Installation

Install the Symfony Cqrs Handlers AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/aligundogdu/symfony-hexagonal-skill/tree/main/skills/symfony-cqrs-handlers
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/aligundogdu/symfony-hexagonal-skill.git /tmp/symfony-hexagonal-skill
mkdir -p .claude/skills
cp -r /tmp/symfony-hexagonal-skill/skills/symfony-cqrs-handlers .claude/skills/symfony-cqrs-handlers
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Symfony Cqrs Handlers in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Symfony Cqrs Handlers on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Symfony Cqrs Handlers is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Symfony CQRS Handlers

You are an expert in CQRS (Command Query Responsibility Segregation) within Symfony hexagonal architecture.

When to Activate

  • User wants to create a command or query
  • User needs a handler for a use case
  • User asks about CQRS patterns or message bus configuration
  • User mentions "use case", "action", "operation" in application context

Why Separate Buses

Symfony's docs recommend a single bus unless you need different middleware. This architecture has that need: command.bus wraps handlers in doctrine_transaction, query.bus must never open write transactions, and event.bus must allow zero handlers. Mention this when users question the extra buses.

Version Notes

FeatureRequiresFallback
#[AsMessageHandler(bus: '...')]Symfony 6.0-
#[AsMessage('async')] on a commandSymfony 7.2framework.messenger.routing in YAML
DeduplicateStampSymfony 7.3 + symfony/lockIdempotency key check in the handler
#[AsMessage(serializedTypeName: ...)]Symfony 8.1default FQCN type name

Command Pattern

Commands represent write operations (create, update, delete). They are messages dispatched to the command bus.

Rules

  • final readonly class, immutable after construction
  • Named as imperative verb: RegisterUser, PlaceOrder, CancelSubscription
  • Contains only scalars/arrays (serializable for async transports), no entities
  • Handler returns void or a scalar identifier (string ID)
  • One handler per command

Template

php
namespace App\Application\{Module}\Command;

use Symfony\Component\Validator\Constraints as Assert;

final readonly class {ActionVerb}{Entity}
{
    public function __construct(
        #[Assert\NotBlank]
        public string $param1,
        public string $param2,
    ) {
    }
}

Handler Template

php
namespace App\Application\{Module}\Command;

use App\Domain\{Module}\Port\{Entity}RepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler(bus: 'command.bus')]
final readonly class {ActionVerb}{Entity}Handler
{
    public function __construct(
        private {Entity}RepositoryInterface $repository,
    ) {
    }

    public function __invoke({ActionVerb}{Entity} $command): void
    {
        // 1. Load/create domain objects
        // 2. Execute business logic (entity methods)
        // 3. Persist via port (repository dispatches domain events)
        // NO side-effects here, use domain events
    }
}

Query Pattern

Queries represent read operations. They return DTOs, never domain entities.

Rules

  • final readonly class, immutable
  • Named descriptively: GetUserById, ListActiveOrders, SearchProducts
  • Handler MUST return a DTO, a list of DTOs or a Page of DTOs
  • Handler NEVER modifies state
  • May use read-optimized ports ({Entity}ReadRepositoryInterface) backed by DBAL QueryBuilder

Template

php
namespace App\Application\{Module}\Query;

final readonly class Get{Entity}ById
{
    public function __construct(
        public string $id,
    ) {
    }
}

Handler Template

php
namespace App\Application\{Module}\Query;

use App\Application\{Module}\DTO\{Entity}DTO;
use App\Domain\{Module}\Port\{Entity}RepositoryInterface;
use App\Domain\{Module}\ValueObject\{Entity}Id;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;

#[AsMessageHandler(bus: 'query.bus')]
final readonly class Get{Entity}ByIdHandler
{
    public function __construct(
        private {Entity}RepositoryInterface $repository,
    ) {
    }

    public function __invoke(Get{Entity}ById $query): ?{Entity}DTO
    {
        $entity = $this->repository->findById(new {Entity}Id($query->id));

        return $entity === null ? null : {Entity}DTO::fromEntity($entity);
    }
}

DTO Pattern

php
namespace App\Application\{Module}\DTO;

use App\Domain\{Module}\Entity\{Entity};

final readonly class {Entity}DTO
{
    public function __construct(
        public string $id,
        public string $name,
    ) {
    }

    public static function fromEntity({Entity} $entity): self
    {
        return new self(
            id: $entity->id()->value,
            name: $entity->name(),
        );
    }
}

Symfony 7.3+ ObjectMapper (#[Map]) can replace hand-written fromX() factories for DTO-to-DTO mapping. Do not map directly into Domain entities with it: it bypasses constructors and therefore invariants.

Dispatching From Controllers

Use the CommandBus / QueryBus wrappers from references/bus-configuration.md. They return the handler result and rethrow the original domain exception instead of Messenger's HandlerFailedException, so the API exception subscriber can map it to the right HTTP status.

References

See references/ for detailed guides:

  • command-patterns.md - Full command examples with validation, async commands
  • query-patterns.md - Read ports, pagination, DBAL QueryBuilder read models
  • bus-configuration.md - Messenger bus setup, middleware, bus wrappers

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Symfony Cqrs Handlers AI skill do?

Symfony CQRS with Messenger: commands, queries, handlers, command.bus / query.bus / event.bus configuration, typed bus wrappers, HandlerFailedException unwrapping, read ports and pagination, use cases. Works on Symfony 6.4, 7.x, 8.x. Use when: command, query, handler, CQRS, bus, use case, command handler, query handler, message bus, HandleTrait, HandledStamp

Why use Symfony Cqrs Handlers on TypingMind?

Because you install it once and use it with any model. Symfony Cqrs Handlers is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Symfony Cqrs Handlers in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/aligundogdu/symfony-hexagonal-skill/tree/main/skills/symfony-cqrs-handlers. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Symfony Cqrs Handlers?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Symfony Cqrs Handlers?

As many as you like. As long as a model supports skills, you can use Symfony Cqrs Handlers with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Symfony Cqrs Handlers AI skill free?

It is published on GitHub by aligundogdu. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇