M. Kodirov

STAGE 03 / LESSON 02

NestJS modules, controllers and providers

NestJS organizes an application around modules and injectable components.

THE IDEA

Understand it.

A controller handles incoming requests and returns responses. A provider, often called a service, contains reusable application behavior. A module groups related controllers and providers.

Dependency injection lets Nest supply a provider to the controller. This separation makes it easier to test business logic without treating every behavior as an HTTP concern.

SEE IT IN CONTEXT

A controller delegates work

@Controller("tasks")
export class TasksController {
  constructor(private readonly tasks: TasksService) {}

  @Get()
  list() {
    return this.tasks.findAll();
  }
}

The controller maps GET /tasks to a method; the injected service supplies the behavior. The provider must also be registered in a module.

LEARN FROM REAL WEBSITES

See it in the real world.

These simplified structures come from public sources. Company systems change, and the sources may describe only one project or an earlier design.

Novu

Public code checked November 2026

A public NestJS API project

Novu's public API package declares NestJS dependencies, including its core and common packages.

  1. Novu API project
  2. NestJS packages

What to learn: The package file confirms a concrete NestJS project but does not by itself reveal every controller, provider or production request path.

Read the source: Novu API package

Cal.com

Public code checked November 2026

An API built from modules

Cal.com publishes a NestJS API application module that imports feature modules and declares controllers and providers.

  1. API application module
  2. Feature modules
  3. Controllers and providers

What to learn: The source shows how a real project groups dependencies. It does not prove the deployment layout of every Cal.com service.

Read the source: Cal.com API application module

TRY IT YOURSELF

Practice.

Where would you put a rule that is needed by both an HTTP handler and a background job?

Show one possible answer

Put the reusable business rule in an appropriate provider or domain service, then call it from both entry points.

GO DEEPER

Official references.