DEV Community

Discussion on: Node.js Folder Structure

Collapse
asamolion profile image
Muhammad Osama Arshad

Can you give descriptions for what you're files do?

what's the roles of

goods.services.js
goods.plugins.js
good.repository.js?

Collapse
slimcoder profile image
Slim Coder Author

controller is c from MVC.
plugins consists of decorators.
repository calls services.
services calls db.
mediators handle complexity of controller.
validations file consist of joi validation.
route consist of routers.

I.E
goods.controller.js
goods.mediator.js
goods.plugins.js
goods.repository.js
goods.services.js
goods.validations.js
goods.routes.js

Collapse
asamolion profile image
Muhammad Osama Arshad • Edited on

Cool.

Here are my thoughts:

  1. The folder structure is expressive enough to handle most cases, however I find that most of this stuff is unnecessary in small to medium scale applications. For larger applications I suppose that many layers may make sense.
  2. I see that you've grouped together all of the feature related code, however I don't see a goods.test.js file. is the by design?
  3. For most small to medium scale applications, a simple service layer and database model layer is sufficient, so this folder structure would be overkill in those cases.
Thread Thread
slimcoder profile image
Slim Coder Author

I also write test.
I was thinking about changing it to follow SRP and then DI and make a factory within each and every responsibilities.

Thread Thread
asamolion profile image
Muhammad Osama Arshad

What's SRP and DI?

Thread Thread
slimcoder profile image
Slim Coder Author • Edited on

SRP: Seperation of Responsibility Principle.
DI: Dependency Injection

Thread Thread
asamolion profile image
Muhammad Osama Arshad

and these are used for?