Advanced Nest.js boilerplate for scalable startups. This boilerplate is extended from ultimate-nestjs-boilerplate
- Nest.js with Fastify
- PostgreSQL with Prisma ORM
- Better Auth for complete authentication. Handles authentication kinds like email/password, OAuth, Magic Link, Pass Keys, Two-Factor Authentication, Session Management, etc. Learn More
- REST, GraphQL & WebSocket API
- Websocket using Socket.io via Redis Adapter(For future scalability with clusters)
- Swagger Documentation and API versioning for REST API
- Automatic API generation on the frontend using OpenAPI Codegen Learn More
- BullMQ for Queues. Bull board UI to inspect your jobs
- Worker server for processing background tasks like queues
- React Email for email template management. MailPit SMTP server for local email testing. Learn More
- Caching using Redis
- Pino for Logging
- Rate Limiter using Redis
- Graceful Shutdown
- Server & Database monitoring with Prometheus & Grafana Learn More
- Offset and Cursor based Pagination
- Local or Remote File Uploads (AWS S3)
- Sentry
- Testing with Jest
- Internationalization using i18n
- pnpm
- Docker: Dev & Prod ready from a single script Learn More
- Github Actions
- Commitlint & Husky
- SWC instead of Webpack
- Make
.envfiles ready:
cp ./.env.example ./.env
cp ./.env.docker.example ./.env.docker
- Start Docker containers:
pnpm docker:dev:up
- Run migrations:
docker exec -it nestjs-boilerplate-server sh
pnpm migration:up
Rolling our own auth is doable but maintaining all kinds of authentication types ourselves has been found out to be a challenging task. Moreover, rolling our own auth poses security risks. That's why this boilerplate uses Better Auth for everything related to authentication. All of the industry standard authentication kinds are ready to be used out of the box so that you focus on building features rather than worrying about auth shenanigans:
- Email/Password
- OAuth
- Magic Link
- Pass Keys
- Two Factor Authentication
- Role based Authentication & Authorization
- Session Management
You can find the frontend client setup here. You can find your auth API documentation by visiting /api/auth/reference

You can automatically generate and use all of your backend API in frontend in just one command, thanks to Swagger and OpenAPI spec. Running pnpm codegen on the frontend (example repo) will automatically generate all API's bootstrapped with Tanstack Query ready to be used with just one import. See complete example here

Prometheus & Grafana are available with Docker setup only. You might only need to monitor your server or database when the user base grows or when you want to debug some specific issues. That's why this step is completely optional. If you want to monitor your server or database, just enable monitoring profile in your .env i.e. COMPOSE_PROFILES=monitoring.
Database Monitoring Dashboard:

- Start container:
pnpm docker:dev:up
- Stop container:
pnpm docker:dev:down
- Start container:
pnpm docker:prod:up
- Stop container:
pnpm docker:prod:down
sh ./bin/deploy.sh
or run workflow .github/workflows/main.yml via GitHub Actions.
Let's face it, it is not practical to just create some random html email templates and inject your variables and send it to your clients. Your email templates must be checked for spam, CSS compatibility for different email clients, accessibility, responsiveness, etc. You need to make sure all these checks are passed so that your emails don't end up in spam folder. React Email is perfect fit for this. It uses React and provides many responsive email component blocks so that you can test all of the things mentioned earlier in your local development.
NOTE: We use React Email only in local development. We don't ship React and it's packages in production at all(you can see that all of the React packages are dev only). After our email templates have been created, we convert the .tsx files into static html files at build time and NodeMailer uses that html file from our backend. All of these things are handled automatically, you don't have to do any extra setup.
- React Email dev server: See all of your email templates in Web UI.
pnpm email:dev
- Build email templates(Handled): Convert
.tsxtemplates file into html(.hbs). This is already handled in post build (buildscript).
pnpm email: build
- Watch Email(Handled): Watch your
.tsxemail files insidetemplates/folder and convert them to html(.hbs). This is already handled when you run your Nest.js server (instart:devscript).
pnpm email:watch
In local you can easily test your email by using MailPit email client that ships with it's own SMTP server. The SMTP server will automatically run when you run your docker in development mode:
pnpm docker:dev:up
After that, just visit http://localhost:<DOCKER_MAIL_CLIENT_PORT>. You can find DOCKER_MAIL_CLIENT_PORT on .env.docker. By default, it will run on http://localhost:18025


