🐆 A boilerplate for server applications with Fastify and Mongo using TypeScript on Vite.
🌈 View Demo: Live | Windows | macOS | Android | iOS
Source Code: Web-side | Native-side | Server-side | Cloud-side
Prerequisites:
- Node.js v20
- PNPM v9
- Docker v4 (Optional)
Get started with Fastify Starter.
# (optional)
# If you already have the MONGODB_URL and REDIS_URL connections,
# you can directly replace them.
# mongo server
$ docker compose up -d local-mongo
# redis server
$ docker compose up -d local-redis
# install dependencies
$ pnpm install
# dev server (in one terminal)
$ pnpm dev
# (negligible)
# The current demo doesn't make any calls to third-party or internal APIs.
# mock server (in another terminal)
$ pnpm mock
Or use barebones scaffolding for your new Fastify app
$ pnpm dlx degit Shyam-Chen/Barebones-Templates/fastify my-fastify-app
Follow steps to execute this boilerplate.
$ pnpm install
$ pnpm dev
$ pnpm mock
$ pnpm build
# Before running the `preview` command, make sure to run the following commands.
$ pnpm build
$ pnpm preview
Files: **/*.{js,ts}
$ pnpm lint
Files: app/src/**/*.ts
$ pnpm check
Files: app/src/**/*.test.ts
$ pnpm test
Files: e2e/src/**/*.test.ts
# Before running the `e2e` command, make sure to run the following commands.
$ pnpm build
$ pnpm preview
$ pnpm e2e
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
- BullMQ - Message Queue
- WebSocket - Two-way Interactive Communication Session
- EventSource - Server-sent Events
- Mailer - Email Sending
- MJML - Email Builder
- Nunjucks - Email Rendering
- LangChain - Vector Embeddings
- OpenAI - Large Language Model
- MongoDB Vector Search - Vector Store
- ---------- Tools ----------
- Vite - Bundler
- TypeScript - JavaScript with Syntax for Types
- Biome - Formatter and Linter
- Vitest - Test Runner
- Playwright - Test Automation
- ---------- Environments ----------
- Node.js - JavaScript Runtime Environment
- PNPM - Package Manager
- Caddy - Web Server
- Docker - Containerized Application Development
- GitHub Actions - Continuous Integration and Delivery
- Render - Cloud Application Hosting
- Hello World
- CRUD Operations
- JWT Authentication
- One-time Password
- File Uploads
- Real-time Data
- Real-time Updates
- Sending Emails
- Internationalization
- Caching (Includes Redis Store)
- Cache Deduplication (Or use Redis Store)
- Background Workers (Or use Redis Store)
- Cron Jobs (Or use Redis Store)
- Delayed jobs (Or use Redis Store)
- Streaming LLM Output
- LLM Conversational Q&A Chatbot
Control the environment.
Set your local environment variables.
// app/vite.config.ts
define: envify({
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 || 'mongodb://root:rootpasswd@127.0.0.1:27017/mydb',
REDIS_URL: process.env.REDIS_URL || 'redis://127.0.0.1:6379',
CLOUDINARY_URL: process.env.CLOUDINARY_URL || 'cloudinary://apikey:apisecret@cloudname',
SMTP_URL: process.env.SMTP_URL || `smtp://${user}:${pass}@smtp.ethereal.email:587`,
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
SECRET_KEY: process.env.SECRET_KEY || 'jbmpHPLoaV8N0nEpuLxlpT95FYakMPiu',
MONGOMS_VERSION: process.env.MONGOMS_VERSION || '7.0.11',
}),
Add environment secrets to the GitHub Actions workflow.
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
OPENAI_API_KEY=xxx
The structure follows the LIFT Guidelines.
.
├── .github
├── app
│ ├── public
│ ├── src
│ │ ├── assets
│ │ ├── components
│ │ ├── composables
│ │ ├── jobs
│ │ ├── locales
│ │ ├── middleware
│ │ ├── plugins
│ │ ├── routes
│ │ ├── templates
│ │ ├── utilities
│ │ ├── app.ts
│ │ ├── main.ts
│ │ ├── shims.d.ts
│ │ └── worker.ts
│ ├── package.json
│ ├── tsconfig.json
│ └── vite.config.ts
├── db -> Set up local data for initializing and testing the database
│ ├── src
│ ├── mongo-init.js
│ └── package.json
├── e2e -> API End-to-end testing
│ ├── src
│ ├── package.json
│ ├── playwright.config.ts
│ └── tsconfig.json
├── mock -> Mocking third-party or private API calls
│ ├── src
│ ├── package.json
│ ├── tsconfig.json
│ └── vite.config.ts
├── .dockerignore
├── .editorconfig
├── .gitignore
├── biome.json
├── Caddyfile
├── compose.yaml
├── Dockerfile
├── package.json
├── pnpm-lock.yaml
├── pnpm-workspace.yaml
├── README.md
└── render.yaml