r/FastAPI • u/omry8880 • May 21 '26
Question ORMs to Pydantic models conversion
I'm developing a side project and trying to follow DDD principles as closely as possible. My current structure is router -> service -> repository. I'm using SQLAlchemy for ORM models, which are created and handled in the repository layer.
Right now, I convert those ORM objects into Pydantic models inside the service layer, and then pass those models to the router, which returns them in the response. I'm wondering whether this is the right approach or if there’s a better pattern for handling the conversion and data flow between layers.
23
Upvotes
View all comments
Show parent comment
1
u/omry8880 May 24 '26
You're right, I'm indeed one layer short.
As the project I'm working on currently isn't that complex or big, I'm fine with that. I mainly wanted to experiment with "application level" DDD and the 3-layer separation.
I'll take your advice and won't change my implementation for now.
Regarding the domain model, is it often just a dataclass identical to the pydantic model?
Will definitely read the book.
Thanks!