Wong
Wong

Reputation: 79

How to structure nodejs application in modules?

Please tell me which option is better ?

Option 1: All these methods will be in Track module

Option 2: These methods will be in separate modules

  1. Track module

    • getTrendingTracks
  2. Like module

    • getMyFavoriteTracks
    • likeTrack
    • unlikeTrack
  3. ListeningHistory module

    • getMyPlayedTracks
    • playTrack
  4. Artist module

    • getArtistTracks

Upvotes: 1

Views: 90

Answers (1)

expandable
expandable

Reputation: 2300

It depends on the size and the future development of the application.

If the project is small and you don't expect to have a lot of new functionality option 1 is a good choice. It will keep all things close to one another and you will be able to find and modify them easily.

For projects with a lot of functionality and longer lifespans option 2 is better. This way you will be able to create smaller and more cohesive modules. These modules will depend on other modules, so you can create a module dependency map. This way you can manage the dependencies in your application better so you don't end up with spaghetti code.

When you want to add new functionality you will have to do one of several things:

  • Add a new module. This is the coolest thing in options 2. You just add a completely new thing to get new functionality.
  • Extend an already existing module. Having smaller modules makes this a lot easier.
  • Extend a small number of modules. Having smaller cohesive modules makes this a lot easier too

I highly recommend taking a look at Unreal Engine. It has a very good modular architecture. It has a huge codebase, so in order for it to be manageable, they split the Engine into modules. You can check it here

Upvotes: 2

Related Questions