Skip to content

πŸ† A boilerplate for Node.js, Fastify, TypeScript, Vite, Vitest, and Render. I18n | MongoDB | JWT | OTP | Redis | Cloudinary | WebSocket | EventSource | Nodemailer | BullMQ | ESLint | Prettier | Playwright | SuperTest | AutoCannon | Pnpm | PM2 | Caddy | Docker | CircleCI | TypeBox

License

Notifications You must be signed in to change notification settings

mlokhandwala/Fastify-Starter

Β 
Β 

Repository files navigation

Fastify Starter

πŸ† A boilerplate for Node.js, Fastify, TypeScript, Vite, Playwright, and Render.

🌈 Live Demo - The client application is here.

Table of Contents

Getting Started

Get started with Fastify Starter.

# dev server
$ pnpm install
$ pnpm dev

# mock server
$ cd mock/requests && pnpm install && cd ../..
$ pnpm mock

Project Setup

Follow steps to execute this boilerplate.

Install dependencies

$ pnpm install

Compiles and hot-reloads for development

$ pnpm dev

Compiles and minifies for production

$ pnpm build

Lints and fixes files

Files: src/**/*.ts

$ pnpm lint

Runs unit tests

Files: src/**/*.spec.ts

$ pnpm unit

Runs end-to-end tests

Files: e2e/**/*.spec.ts

# Before running the `e2e` command, make sure to run the following commands.
$ pnpm build
$ pnpm preview

# If it's not installed, run it.
$ cd e2e && pnpm install && cd ..

$ pnpm e2e

Performance metrics

Files: benchmark/**/*.spec.ts

# If it's not installed, run it.
$ cd benchmark && pnpm install && cd ..

$ pnpm bench

Mock requests

# If it's not installed, run it.
$ cd mock/requests && pnpm install && cd ../..

$ pnpm mock

Documentation

Files: docs/**/*.md

# If it's not installed, run it.
$ cd docs && pnpm install && cd ..

$ pnpm doc

Key Features

This seed repository provides the following features:

  • ---------- Essentials ----------
  • Fastify - Web Application Framework
  • MongoDB - Document Database
  • JWT - Authentication
  • PBKDF2 - Hash Passwords
  • OTP - Authenticator
  • Cloudinary - Asset Management
  • I18n - Internationalization and Localization
  • Redis - In-memory Data Structure Store
  • WebSocket - Two-way Interactive Communication Session
  • EventSource - Server-sent Events
  • Mailer - Email Sending
  • Email - Email Builder
  • Nunjucks - Email Rendering
  • Sheets - Spreadsheet Data Toolkit
  • BullMQ - Message Queue
  • ---------- Tools ----------
  • Vite - Bundler
  • TypeScript - JavaScript with Syntax for Types
  • ESLint - Linter
  • Prettier - Formatter
  • Vitest - Test Runner
  • Playwright - Test Automation
  • Autocannon - Measure Performance
  • VitePress - Documentation
  • ---------- Environments ----------
  • Node.js - JavaScript Runtime Environment
  • Pnpm - Package Manager
  • PM2 - Process Manager
  • Caddy - Web Server
  • Docker - Containerized Application Development
  • CircleCI - Continuous Integration and Delivery
  • Render - Cloud Application Hosting

Configuration

Control the environment.

Default environments

Set your local environment variables.

// env.ts
export default {
  NODE_ENV: process.env.NODE_ENV || 'development',

  HOST: process.env.HOST || '127.0.0.1',
  PORT: process.env.PORT || 3000,

  SITE_URL: process.env.SITE_URL || 'http://127.0.0.1:5173',

  MONGODB_URL: process.env.MONGODB_URL || 'xxx',
  REDIS_URL: process.env.REDIS_URL || 'xxx',
  CLOUDINARY_URL: process.env.CLOUDINARY_URL || 'xxx',
  SMTP_URL: process.env.SMTP_URL || 'xxx',

  SECRET_KEY: process.env.SECRET_KEY || 'xxx',
};

Continuous integration environments

Add environment variables to the CircleCI build.

# production
DEPLOY_HOOK=xxx

# development
DEV_DEPLOY_HOOK=xxx

# staging
STAGE_DEPLOY_HOOK=xxx

Continuous delivery environments

Add environment variables to the Render build.

SITE_URL=xxx

MONGODB_URL=xxx
REDIS_URL=xxx
CLOUDINARY_URL=xxx
SMTP_URL=xxx

SECRET_KEY=xxx

Directory Structure

The structure follows the LIFT Guidelines.

.
β”œβ”€β”€ .circleci
β”œβ”€β”€ benchmark
β”œβ”€β”€ docs
β”œβ”€β”€ e2e -> e2e testing (Caddy Server proxy api and proxy mock api)
β”œβ”€β”€ mock
β”‚   β”œβ”€β”€ requests -> mock api
β”‚   └── responses -> mock data for mock api, unit testing, and e2e testing
β”œβ”€β”€ public -> not handled by vite, copy it to dist
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ assets -> wasm
β”‚   β”œβ”€β”€ components -> shared module
β”‚   β”œβ”€β”€ composables -> shared module
β”‚   β”œβ”€β”€ locales -> core module
β”‚   β”œβ”€β”€ middleware -> core module
β”‚   β”œβ”€β”€ modules -> feature modules
β”‚   β”‚   └── <FEATURE> -> feature module
β”‚   β”‚       β”œβ”€β”€ __tests__ -> unit testing
β”‚   β”‚       β”œβ”€β”€ _locales
β”‚   β”‚       β”œβ”€β”€ controller.ts
β”‚   β”‚       β”œβ”€β”€ registry.ts -> route component
β”‚   β”‚       β”œβ”€β”€ schema.ts
β”‚   β”‚       β”œβ”€β”€ service.ts
β”‚   β”‚       └── types.ts
β”‚   β”œβ”€β”€ plugins -> root module
β”‚   β”œβ”€β”€ templates -> email templates with nunjucks
β”‚   β”œβ”€β”€ utilities -> shared module
β”‚   β”œβ”€β”€ app.ts
β”‚   β”œβ”€β”€ error.ts
β”‚   β”œβ”€β”€ main.ts
β”‚   └── shims.d.ts
β”œβ”€β”€ .editorconfig
β”œβ”€β”€ .eslintrc
β”œβ”€β”€ .gitignore
β”œβ”€β”€ .prettierrc
β”œβ”€β”€ Caddyfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ env.ts
β”œβ”€β”€ index.ts -> entrypoint
β”œβ”€β”€ LICENSE
β”œβ”€β”€ package.json
β”œβ”€β”€ pnpm-lock.yaml
β”œβ”€β”€ README.md
β”œβ”€β”€ render.yaml
β”œβ”€β”€ tsconfig.json
└── vite.config.ts

Microservices

A microservice architecture – a variant of the service-oriented architecture structural style – is an architectural pattern that arranges an application as a collection of loosely-coupled, fine-grained services, communicating through lightweight protocols.

See Micro-Fullstack's Micro Backends for instructions on how to create microservices from source code.

api.example.com
β”œβ”€β”€ /auth
β”‚   └── auth.api.example.com
β”œβ”€β”€ /stats
β”‚   └── stats.api.example.com
β”œβ”€β”€ /todoist
β”‚   └── todoist.api.example.com
β”œβ”€β”€ /feature
β”‚   └── feature.api.example.com
β”œβ”€β”€ /files
β”‚   └── files.api.example.com
└── /settings
    └── settings.api.example.com

About

πŸ† A boilerplate for Node.js, Fastify, TypeScript, Vite, Vitest, and Render. I18n | MongoDB | JWT | OTP | Redis | Cloudinary | WebSocket | EventSource | Nodemailer | BullMQ | ESLint | Prettier | Playwright | SuperTest | AutoCannon | Pnpm | PM2 | Caddy | Docker | CircleCI | TypeBox

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 89.4%
  • HTML 9.1%
  • Dockerfile 1.5%