NestJSNest building blocksLesson 41 / 69

Modules, controllers & providers

Fill-gap30 min

Modules, controllers & providers

NestJS organizes a server in three roles:

  • Controller — reads the request, calls the service, returns the response.
  • Service — holds the logic and does the work.
  • Module — wires them together and declares what's shared.
@Controller('lessons')
export class LessonsController {
  constructor(private readonly lessons: LessonsService) {}

  @Get()
  list() { return this.lessons.listAll(); }
}

The rule that keeps Nest apps readable: controllers stay thin, services do the thinking, and one module owns one feature (roadmaps, auth, diagrams — look inside this app's src/ and you will recognize the shape).

Exercise

In this repo's src/roadmaps, identify the three roles. Then write pseudocode for a favorites feature with the same shape.