con un clic
domain-entities
When to use Dry::Struct DTO entities vs. plain Ruby class entities in domain/entities/
Menú
When to use Dry::Struct DTO entities vs. plain Ruby class entities in domain/entities/
Request contracts validate input AND map external API names onto domain entities
Domain-Driven Design architecture patterns and conventions for this project
Roar::Decorator representers that turn domain entities into JSON
Presentation layer serializes domain entities to wire formats (JSON, etc.)
Repository pattern for translating between ORM rows and domain entities
How orm/ and repositories/ split responsibility in app/infrastructure/database/
| name | domain-entities |
| description | When to use Dry::Struct DTO entities vs. plain Ruby class entities in domain/entities/ |
Entities live in app/domain/entities/ and represent things the domain
recognizes by identity. This project uses two implementation styles depending
on whether the entity carries behavior.
Use Dry::Struct when the entity is a passive container that:
Inline example: ./prompt_log.rb
Required shape:
Tyla::Entity::*Dry.Types(). Only use .optional for fields the schema
or workflow legitimately allows to be nil — e.g. id before persistence,
pending-row columns that get back-filled laterto_attr_hash method returning to_hash.except(:id, :created_at) so a
repository can pass it straight into the ORM without re-mappingUse a plain Ruby class when the entity:
See ../SKILL.md (section "Entity & Value Object
Implementation") for the canonical AttendanceReport example.
| Question | Answer | Choice |
|---|---|---|
| Does it have methods beyond getters? | No | Dry::Struct DTO |
| Does it compute or memoize derived values? | Yes | Plain Ruby class |
| Does it cross a boundary as data (DB / API) with no behavior? | Yes | Dry::Struct DTO |
Dry::Struct + external .build factory that computes values and stuffs
them into a passive struct. That separates computation from the object that
should own it.
The Dry::Struct form here is reserved for pure DTOs with no computation
— the values come straight from the boundary (DB row, validated request),
nothing is calculated in flight.