So I'm writing a pretty big RESTful web-app and I opted for NestJS. So far I like it, I like the modular structure with DI, and I find it very appropriate for a REST app.
My general structure is basically a number of modules for the "main" resources, and they each have their own sub-modules for their sub-resources.
I use the Repository pattern and made it so that any repository is available to any provider who whishes to get it (since it relies on a global dependency), but generally I use repositories in services related to the entity, and service functions across the module in controllers, guards, interceptors and so on.
Some resorces might be shared and so I also have some "partial" modules, instantinated in a slightly different manner from one resource to another.
Other than that, there are the "utility" modules, which I made all global for convinience, and provide general common functionality (database, authentication, 3rdParties).
The "issue" begins when sometimes, some resources need access to services in their parent-module, so a circular dependency resolution is needed. Other times a service is needed from a module that is outside this resource's module hierarchy branch, so a resource that is not "under" nor "above" this resource. I can already see the jungle of dependencies to come, with circular dependencies and basically making perhaps most of my "main" resource modules available for most other main resources.
Now I wonder why not just make all my "main" resource modules gloabl, thus all my services are available globally to anyone who wishes to inject them, plus all my sub-modules are basically also available anywhere, though you need to explicitly provide them in module definition.
Why not make all modules global, for that matter, if youv'e already leveraged the advantages of the modular approach, and make your life easier without having to define endless lists of dependencies in module definitions, and without circular dependency issues?
Am i missing something here?
I feel like I'm maybe not looking at it from the right angle..