rubiin/ultimate-nest
À propos
Starter template with blog clone as project
Développement web et applicatifProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- -1
- in 15 days
- -2
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalBlog made using Nestjs + Mikro-orm codebase(backend) containing real world examples (CRUD, auth (password based and oauth), advanced patterns, etc) and batteries included and ever-evolving
NOTE: Starting April 18,2022 , the repo has ditched most promises for observables. You can check the latest promised version code at commit
More on why observables are better than promises can be read here
Table of Contents
- What's included
- Prerequisites
- Getting started
- Scripts
- Configuration
- Project structure
- Authentication
- Deployment
- Documentation
What's included
- 📱 NestJS and 🎉 TypeScript
- 🏪 MikroORM on 🐘 PostgreSQL, with migrations and seeders
- 🗝 Authentication with JWT access and refresh tokens, OAuth (Google, Facebook), 2FA (TOTP), email verification and session management
- 🏬 Authorization - RBAC with CASL
- 🐇 RabbitMQ for background jobs and 🧠 Redis for caching
- 📧 Mail with templates (SMTP or SES), 💬 Twilio and Firebase config, Cloudinary and Minio uploads, Stripe webhooks
- 🛡️ Resilience — timeouts, circuit breakers, bulkheads and fallbacks around Cloudinary, mail and RabbitMQ
- 🌐 I18n, 📃 Swagger API docs and 🧵 swagger-stats metrics
- ⚙️ Config validated at startup with Zod, one file per integration
- 📏 Oxlint and Oxfmt, 🧪 Vitest, 🐺 Husky git hooks
- 🐳 Docker Compose for deployment
Prerequisites
- Node.js
24.22.0or newer (see.nvmrc) - pnpm, the repo uses
pnpm-lock.yamlso npm and yarn are not supported - Docker, for local PostgreSQL, Redis, RabbitMQ and a mail catcher
- Optional: just for the shortcuts in
justfile
Getting started
npx degit rubiin/ultimate-nest my-nest-app # or use the "Use this template" button
cd my-nest-app
pnpm install
cp env/.env.sample env/.env.dev
Then start the backing services, run migrations, seed and start the app. The full walkthrough is in docs/getting-started.md.
Once running, Swagger is at http://localhost:3000/doc and the metrics dashboard at
http://localhost:3000/stats, which asks for SWAGGER_USER and SWAGGER_PASSWORD from the env file.
Scripts
Every script needs NODE_ENV (dev, prod, test or stage), which selects env/.env.<NODE_ENV>.
| Command | What |
|---|---|
pnpm start:dev |
Start in watch mode |
pnpm build / pnpm start:prod |
Compile to dist/, run the build |
pnpm start:hmr |
Start with hot module replacement |
pnpm test / pnpm test:cov |
Unit specs, with coverage |
pnpm test:e2e |
E2E specs in test/, needs the services running |
pnpm lint / pnpm format:check |
oxlint and oxfmt |
pnpm orm migration:create |
Generate a migration from entity changes |
pnpm orm migration:up / :down |
Apply or roll back migrations |
pnpm orm seeder:run |
Run the seeders in src/common/database/seeders |
The ORM CLI reads compiled entities from dist/, so run pnpm build first. justfile wraps these, for
example just migrate, just seed and just encryption. Run just to list them.
Configuration
Each integration has its own file in src/lib/config/configs with a Zod schema and a registerAs block, and
src/lib/config/config.module.ts loads them. Every variable is validated at startup, and the app refuses to
boot on a missing or malformed one. env/.env.sample lists every variable with a working local value, and
env/.env.<NODE_ENV> is the copy you run against. A blank value is not the same as an absent one: optional
integrations (Stripe, Sentry, Twilio, Minio, S3) reject a blank so a half-configured integration fails loudly
instead of silently doing nothing.
To drop an integration you do not need (for example Redis or Twilio), remove its config from
config.module.ts, its schema from config.validation.ts, and its variables from your env file. See
docs/config.md.
Project structure
ultimate-nest
├── env Env files: .env.sample (committed template), .env.<NODE_ENV> (yours, copy of it)
├── migrations MikroORM migrations
├── docs Guides, start with getting-started.md
├── test End to end specs
├── src
│ ├── main.ts Entry point
│ ├── common Shared code: database base classes, decorators, guards, pipes, DTOs, types
│ ├── entities MikroORM entities
│ ├── lib Standalone modules: config, mail, i18n, jwt, cache, casl, rabbit, ...
│ ├── modules Feature modules: auth, user, post, newsletter, chat, ...
│ ├── resources Static files: i18n, mail templates
│ └── _mocks_ Shared mocks for unit tests
└── dist Build output
A feature module in src/modules/<name> holds its controller, service, module, dto folder and colocated
*.spec.ts files.
Authentication
The API uses JSON Web Tokens. Send the access token on each request in the header
Authorization: Bearer <token>. Refresh tokens are single-use and rotated on POST /v1/auth/token/refresh,
and GET /v1/auth/sessions lists the devices a user is logged in on.
Deployment
scripts/deploy.sh drives the local stack in docker-compose.dev.yml: the app plus Postgres, Redis,
RabbitMQ and Mailpit. The app container builds, migrates and seeds itself on boot. ENV picks the env
file, dev by default.
./scripts/deploy.sh # start the stack, reusing the image already built
./scripts/deploy.sh build # rebuild the image, then start the stack detached
./scripts/deploy.sh logs # follow the build, migrate and seed output
./scripts/deploy.sh down # stop the stack, keeping the volumes
The source is baked into the image rather than mounted, so a code change needs build.
./scripts/deploy.sh services starts only the backing services, for running the app on the host.
docker-compose.yml is the production-style stack (Traefik, TLS, pgAdmin). It runs the dev image with
the source mounted and no migrate step, so it is not production ready.
Documentation
More guides are in docs/: getting started, config,
database, testing, logging,
resilience, decorators, linting,
timezone and naming.
Do you use this template?
Don't be shy to give it a star! ★
Support
Also if you are into NestJS ecosystem you may be interested in one of my other libs:
A collection of helper functions for typescrip development. It includes functions for array,object,string,etc
Platform config manager for nestjs. It supports multiple config files and environment variables.
This is a minio module for Nest.
This is a cloudinary module for Nest.
A Module for Utilizing Pg-promise with NestJS
Star History
Made with ❤️ with opensource.
Explorer des projets similaires
Chargement…

