Reputation: 117
I am working with a large scale NestJS application and been trying to understand best practices around managing modules. The app has many nested modules which need to communicate with eachother. Can anyone provide any insights or tips for managing modules in a large scale NestJS app? One specific question I have is - for the diagram below, is it ok practice to have providers being used between Module C and Module E? Or if these needed to provide services to one or the other, should they be nested under the same module?
Upvotes: 3
Views: 4137
Reputation: 353
Think of modules as bounded contexts. Say we are building an application that needs to speak to a third party API like the one Shopify provides - you would have a service the contains the knowledge of how to speak to this API. Let’s call it the ShopifyService, and this is exported from the ShopifyModule.
Now let’s say Module C is the ProductModule and contains a provider called the ProductService and you want to fetch some product information from the authenticated Shopify store - you would import the ShopifyModule in the ProductModule and then likely inject the ShopifyService into the constructor of the ProductService to make use of the API abstractions.
Module E is the OrderModule, contains a provider called the OrderService and needs to fetch order information from the authenticated Shopify store. You would likely import the ShopifyModule and make use of its provider in the same way.
As you can see, there’s no direct relationship between Module C and Module E, but they both make use of a common module/set of providers.
Hopefully that answers your question!
Upvotes: 4