I'm new to the NodeJS world, and I try to apply as much good practice as possible for my server to be maintainable and scalable. My application run on Node 12 (will migrate it to version 14 in the near future) and coded in Typescript.
I currently use this kind of data structure :
src
│ app.js # App entry point
└───api # All the endpoints of the app (controllers)
└───config # Environment variables and configuration related stuff
└───jobs # Jobs definitions (cron)
└───loaders # Startup process
└───models # Database & Business models
└───services # All the business logic is here
└───subscribers # Event handlers for async task
└───types # Type declaration files (d.ts) for Typescript
I would like to implement differents design pattern in order to fit my needs but i dont realy know where and how to put them in my code to keep a clean and logical structure. The patterns :
- Builder/Factory : To create some of my models, I would like to use Factory & Builder pattern in order to keep the control on the data that i will push to my backend (I use a no-sql DB, so i want to control the data integrity that is ship in DB).
- Visitor : I have to communicate with external hardware, and the protocol communication will vary depending on hardware model. Visitor will help me to use the good protocol depending on the hardware model.
My problem is that i don't know where and how to put those in this kind of project structure to make sense. Is there a good practice on how to maintain this in order to keep a SOLID pattern ? If you have any suggestion on my folder structure, any recommendation will be appreciated !
Aucun commentaire:
Enregistrer un commentaire