A module is a class decorated with @Module() that groups a related set of controllers and providers. Every application has at least one, the root module, and Nest builds its dependency graph starting from it.
@Module({
imports: [DatabaseModule], // Other modules to import
controllers: [UserController], // Controllers in this module
providers: [UserService], // Services/providers in this module
exports: [UserService] // Providers to export for other modules
})
export class UserModule {}
By default, a module encapsulates its providers. Another module can inject only the providers listed in exports, and only after it adds this module to its imports.
Modules give you:
a small public API for each feature, through exports
a clear separation of concerns, one module per feature
reuse of the same module across applications
lazy loading through LazyModuleLoader, which loads a module only when it is needed
Rewriting in plainer words…
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.