One module per feature
As the API grows, group each feature — dishes, orders, users — into its own module. A module's providers are private unless it exports them; another module must import it to use them. Those boundaries keep big apps understandable.
A module that shares its service
import { Module } from "@nestjs/common";
import { DishesController } from "./dishes.controller";
import { DishesService } from "./dishes.service";
@Module({
controllers: [DishesController],
providers: [DishesService],
exports: [DishesService],
})
export class DishesModule {}@Module({
imports: [DishesModule],
controllers: [OrdersController],
providers: [OrdersService],
})
export class OrdersModule {}
@Module({ imports: [DishesModule, OrdersModule] })
export class AppModule {}- Forget the export or the import and Nest refuses to start: "Nest can't resolve dependencies of the OrdersService (?)…" — read that message carefully, it tells you exactly what's missing.
- nest generate module orders creates the folder and registers it in AppModule.