Remix.run Logo
NeutralForest 4 days ago

What's the motivation for doing this? When does Pydantic in the domain model starts being an issue?

halfcat 4 days ago | parent [-]

When the structure of your team makes it a problem. Conway’s law.

If you have one person maintaining a CRUD app, splitting out DTOs and APIs and all of these abstractions are completely not needed. Usually, you don’t even know yet what the right abstraction is, and making a premature wrong abstraction is WAY worse. Building stuff because you might need it later is a massive momentum killer.

But at some point when the project has grown (if it grows, which it won’t if you spend all your time making wrong abstractions early on), the API team doesn’t want their stuff broken because someone changed a pydantic model. So you start to need separation, not because it’s great or because it’s “the right way” but because it will collapse if you don’t. It’s the least bad option.

NeutralForest 4 days ago | parent [-]

I'm not sure I agree, you can still use Pydantic in the domain model and update the version of the API when you change the expected schemas of your CRUD application.

Where I'm with you, is that you should take care of your boundaries and muddling the line between your Pydantic domain models and your CRUD models will be painful at some point. If your domain model is changing fast compared to the API you're exposing, that could be an issue.

But that's not a "Pydantic in the domain layer" issue, that's a separation of concerns issue.

chausen 4 days ago | parent [-]

Often you want your domain models to be structured differently than API models, to make them as convenient/understandable to work with as possible for your use case. If you already have different models, why would you want Pydantic in the domain? Even if they start out the same, this would allow them to more easily evolve to be different. I'm not a python expert, so I could be missing the point on Pydantic, but it seems like its value is at the edges of your application.

NeutralForest 3 days ago | parent [-]

That's all fair, I just think it has more to do with separation of concerns than Pydantic and that the OP doesn't make it clear at all.