/nestjs-boilerplate

Nestjs boilerplate

Primary LanguageTypeScript

This project is in development

Introduction

Standards

This boilerplate borrows idea from shadcn/ui that you can copy and paste receipts into your project. This project includes some pre-configured parts that you basically need for every app (auth, orm, queue, email ...). That is you can own your code, just copy and paste then making the changes according to your needs.

From the docs:

Why copy/paste and not packaged as a dependency?

The idea behind this is to give you ownership and control over the code, allowing you to decide how the components are built and styled.

Start with some sensible defaults, then customize the components to your needs.

One of the drawback of packaging the components in an npm package is that the style is coupled with the implementation. The design of your components should be separate from their implementation.

Injection tokens

So instead of writing:

import { CACHE_MANAGER } from "@nestjs/cache-manager";
import { Cache } from "cache-manager";

constructor(@Inject(CACHE_MANAGER) private cache: Cache)

we can use the string base injection:

import { Cache } from "src/core/cache";

constructor(@Inject('cache') private cache: Cache)

It can reduce cognitive load IMO

String Usage
cache import { Cache } from "src/core/cache";

constructor(@Inject('cache') private cache: Cache)
db:sqlite import { DB } from "src/core/database-drizzle";

constructor(@Inject('db:sqlite') private db: DB['sqlite'])
db:mysql import { DB } from "src/core/database-drizzle";

constructor(@Inject('db:mysql') private db: DB['mysql'])
db:pgsql import { DB } from "src/core/database-drizzle";

constructor(@Inject('db:pgsql') private db: DB['pgsql'])
config import { Config } from "src/core/config";

constructor(@Inject('config') private config: Config)

Installation

$ pnpm install
$ cp .env.example .env

Then update your APP_KEY in .env

Running the app

# development
$ pnpm run start

# watch mode
$ pnpm run start:dev

# production mode
$ pnpm run start:prod

TODO

  • Mikro-ORM
  • Prisma (?)
  • Nodemailer
  • BullMQ
  • Zod validation
  • Refresh token
  • Rate limiter
  • Filesystem (local + s3)
  • GraphQL (?)
  • Logging (pino ?)