Nodebestpractices: I'm confused about this part of best practices

Created on 21 Dec 2018  路  23Comments  路  Source: goldbergyoni/nodebestpractices

1.1 Structure your solution by components

In this section recommendation is to split components into multiple layers. Things like service, controller, DAL and so on. I have searched many times in Google and I couldn't find any examples with such project structure. That would be very helpful to add a link to a repo that has this structure or if three is none, some code examples that demonstrate this categorization would be appreciated.

Most helpful comment

@aadikill Welcome 馃憢

I understand your concerns and we will start working soon on an example, I just have other OSS projects to accomplish before. For now, I added you to a very preliminary draft code that illustrates the design by components, it's just not documented so I hope it will be useful. Focus on the "Job" Microservice.

Simply put, you just have to create a folder (or a repo) for each domain (e.g. Trello Boards, Users, Carts) and include in this folder all the code including everything that is related to this topic. You should be able to copy this folder alone to some server and run the code. In other words, the folders/components are not allowed to approach each other using a pysical path rather only through network communication.

How do you structure inside each folder/component? how does the component interact with each other? these are all very big design questions that need some context and may vary based on different scenarios. Some designers like MVC-style structure, others (like me) prefer layered architecture. You may prepare some design, present it here and we can discuss it.

@BrunoScheufler About "for example a simple REST microservice where your data is supplied by a shared library or something like this" - I guess that the smaller the app is, the less relevant are all the best practices in the world, maybe we should mention that our repo related to medium> app sizes?

All 23 comments

@ImanMh I think this strongly depends on the way you want to build your projects. Said setup is especially useful if you have a structure which can be separated into single files for each part of the functionality. However, in cases where you're not using any of these parts, for example a simple REST microservice where your data is supplied by a shared library or something like this, I guess the recommendation won't help you. We might as well look into adapting this to current practices, what do you think @i0natan

@BrunoScheufler What I'm saying is not that it should match my code structure, I'm just saying lets put up an example that is more likely to be familiar or even better, let's refer a code repo(or code example) as well. This screen shot demonstrate a lot of layering so it can cover different projects needs. The issue is that people like me who haven't been involved in projects like this can't really achieve any understanding of what goes where in such separations.

@ImanMh completely agree 馃憤 As we're promoting the most agreed-upon practices, I guess we should find the common denominator for our solution 馃槃

@BrunoScheufler right now I'm trying to improve my backend coding experience and I really like the stuff you put in this repo, how ever turning it into action requires more details and explanations. For instance I want to add sequalize to my project I think I want to add models inside a code structure like the one you demonstrated but I'm not sure about migrations and seeds which are essential for a production ready environment. I think we can add much more details and suggestions.

@ImanMh as migrations and db seeds are often affecting multiple projects when you've got multiple services accessing the same database instance, they are stored in an init directory, which is automatically consumed by the database service on initial startup, being a popular choice when using container-based setups. However I guess these things vary from setup to setup

I also need help regarding this structure. Let us consider Trello app structure.
How should I structure my project?
I need to implement User, Board, Card
now Board needs data from user to know who created the board and who all are the members and card needs data from board as well as from user.

I should I implement Data Access Layer in above scenario?
It will be really helpful if somebody can share a snippet.

@aadikill Welcome 馃憢

I understand your concerns and we will start working soon on an example, I just have other OSS projects to accomplish before. For now, I added you to a very preliminary draft code that illustrates the design by components, it's just not documented so I hope it will be useful. Focus on the "Job" Microservice.

Simply put, you just have to create a folder (or a repo) for each domain (e.g. Trello Boards, Users, Carts) and include in this folder all the code including everything that is related to this topic. You should be able to copy this folder alone to some server and run the code. In other words, the folders/components are not allowed to approach each other using a pysical path rather only through network communication.

How do you structure inside each folder/component? how does the component interact with each other? these are all very big design questions that need some context and may vary based on different scenarios. Some designers like MVC-style structure, others (like me) prefer layered architecture. You may prepare some design, present it here and we can discuss it.

@BrunoScheufler About "for example a simple REST microservice where your data is supplied by a shared library or something like this" - I guess that the smaller the app is, the less relevant are all the best practices in the world, maybe we should mention that our repo related to medium> app sizes?

@i0natan Thanks for adding extras, By the way I thing that draft is 404, could you update the link if you still have it?

@i0natan agree, however I also think that project structure practices are changing a lot across architectures due to frameworks/libraries often recommending a certain structure, whereas multiple other variations are usable. It seems pretty hard to find a common denominator to create a best practice from. Long story short: I'm not sure if we should recommend a project structure that might get outdated quickly, and deciding from the infinite pool of structures out there is also hard 馃

@BrunoScheufler You'll be surprised how everlasting the leading architectures are (DDD, clean, hexagonal, etc) and how similar they are. They all dictate a very similar conceptual project structure and anything that is doing something else simply goes against the leading paradigm. With that said, there's also a room for some flexibility and style.

Example - all architecture dictates separating the business logic (features) from the delivery mechanism (e.g. Express) and other tech concerns (e.g. DB, logger). Our structure will just show an example of separation - a different folder for "Domain" (business logic"). We won't emphasize that one must create a folder, rather that some separation (E.g. Class, object) is needed. Does this make sense?

@ImanMh - you mean the link to the example repo? it's private, shall I add you?

@i0natan absolutely! I completely agree to your explanation 馃憤

@i0natan yes add me, I appreciate it.

@ImanMh Done

@i0natan can you add me to the starter too, please?

Sure thing, by eod

@i0natan I would appreciate a look at the starter as well. 馃檪

@i0natan I would appreciate a look at the starter as well. 馃檪

Sure, done. Note that it's very preliminary and raw...

@i0natan can you add me to the starter as well, please?

Done, note that it's a draft at best

@goldbergyoni I would also appreciate an invitation for the example repo! 馃檪

@goldbergyoni same here! :)

Me too, please invite me! :)

Hi @goldbergyoni. Thanks for your work on this project. Would you be able to add me to the example repo please?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

BrunoScheufler picture BrunoScheufler  路  3Comments

halfzebra picture halfzebra  路  4Comments

MIKOLAJW197 picture MIKOLAJW197  路  4Comments

goldbergyoni picture goldbergyoni  路  5Comments

goldbergyoni picture goldbergyoni  路  4Comments