Symfony Domain Modeling logo

Symfony Domain Modeling

Community
aligundogdu
symfony-domain-modeling

Symfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status

Overview

Publisheraligundogdu
Repositorysymfony-hexagonal-skill
Skill namesymfony-domain-modeling
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 Domain Modeling 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-domain-modeling
  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-domain-modeling .claude/skills/symfony-domain-modeling
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Symfony Domain Modeling 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 Domain Modeling 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 Domain Modeling 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 Domain Modeling

You are an expert in Domain-Driven Design within Symfony hexagonal architecture. Use this skill when users need to create or modify domain model elements.

When to Activate

  • User wants to create an entity or aggregate root
  • User asks about value objects
  • User needs domain events
  • User mentions domain exceptions or business rules
  • User discusses aggregates or invariants

Version Notes

FeatureRequiresFallback
final readonly classPHP 8.2PHP 8.1: final class + public readonly properties
public private(set) properties, property hooksPHP 8.4 + Doctrine ORM 3.4private property + getter
clone($this, ['amount' => $x])PHP 8.5new self(...)
array_find(), array_any(), array_all()PHP 8.4foreach loop

Generate the fallback form unless the detected PHP constraint allows the newer syntax.

Entity Patterns

Rules

  • Private constructor + static factory method(s)
  • No Doctrine annotations/attributes, mapping is XML in Infrastructure
  • Record domain events on state changes
  • Protect invariants in methods, not in external validators
  • Use value objects for typed properties (no primitive obsession)
  • Receive IDs and "now" from the caller (generated via ports), never call UUID libraries or time() inside the entity
  • Type the event list for PHPStan: /** @var list<DomainEvent> */

Template

php
namespace App\Domain\{Module}\Entity;

use App\Domain\Shared\Event\DomainEvent;

final class {Entity}
{
    /** @var list<DomainEvent> */
    private array $domainEvents = [];

    private function __construct(
        private {Entity}Id $id,
        // typed properties using value objects
    ) {
    }

    public static function create({Entity}Id $id /*, params */): self
    {
        // validate invariants
        $entity = new self($id /*, params */);
        $entity->recordEvent(new {Entity}Created($id->value));

        return $entity;
    }

    // Business methods that protect invariants
    public function doAction(/* params */): void
    {
        // guard clause / invariant check
        // state change
        $this->recordEvent(new {ActionDone}($this->id->value));
    }

    /** @return list<DomainEvent> */
    public function pullDomainEvents(): array
    {
        $events = $this->domainEvents;
        $this->domainEvents = [];

        return $events;
    }

    private function recordEvent(DomainEvent $event): void
    {
        $this->domainEvents[] = $event;
    }
}

Value Object Patterns

Rules

  • Always final readonly class (PHP 8.2+)
  • Self-validating in constructor (throw domain exception if invalid)
  • Immutable, no setters; transformations return new instances
  • Implement equals() for comparison
  • Use for: IDs, email, money, dates, status enums

Template

php
namespace App\Domain\{Module}\ValueObject;

use App\Domain\{Module}\Exception\Invalid{ValueObject}Exception;

final readonly class {ValueObject}
{
    public function __construct(
        public string $value,
    ) {
        if (/* validation fails */) {
            throw Invalid{ValueObject}Exception::forValue($value);
        }
    }

    public function equals(self $other): bool
    {
        return $this->value === $other->value;
    }

    public function __toString(): string
    {
        return $this->value;
    }
}

Domain Event Patterns

Rules

  • Past-tense naming: UserRegistered, OrderPlaced, PaymentFailed
  • Immutable (final readonly class) implementing App\Domain\Shared\Event\DomainEvent
  • Carry only the data needed by handlers (IDs and scalars, not entities), they get serialized on async transports
  • Created inside entities on state changes
  • No #[AsMessage] on domain events (it is a Symfony attribute): route them in messenger.yaml

Template

php
namespace App\Domain\{Module}\Event;

use App\Domain\Shared\Event\DomainEvent;

final readonly class {PastTenseEvent} implements DomainEvent
{
    public function __construct(
        public string $aggregateId,
        public \DateTimeImmutable $occurredOn,
        // additional event-specific data
    ) {
    }

    public function aggregateId(): string
    {
        return $this->aggregateId;
    }

    public function occurredOn(): \DateTimeImmutable
    {
        return $this->occurredOn;
    }
}

Domain Exception Patterns

php
namespace App\Domain\{Module}\Exception;

final class {DomainException} extends \DomainException
{
    public static function because{Reason}(string $context): self
    {
        return new self(sprintf('Descriptive message: %s', $context));
    }
}

References

See references/ for detailed patterns:

  • entity-patterns.md - Full entity examples with aggregates
  • value-object-patterns.md - Common value object implementations, ID generation port
  • domain-event-patterns.md - Event design and dispatch patterns

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 Domain Modeling AI skill do?

Symfony DDD domain modeling in pure PHP: entities, aggregates, value objects, domain events, domain exceptions, ID generation ports, PHP 8.2-8.5 modeling features (readonly, private(set), clone with). Use when: entity, value object, domain event, aggregate, domain exception, domain model, domain logic, business rule, invariant, enum status

Why use Symfony Domain Modeling on TypingMind?

Because you install it once and use it with any model. Symfony Domain Modeling 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 Domain Modeling in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/aligundogdu/symfony-hexagonal-skill/tree/main/skills/symfony-domain-modeling. 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 Domain Modeling?

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 Domain Modeling?

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

Is the Symfony Domain Modeling 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 👇