Prefer feature based file structure. Why group all your models and all your services together. They donβt really have anything in common. They just happen to be of the same type. Better to group posts model and posts service together.
Programming languages enthusiast. Author of Learn Type Driven Development: https://www.packtpub.com/application-development/learn-type-driven-development
We might be talking about different 'models' here. E.g. the types that are tightly coupled to a particular controller (request) or a service should probably live in the same file or folder. But types that are not obviously coupled could go in a shared 'models' folder, but then I would argue, why are they not strongly coupled to any controller or service? Another point here is that it's OK for a controller to import the types of a service that it uses, that is just normal layered architecture for a higher level to be aware of the lower level.
Senior Software Engineer at Noom, formerly Team Lead Engineering at XING. I intend to write about functional programming and occasionally some random engineering topic.
I've been using this generic structure, which I find works pretty well in practice in several languages and domains:
/common
/models (shared models are moved here)
/...
/feature1
/data
/models (optional folder, if project is too small, not worth it
/domain
/models
/presentation
/feature2
/data
/domain
/presentation
Prefer feature based file structure. Why group all your models and all your services together. They donβt really have anything in common. They just happen to be of the same type. Better to group posts model and posts service together.
This doesn't make much sense. A model will often apply to multiple request methods and/or routes.
So import it where it's needed. Same way as you do when putting models in its folder etc.
We might be talking about different 'models' here. E.g. the types that are tightly coupled to a particular controller (request) or a service should probably live in the same file or folder. But types that are not obviously coupled could go in a shared 'models' folder, but then I would argue, why are they not strongly coupled to any controller or service? Another point here is that it's OK for a controller to import the types of a service that it uses, that is just normal layered architecture for a higher level to be aware of the lower level.
I've been using this generic structure, which I find works pretty well in practice in several languages and domains:
That's a good architecture too! :)