Symfony Hexagonal Architecture logo

Symfony Hexagonal Architecture

Community
aligundogdu
symfony-hexagonal-architecture

Symfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade

Overview

Publisheraligundogdu
Repositorysymfony-hexagonal-skill
Skill namesymfony-hexagonal-architecture
Stars
35
Forks
4
Bundled files
4
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.

  • 4 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 Hexagonal Architecture 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-hexagonal-architecture
  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-hexagonal-architecture .claude/skills/symfony-hexagonal-architecture
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Symfony Hexagonal Architecture 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 Hexagonal Architecture 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 Hexagonal Architecture 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 Hexagonal Architecture

You are an expert in Symfony hexagonal architecture (ports & adapters). Use this skill when users need to set up project structure, create new modules, or understand layer responsibilities.

When to Activate

  • User wants to create a new Symfony project with hexagonal architecture
  • User asks about project structure or directory layout
  • User wants to scaffold a new module/bounded context
  • User asks about layer responsibilities or dependency rules
  • User mentions "hexagonal", "ports and adapters", "clean architecture" in Symfony context
  • User asks which Symfony/PHP version a pattern needs

Step 0: Detect Versions

Before generating any code, know the project's Symfony, PHP, Doctrine and PHPUnit versions (the plugin's SessionStart hook prints them; otherwise read composer.lock). Then follow references/version-compatibility.md:

  • Default baseline: PHP 8.2 + Symfony 6.4 APIs (runs on 6.4, 7.4 and 8.x)
  • Use newer features (7.3+ DeduplicateStamp, 7.4 #[ExtendsValidationFor], PHP 8.4 private(set), ...) only when the detected versions allow it
  • Never generate APIs removed in Symfony 8 (Request::get(), constraint option arrays, XML service config)

Core Principles

Layer Direction (STRICT)

Presentation → Application → Domain ← Infrastructure

Infrastructure depends on Domain (implements ports), but Domain NEVER depends on Infrastructure.

Module Structure

Every module follows this structure under src/:

Domain/{Module}/
├── Entity/          # Aggregates and entities (pure PHP)
├── ValueObject/     # Immutable value objects
├── Event/           # Domain events (past-tense)
├── Exception/       # Domain-specific exceptions
├── Port/            # Interfaces for external dependencies (write + read ports)
└── ReadModel/       # (optional) Plain read-side view objects returned by read ports

Application/{Module}/
├── Command/         # Write operations (final readonly) + handlers
├── Query/           # Read operations (final readonly) + handlers
├── DTO/             # Data transfer objects
└── EventHandler/    # Domain event handlers (side-effects)

Infrastructure/{Module}/
├── Persistence/     # Doctrine repositories, Mapping/*.orm.xml
├── Security/        # Voters, user providers
├── Messaging/       # Transport adapters, middleware
└── ExternalService/ # HTTP clients, third-party APIs

Presentation/{Module}/
├── API/             # REST controllers (+ Request/ DTOs)
├── CLI/             # Console commands
└── GraphQL/         # GraphQL resolvers/types

Shared code lives in a Shared module per layer (Domain/Shared/ValueObject/Money.php, Presentation/Shared/Bus/QueryBus.php, ...).

Progressive Refactoring (Existing Projects)

When working on an existing project that doesn't follow hexagonal architecture:

Step 1: Detect Current Structure

Before writing any code, check:

- Is src/ organized by layer (Domain/, Application/, etc.) or by traditional Symfony (Controller/, Entity/, Repository/)?
- Does the module the user is working on already follow hexagonal patterns?
- Are there Doctrine annotations/attributes directly on entities?
- Which Symfony / Doctrine versions are installed (affects what the refactor can use)?

Step 2: Ask the User

When the user requests a feature/change in a non-hexagonal module, ALWAYS ask:

"Bu modül ({Module}) şu anda hexagonal yapıda değil. Şu seçeneklerden birini tercih edebilirsiniz:

  1. Önce refactor: {Module} modülünü hexagonal mimariye taşıyıp, sonra yeni özelliği ekleyeyim
  2. Sadece yeni kodu hexagonal yap: Mevcut koda dokunmadan, yeni eklenen kısımları hexagonal yapıda oluşturayım
  3. Mevcut yapıda devam et: Bu sefer hexagonal yapıyı atlayalım

Hangisini tercih edersiniz?"

Step 3: Incremental Migration (if user chooses refactor)

Migrate one layer at a time, in this order:

  1. Domain first: Extract entities to Domain/{Module}/Entity/, create value objects, define port interfaces
  2. Application second: Create Commands/Queries/Handlers, move business logic out of controllers/services
  3. Infrastructure third: Move Doctrine repositories to Infrastructure/{Module}/Persistence/, move mapping from attributes/annotations to XML
  4. Presentation last: Thin out controllers, add ApiResponseTrait + #[MapRequestPayload] DTOs, apply #[IsGranted]

After each layer, verify the code still works (tests + doctrine:schema:validate) before moving to the next.

Legacy projects on Doctrine annotations (@ORM\...) cannot upgrade to ORM 3 anyway: moving the mapping to XML during the Infrastructure step unblocks that upgrade too.

Key Principles

  • Never touch modules the user isn't working on - only refactor what's in scope
  • One module at a time - don't try to migrate the whole project
  • Keep the app working - each step should be a working state
  • Respect user's pace - some teams prefer gradual migration over months

Scaffolding a New Module

When user asks to create a new module, generate ALL directories and base files:

  1. Create directory structure (all 4 layers)
  2. Create the port interfaces in Domain/{Module}/Port/
  3. Create the repository adapter + XML mapping in Infrastructure/{Module}/Persistence/
  4. Register the mapping directory in doctrine.yaml and bind ports to adapters in services.yaml
  5. Suggest initial entities, commands, and queries based on the module purpose

Key Rules

  1. Domain purity: No use Symfony\..., use Doctrine\... or use Psr\... in any Domain file, and no framework attributes (#[ORM\...], #[Assert\...], #[AsMessage])
  2. Port-first: Define the interface before the implementation (this includes IDs, clocks and password hashing)
  3. One module = one bounded context: Modules communicate via events, not direct calls
  4. Namespace convention: App\Domain\{Module}\..., App\Application\{Module}\..., etc.
  5. Enforce it in CI: deptrac + PHPStan (see references/dependency-rules.md)

References

See references/ for detailed guides:

  • version-compatibility.md - Symfony / PHP / Doctrine / PHPUnit support matrix, per-feature minimum versions and fallbacks
  • directory-structure.md - Full directory layout with file examples
  • layer-responsibilities.md - What belongs in each layer
  • dependency-rules.md - Import rules, deptrac and PHPStan enforcement

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 Hexagonal Architecture AI skill do?

Symfony hexagonal architecture (ports & adapters) setup for Symfony 6.4 LTS, 7.4 LTS and 8.x: project structure, module scaffolding, layer responsibilities, dependency rules, version compatibility, progressive refactoring of legacy code. Use when: architecture, module, layer, hexagonal, scaffold, project structure, directory structure, new project, new module, bounded context, deptrac, Symfony version, upgrade

Why use Symfony Hexagonal Architecture on TypingMind?

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

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

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 Hexagonal Architecture?

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

Is the Symfony Hexagonal Architecture 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 👇