https://github.com/jcserv/fastify-api-template
This template can be used to quickly bootstrap a Fastify API server
https://github.com/jcserv/fastify-api-template
Last synced: 11 days ago
JSON representation
This template can be used to quickly bootstrap a Fastify API server
- Host: GitHub
- URL: https://github.com/jcserv/fastify-api-template
- Owner: jcserv
- License: gpl-3.0
- Created: 2026-06-20T07:04:56.000Z (about 1 month ago)
- Default Branch: main
- Last Pushed: 2026-06-20T13:41:13.000Z (about 1 month ago)
- Last Synced: 2026-06-20T15:12:31.209Z (about 1 month ago)
- Language: TypeScript
- Homepage:
- Size: 102 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-api-template
A batteries-included template for spinning up a [Fastify](https://fastify.dev) API in TypeScript.
> Click **Use this template** on GitHub to bootstrap a new repo.
## Features
- ⚡ **Fastify 5** with typed routes via [`json-schema-to-ts`](https://github.com/ThomasAribart/json-schema-to-ts)
- 🦀 **oxlint + oxfmt** for fast linting and formatting
- 📦 **rolldown** for production bundling
- ✅ **vitest** for testing
- 🪝 **husky + lint-staged** pre-commit hooks (lint, typecheck, test)
- 🐳 **Docker + Docker Compose** (app + Postgres)
- 🔁 **GitHub Actions** CI (lint, typecheck, test, build, docker)
- 🛑 Graceful shutdown + structured logging (pino)
## Project structure
```
src/
app.ts # builds the Fastify instance (testable, no listen)
server.ts # boots app.ts, wires logging + graceful shutdown
config.ts # env-driven config
app.test.ts # example test using app.inject
routes/
index.ts # route definitions
types.ts # JSON schemas for typed request/response
```
## Getting started
```sh
cp .env.example .env
pnpm install
pnpm dev
```
Server runs at `http://localhost:3000`. Try `GET /health`.
## Scripts
| Command | Description |
| ----------------- | ------------------------------- |
| `pnpm dev` | Run with hot reload |
| `pnpm build` | Bundle to `dist/` with rolldown |
| `pnpm start` | Run the production build |
| `pnpm lint` | Lint + format check |
| `pnpm lint:fix` | Lint + format, applying fixes |
| `pnpm typecheck` | Typecheck (`tsc --noEmit`) |
| `pnpm test` | Run tests once |
| `pnpm test:watch` | Run tests in watch mode |
## Docker
```sh
docker compose up --build
```
Brings up the API and a Postgres instance. Configure via `.env`.
## Adding a route
1. Define the JSON schema in `src/routes/types.ts`.
2. Register the handler in `src/routes/index.ts` using `app.withTypeProvider()` for inferred types.
## License
ISC