I need suggestions on following:-
How to structure routes
Controller
Service (A service layer for db interaction)
Error Handling
How to write common error handler and send there respective response message to user with there respective error code
Log Messages
I want code with less duplicasy more generic, it would be grate if you share a boiler plate code
@pramodrwt Welcome! These are all great things to establish best practices for - we'll start a discussion here once we have thought about it
@pramodrwt Welcome! These are the right questions to ask when architecting a node app. You're doing the right thing by investigating and drill into these topics.
We're working on a boilerplate. It will take some time. Soon we will present our boilerplate draft along with explanations in a webinar, would you like to participate?
In the interim, we will put here together a few helpful links and thoughts. I suggest you start with watching this YouTube - it well explains the layers structure (your controller question) and emphasizes that your routes should use a service layer (not "helpers") for all the real domain logic. You may also read about DDD layers
Will share other thoughts about other bullets in the next few days
This is an interesting article about architecture posted in the Nodejs collection: https://medium.com/the-node-js-collection/clean-node-1df635d176f7.
It discusses a normal-ish flow for creating the app and the problems that arise. And from the comments part 2 should be coming out soon to show layers and eventually move to Clean Architecture (from Uncle Bob).
@TheHollidayInn Added to my short read list. Thanks
Hello there! ๐
This issue has gone silent. Eerily silent. โณ
We currently close issues after 100 days of inactivity. It has been 90 days since the last update here.
If needed, you can keep it open by replying here.
Thanks for being a part of the Node.js Best Practices community! ๐
Any update on this ?
@pramodrwt Unfortunately not. We've done our best to cover a multitude of practices but most of your great questions were not answered. Could you maybe your 2 top prioritized questions and share here so I can share my thoguhts with you directly?
Hello there! ๐
This issue has gone silent. Eerily silent. โณ
We currently close issues after 100 days of inactivity. It has been 90 days since the last update here.
If needed, you can keep it open by replying here.
Thanks for being a part of the Node.js Best Practices community! ๐
@pramodrwt i would suggest that you can use uncle Bob's clear architecture for your application.
here are few helpful videos.
https://www.youtube.com/watch?v=fy6-LSE_zjI
https://www.youtube.com/watch?v=CnailTcJV_U
I second @imVinayPandya , watched one of those and it's just great
@imVinayPandya, Thanks
@pramodrwt Unfortunately not. We've done our best to cover a multitude of practices but most of your great questions were not answered. Could you maybe your 2 top prioritized questions and share here so I can share my thoguhts with you directly?
Thanks @i0natan
Best practices for NodeJs application architecture :
- how to manage various layer in application like interaction between different layers?
Simply put, use 3 or 4 layers, with very simple in-memory direct interaction between those. For example, with 3 layers have:- Entry point layer - anything that can start a transaction like API. Very thin layer that just handle errors and maps information . Calls the domain layer
- Domain layer - the core of your app, rules, calls to other services, etc
- Data access layer - I guess the responsibility of this layer is clear, might use on ORM here
- Other layers - some add 4th layer for use-cases, more details can be found on this video:
https://www.youtube.com/watch?v=fy6-LSE_zjI&t=11s
- What are design patterns we can use ? or any specific design pattern is best suit for any particular use case ?
This is a very broad question, like asking for the solution for anything :)
@i0natan Thanks
Hello there! ๐
This issue has gone silent. Eerily silent. โณ
We currently close issues after 100 days of inactivity. It has been 90 days since the last update here.
If needed, you can keep it open by replying here.
Thanks for being a part of the Node.js Best Practices community! ๐
Most helpful comment
@pramodrwt i would suggest that you can use uncle Bob's clear architecture for your application.
here are few helpful videos.
https://www.youtube.com/watch?v=fy6-LSE_zjI
https://www.youtube.com/watch?v=CnailTcJV_U