Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Project structure · Backend

NestJS project structure

Opens with credits

For people who want a structured TypeScript backend with clear rules about where code goes. Every feature is a Nest module that owns its controller, service, DTOs, entities and tests, so the app grows by adding folders, not by stretching old ones. The tree follows one orders API from nest new to a codebase a whole team can run for years.

Curated by Tauseef FayyazIntermediate187 files and foldersNestJS 12.1, Node.js 24 LTS, TypeScript 6 (scaffold pin; 7.0 is out)Checked October 2026
Explore the filesPick any file to see what it is, why it exists and when you add it.

How it grows

Each stage opens the explorer there

  1. 1Day 1What the scaffold and your first hour give you23 files and folders
  2. 2GrowingWhat a real app with features and tests adds+83 files and folders
  3. ProductionWhat running it for real users adds+35 files and foldersOpens with credits
  4. ExpertWhat a team needs to keep it healthy for years+46 files and foldersOpens with credits

How it is organised

  • One module per feature: src/orders holds everything about orders (module, controller, service, DTOs, entity, tests). Do not split the app into top-level controllers/ and services/ folders.
  • Controllers stay thin: they read the request, call a service and return. Business rules live in services, where unit tests can reach them without HTTP.
  • Every request body is a DTO class with class-validator rules, and a global ValidationPipe with whitelist on rejects anything else. Responses go through response DTOs so internal columns never leak.
  • Secure by default: the auth guard and throttler are global (APP_GUARD), routes opt out with @Public() and @SkipThrottle(), and app.useSecurityHeaders() (Nest 12.1) sets Helmet-style headers without an extra package.
  • Global setup lives in one configureApp() function used by main.ts and every e2e test, so tests exercise exactly what production runs.
  • TypeORM through @nestjs/typeorm, chosen because it is a Nest-maintained package and its repository injection fits Nest dependency injection and testing. Prisma is a fine alternative with its own docs chapter. The schema changes only through migrations committed to git; synchronize stays off.
  • Configuration comes from environment variables, read once through @nestjs/config and validated at startup, so a missing secret stops the app instead of a request.
  • Slow or flaky work (emails, webhooks) goes on a BullMQ queue, and enableShutdownHooks lets SIGTERM drain requests and workers before the process exits.
  • Add Expert tooling (contracts, mutation tests, boundaries, release automation) when a team and several consumers make it pay; Nest monorepo mode (apps/ and libs/) comes only with a second deployable app.

At the top of the project

Open one in the explorer for the full story

Learn more on Sefism

Roadmaps, cheat sheets and projects that go with NestJS.

See 9 more
Checked against 20 official sources, October 2026. If something has changed, the docs win.Show sources

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com