A production-ready, feature-rich boilerplate for building robust and scalable APIs using Fastify and TypeScript. This starter kit comes with a pre-configured setup for authentication, database, testing, and more, allowing you to focus on writing your application logic.
- Framework: Fastify for high-performance, low-overhead web framework.
- Language: TypeScript for type safety and better developer experience.
- Authentication: Integrated with better-auth for easy implementation of various OAuth providers (Google, GitHub, Discord, etc.).
- Database ORM: Drizzle ORM for a modern, type-safe SQL query builder.
- API Layer: tRPC for building end-to-end typesafe APIs without schemas or code generation.
- Environment Variables: Configuration management using
@fastify/env
. - Linting & Formatting: ESLint and Prettier for consistent code style.
- Testing: Vitest for fast and reliable unit and integration testing.
- Containerization: Docker setup for development and production environments.
- CI/CD: Husky and lint-staged for pre-commit hooks.
git clone https://github.com/codersaadi/fastify
cd fastify
pnpm install
Copy the example environment file and update it with your configuration.
cp .env.example .env
docker-compose up -d
pnpm run db:migrate
pnpm run dev
The API will be available at http://localhost:3000
.
Script | Description |
---|---|
build |
Compiles the TypeScript code to JavaScript. |
dev |
Starts the development server with hot-reloading. |
start |
Starts the production server. |
lint |
Lints the codebase using ESLint. |
lint:fix |
Automatically fixes linting issues. |
format |
Formats the code using Prettier. |
format:check |
Checks for formatting issues. |
type-check |
Runs TypeScript compiler to check for type errors. |
test |
Runs tests using Vitest. |
test:watch |
Runs tests in watch mode. |
test:coverage |
Generates a test coverage report. |
db:generate |
Generates Drizzle ORM migration files. |
db:push |
Pushes schema changes to the database (without migrations). |
db:migrate |
Applies pending migrations to the database. |
db:drop |
Drops the database schema. |
/
├── conf/ # Nginx configuration
├── docker/ # Docker-related files
├── src/
│ ├── auth/ # Authentication providers and configuration
│ ├── config/ # Environment variable configuration
│ ├── db/ # Drizzle ORM schema, client, and migrations
│ ├── decorators/ # Fastify decorators
│ ├── hooks/ # Fastify hooks
│ ├── plugins/ # Fastify plugins (auth, db, tRPC, etc.)
│ ├── routers/ # API route definitions (trpc)
│ ├── schema/ # Reusable Zod schemas
│ ├── types/ # Global type definitions
│ └── utils/ # Utility functions
├── .env.example # Example environment variables
├── docker-compose.yaml # Docker Compose for development
├── Dockerfile # Dockerfile for production
└── package.json # Project dependencies and scripts
Authentication is handled by the better-auth
library, providing a simple way to integrate OAuth providers.
- Configuration:
src/auth/auth.config.ts
- Providers: Add or customize providers in
src/auth/providers/
. - Usage: The
auth
decorator can be used to protect routes.
API documentation is automatically generated using @fastify/swagger
. Once the server is running, you can access the Swagger UI at http://localhost:3000/documentation
.
This project is licensed under the MIT License. See the LICENSE file for details.