ddd-forum icon indicating copy to clipboard operation
ddd-forum copied to clipboard

[question] models vs repository mode

Open jpollard-cs opened this issue 4 years ago • 0 comments

First of all this is great and thank you for this valuable contribution to the community. The ecosystem is a mess and I can't tell you how many times I've seen architecture end up being an afterthought when it's far too late.

I've been working out a similar approach although using the hexagonal architecture and TypeORM, but have considered switching back to Sequelize mostly because it's what my coworkers are familiar with and partially because of the rigidity of TypeORM despite the first class repository and TypeScript support. The use-case approach of the clean architecture is also really growing on me as I start to tackle more complex problems and application services grow in complexity.

Have you considered using sequelize-typescript's Repository Mode and if so why did you end up going with the active record approach. I appreciate that you isolate this through the repository abstraction and totally think that's a reasonable approach. An alternative, which to be fair is less pure (violates SRP) but involves less mapping would be to use models under sequelize-typescript's repository mode. This leaves out all the extra baggage that comes with the active record approach so you could get away, in most cases, with using the model as both your ORM and domain model. Any thoughts on this? This has been a win for me in terms of eliminating friction for developer adoption.

I'm also curious how you're dealing with persisting aggregates in Sequelize - I know you can use includes for queries, but can you automatically persist to embedded entities (e.g. if an Order has LineItem[] and you update that LineItem[] through the Order can you then get the Order model to persist the LineItem[]changes whenever save is called)? Or do you just have to handle this manually in the repository. To be fair you should strive to keep your aggregates small so it should be rare for this scenario to get overly complex.

jpollard-cs avatar Oct 16 '19 17:10 jpollard-cs