🐆 A boilerplate for Node.js, Fastify, TypeScript, Vite, Playwright, and Render.
🌈 Live Demo - The client application is here.
- Getting Started
- Project Setup
- Key Features
- Configuration
- Directory Structure
- Microservices
- Containerization
Get started with Fastify Starter.
# dev server
$ pnpm install
$ pnpm dev
# mock server
$ cd mock/requests && pnpm install && cd ../..
$ pnpm mock
Follow steps to execute this boilerplate.
$ pnpm install
$ pnpm dev
$ pnpm build
# Before running the `preview` command, make sure to run the following commands.
$ pnpm build
$ pnpm preview
Files: src/**/*.ts
$ pnpm lint
Files: src/**/*.spec.ts
$ pnpm unit
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
Files: benchmark/**/*.spec.ts
# Before running the `bench` command, make sure to run the following commands.
$ pnpm build
$ pnpm preview
# If it's not installed, run it.
$ cd benchmark && pnpm install && cd ..
$ pnpm bench
# If it's not installed, run it.
$ cd mock/requests && pnpm install && cd ../..
$ pnpm mock
Files: docs/**/*.md
# If it's not installed, run it.
$ cd docs && pnpm install && cd ..
$ pnpm doc
This seed repository provides the following features:
- ---------- Essentials ----------
- Fastify - Web Application Framework
- Routes - File-based Routing
- 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
- Hello World
- CRUD Operations
- Authentication
- One-time Password
- File Uploads
- Real-time Data
- Real-time Updates
- Sending Emails
- Internationalization
- Background Workers
- Cron Jobs
- Caching
Control the environment.
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',
};
Add environment variables to the CircleCI build.
# production
DEPLOY_HOOK=xxx
# development
DEV_DEPLOY_HOOK=xxx
# staging
STAGE_DEPLOY_HOOK=xxx
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
The structure follows the LIFT Guidelines.
.
├── .circleci
├── benchmark -> load testing
├── docs -> api documentation
├── e2e -> e2e testing (Caddy Server proxy api and proxy mock api)
├── mock
│ ├── requests -> mock third-party 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
│ ├── plugins -> root module
│ ├── routes -> feature modules
│ ├── 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
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
services:
- type: web
name: node-app
runtime: docker
- type: web
name: caddy-server
runtime: docker