🌟 We are Open Source! Check out our repository on GitHub

NestJS Project Structure

A scalable and maintainable folder structure for NestJS applications

File Structure

  • src
    • main.ts
    • app.module.ts
    • app.controller.ts
    • app.service.ts
    • users
      • users.module.ts
      • users.controller.ts
      • users.service.ts
  • package.json
  • nest-cli.json
  • tsconfig.json
  • README.md

Directory Structure Explanation

src/

The main source directory containing all NestJS application code.

src/main.ts

The entry point of the NestJS application where the app is bootstrapped.

src/app.module.ts

The root module that organizes the application structure and imports other modules.

src/app.controller.ts

The main controller handling basic routes and application-level endpoints.

src/app.service.ts

The main service containing business logic for the application controller.

src/users/

A feature module containing all user-related functionality.

users/users.module.ts

The users module that organizes user-related providers and controllers.

users/users.controller.ts

Controller handling HTTP requests for user-related operations.

users/users.service.ts

Service containing business logic for user operations.