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
EntityManagerInterfaceinto 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
| Smell | Fix |
|---|---|
| Doctrine entity used as Domain Entity | Separate Domain Entity + map |
#[ORM\…] on Domain classes | Move mapping to Infra model |
| EM flushed inside Use Case | Port + Infra unit of work adapter |