A modern NestJS project structure with best practices using Fastify, Prisma, MongoDB, and SWC.
- Framework: NestJS 10.x with Fastify
- Database: MongoDB with Prisma ORM
- Compiler: SWC for TypeScript
- Package Manager: pnpm
- Authentication: JWT with Passport
- Documentation: Swagger/OpenAPI
- Validation: class-validator with DTOs
- Logging: Pino for structured logging
- Testing: Jest
- Linting: ESLint with TypeScript rules (inspired by brocoders/nestjs-boilerplate)
- Modular architecture with proper separation of concerns
- Global exception handling and request/response transformation
- Database integration with Prisma ORM
- Structured logging
- API documentation with Swagger
- Configuration management with validation
- Authentication and authorization
- Unit and e2e testing setup
- Performance optimized with Fastify and SWC
├── prisma/ # Prisma ORM schema and migrations
├── src/
│ ├── config/ # Environment configuration
│ │ ├── envs/ # Environment-specific configs
│ │ └── interfaces/ # Configuration interfaces
│ ├── common/ # Global Nest modules
│ │ ├── constants/ # Constant values and enums
│ │ ├── controllers/ # Common controllers
│ │ ├── decorators/ # Custom decorators
│ │ ├── dto/ # Data Transfer Objects
│ │ ├── filters/ # Exception filters
│ │ ├── guards/ # Route guards
│ │ ├── interceptors/ # Request/response interceptors
│ │ ├── interfaces/ # TypeScript interfaces
│ │ ├── middleware/ # HTTP middleware
│ │ ├── pipes/ # Validation pipes
│ │ └── providers/ # Common providers
│ ├── core/ # Core modules (auth, database, etc.)
│ ├── modules/ # Feature modules
│ │ └── users/ # Example feature module
│ │ ├── controllers/
│ │ ├── services/
│ │ ├── dto/
│ │ └── entities/
│ ├── prisma/ # Prisma service
│ ├── shared/ # Shared modules
│ ├── app.module.ts # Root application module
│ └── main.ts # Application entry point
└── test/ # End-to-end tests
- Clone the repository
- Install dependencies:
pnpm install- Set up environment variables:
cp .env.sample .env
# Edit .env with your configuration- Generate Prisma client:
pnpm prisma:generate- Seed the database (optional):
pnpm db:seedDevelopment mode:
pnpm start:devProduction mode:
pnpm build
pnpm start:prodLinting code:
# Check for ESLint errors
pnpm lint:check
# Fix ESLint errors automatically
pnpm lintNote: ESLint configuration is inspired by brocoders/nestjs-boilerplate
Formatting code:
pnpm formatRunning unit tests:
pnpm testRunning e2e tests:
pnpm test:e2eAPI documentation is available at /docs when the application is running. It provides an interactive interface to explore and test the API endpoints.