General Flow

The server listens at a certain port. The incoming requests are routed to the specific controller they’re bound to.

Controllers/Handlers

  • Has request and response parameters bound at runtime by the programming language of choice
  • Validates and transforms (e.g. deserializes) the data from the request. If needed, sends responses for invalid data and such.
  • Sends the data to the service layer for processing.

They should be should be lightweight and focused on orchestration rather than implementation.

Service layer

  • Handles business logic
  • Interacts with the repository layer to access/manage the db data

They might fetch data from one repository, transform it based on business rules, update another repository, and send notifications through external APIs - all as part of a single business operation.

Repository/Database layer

  • abstraction over data storage and retrieval operations
  • SRP for the repository methods (to fetch, modify the data).

In nestjs, it is common to not have this layers especially when we have ORMs like Drizzle and TypeORM that already provide certain abstractions over database queries.


Then we go back to the controller which sends the response to the client.

Middleware

Guards

Interceptors

Pipes (nest.js)

Sources