1 min readCalm pace · scan the outline anytime

Symfony persistence

Doctrine ORM stays in Infrastructure for Modular Hexagonal DDD.

Symfony persistence

Host: Symfony 8.1.x (PHP ≥ 8.4) · Researched 2026-08
One-shot: /apply/symfony.full.md · Short: /symfony

Doctrine entities and repositories live in Infrastructure. Domain Entities stay plain PHP.

Layout

{Module}/Infrastructure/Persistence/Doctrine/
  Entity/          # Doctrine-mapped models (not Domain Entities)
  Repository/      # implements Domain ports
  Migrations/      # or project migrations/ with module prefixes

Rules

  • Never inject EntityManagerInterface into Use Cases or Domain.
  • Map Doctrine entity ↔ Domain Entity in the repository adapter.
  • DQL/QueryBuilder stay inside Infra.
  • Prefer module-owned tables; avoid coupling schemas across BCs.

Anti-patterns

SmellFix
Doctrine entity used as Domain EntitySeparate Domain Entity + map
#[ORM\…] on Domain classesMove mapping to Infra model
EM flushed inside Use CasePort + Infra unit of work adapter
Modular Hexagonal Domain-Driven Design
Core 1.0.0-draft