value-objects-and-dtos
Installation
SKILL.md
Value Objects And Dtos (Symfony)
Use when
- A domain concept with rules of its own (money, email, address) travels as raw scalars.
- Data crosses a boundary: request input, API output, message payload.
- Storing a value object inside a Doctrine entity.
Default workflow
- Decide: a value object for a domain concept with invariants, a DTO for data crossing a boundary.
- Make it
readonly, validate in the constructor, and fail fast. - Give value objects equality by value and operations that return new instances.
- Persist value objects as Doctrine embeddables.
- Keep input DTOs (validation constraints) apart from output DTOs (serializer attributes).
Guardrails
- No setters and no mutation: a change returns a new instance.
- DTOs carry data only, with no behavior.
- Never expose entities directly as API input or output.
- Store money as an integer in minor units, never as a float.