Nodebestpractices: What are best approach to design Scalable, Maintable (Clean Code) node Architecture for Enterprise Application

Created on 9 Sep 2018  ยท  15Comments  ยท  Source: goldbergyoni/nodebestpractices

I need suggestions on following:-

How to structure routes

  • Contain request validation or response handing here?
  • Or keep it simple just with middlewares?

Controller

  • Should we add business logic in controller or create a helper layer(in case of helper layer controller will contain just call of helper class and handling request and response )?

Service (A service layer for db interaction)

  • Since i am using Mongoose as ODM so what is better approach weather i should i have to create only single save(), update(), find(), get() functions in entire application and pass my Model at run time based on modal execute there respective function Or just keep copy and paste same function again and again with different model ?

Error Handling
How to write common error handler and send there respective response message to user with there respective error code

Log Messages

  • What is best practices for logging
  • Log message format
  • What information we should add in logs (precise) and what shouldn't
  • How we can make it common (avoid duplicable code)

I want code with less duplicasy more generic, it would be grate if you share a boiler plate code

stale

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

All 15 comments

@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?
  • What are design patterns we can use ? or any specific design pattern is best suit for any particular use case ?
  • 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! ๐Ÿ’š

Was this page helpful?
0 / 5 - 0 ratings

Related issues

heyfirst picture heyfirst  ยท  6Comments

bikingbadger picture bikingbadger  ยท  6Comments

YukiOta picture YukiOta  ยท  3Comments

mcollina picture mcollina  ยท  3Comments

Luifr picture Luifr  ยท  5Comments