DEV Community

Discussion on: Bulletproof node.js project architecture πŸ›‘οΈ

Collapse
 
elie222 profile image
Elie

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.

Collapse
 
sweepyoface profile image
sweepyoface

This doesn't make much sense. A model will often apply to multiple request methods and/or routes.

Collapse
 
elie222 profile image
Elie

So import it where it's needed. Same way as you do when putting models in its folder etc.

Collapse
 
yawaramin profile image
Yawar Amin

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.

Collapse
 
psfeng profile image
Pin-Sho Feng • Edited

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
Thread Thread
 
santypk4 profile image
Sam

That's a good architecture too! :)