Project Structure
A generated Nest project follows a predictable layout centered on src/ with a main.ts entry point.
When you run nest new, you get a predictable folder layout. Knowing what each file does removes the guesswork.
Key files
| File | Purpose |
|---|---|
src/main.ts | Entry point that bootstraps the app. |
src/app.module.ts | The root module. |
src/app.controller.ts | A sample controller. |
src/app.service.ts | A sample provider. |
test/ | End-to-end tests. |
nest-cli.json | CLI configuration. |
As your app grows you add one folder per feature (for example src/users/) containing that feature's module, controller, service, and DTOs.
Example
src/
main.ts # bootstrap
app.module.ts # root module
users/
users.module.ts
users.controller.ts
users.service.ts
dto/
create-user.dto.ts
test/
nest-cli.json
package.json
tsconfig.jsonWhen to use it
- A new engineer clones the repo and immediately understands that all application code lives under src/ and compiled output goes to dist/.
- A DevOps engineer configures the Docker image to copy only dist/ and node_modules, knowing src/ is not needed at runtime.
- A team enforces the convention that each feature gets its own subfolder under src/ mirroring the module name (e.g., src/orders/).
More examples
Default project layout
Shows the file tree produced by `nest new`, making every file's role predictable for any team member.
my-api/
βββ src/
β βββ app.controller.ts
β βββ app.module.ts
β βββ app.service.ts
β βββ main.ts
βββ test/
βββ tsconfig.json
βββ package.jsonFeature module subfolder
Illustrates the recommended co-location pattern where one feature owns its module, controller, service, DTOs, and entities.
src/
βββ users/
β βββ dto/
β β βββ create-user.dto.ts
β βββ entities/
β β βββ user.entity.ts
β βββ users.controller.ts
β βββ users.module.ts
β βββ users.service.ts
βββ app.module.tstsconfig decorator settings
Highlights the tsconfig settings NestJS requires: decorator support and the srcβdist compilation mapping.
{
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
}
}
Discussion