Production-ready Fastify starter template with TypeScript, Prisma, Docker, Prometheus, and the Golden Orchestrator pattern.
π Live Demo - See it in action with Swagger docs
One-click deployment - Great for demos and testing. Includes API + PostgreSQL only.
| Platform | Deploy Button | Time | Cost |
|---|---|---|---|
| Render β | 3 min | ~$7/mo | |
| Railway | 5 min | ~$5/mo |
Docker Compose on VPS - Complete stack with Grafana dashboards and monitoring.
# One command - full production setup
npm run generate:dashboards
docker compose -f docker/docker-compose.yml up -dβ
API + PostgreSQL + Prometheus + Grafana
β
Auto-generated dashboards work perfectly
β
~$5-10/mo on DigitalOcean, Hetzner, or Linode
π Full instructions: See DEPLOY.md for all deployment options
Production-ready Fastify template with best practices, type safety, and Prometheus metrics built-in.
| Feature | This Starter | NestJS | Express | Other Fastify |
|---|---|---|---|---|
| Pipeline Architecture | β Built-in | β None | β None | |
| Performance | β‘ Native Fastify | π’ Express under hood | π Express | β‘ Fastify |
| Type Safety | β Strict TypeScript | β Good | ||
| Metrics | β Prometheus built-in | β Basic | β Basic | |
| Docker | β Full stack |
Perfect for:
- Production APIs that need to scale
- Teams that value developer experience
- Projects that require strong type safety
- Fastify - High-performance web framework (4x faster than Express)
- TypeScript - Full type safety with strict mode
- Prisma - Type-safe database ORM with migrations
- PostgreSQL - Production database
- Docker - Full containerization
- Prometheus - Built-in metrics at
/metrics - Swagger - Auto-generated API documentation
- Golden Orchestrator Pattern - Pipeline-based business logic
- Singleton Services - Efficient resource management
- Pure Operations - Testable, composable functions
- Performance Tracking - Automatic metrics for every pipeline stage
- ESLint & Prettier - Consistent code formatting
- Husky - Pre-commit hooks
- Hot Reload - Fast development cycle with tsx
- TypeBox - Runtime validation with TypeScript types
- Swagger/OpenAPI - Auto-generated API documentation
- JWT Authentication - Secure auth flow
- Rate Limiting - DDoS protection
- CORS - Configurable cross-origin support
- Helmet - Security headers
- Health Checks - Kubernetes-ready endpoints
- Graceful Shutdown - Clean process termination
- Structured Logging - Pino with correlation IDs
- Environment Validation - Fail fast on missing config
fastify-gold-standard-starter/
βββ src/
β βββ core/
β β βββ orchestration/ # Golden orchestrator pattern
β β β βββ base-orchestrator.ts
β β β βββ performance-interceptor.ts
β β β βββ types.ts
β β βββ hooks/ # Fastify lifecycle hooks
β βββ plugins/ # Fastify plugins
β β βββ auth.ts # JWT authentication
β β βββ cors.ts # CORS configuration
β β βββ env.ts # Environment validation
β β βββ metrics.ts # Prometheus metrics
β β βββ prisma.ts # Database client
β β βββ swagger.ts # API documentation
β βββ routes/ # API endpoints
β β βββ health/ # Health checks
β β βββ auth/ # Authentication
β β βββ users/ # User management
β β βββ example/ # Example CRUD
β βββ services/ # Business logic
β β βββ todo/ # Example service
β β βββ orchestrator.ts # Pipeline orchestrator
β β βββ operations/ # Pure functions
β β βββ types/ # TypeScript types
β β βββ __tests__/ # Co-located tests
β β βββ index.ts # Service facade
β βββ utils/ # Utilities
β βββ app.ts # Fastify app setup
β βββ server.ts # Entry point
βββ prisma/
β βββ schema.prisma # Database schema
β βββ migrations/ # Database migrations
βββ docker/
β βββ docker-compose.yml # Local development
β βββ prometheus/ # Prometheus config
β βββ grafana/ # Grafana dashboards
βββ scripts/
β βββ generate-dashboards.ts # Auto-generate Grafana dashboards
βββ Makefile # Make commands for common tasks
βββ setup.sh # One-command setup script
βββ .github/
βββ workflows/
βββ ci.yml # CI/CD pipeline
- Node.js 18-20 LTS (Node 22+ may show dependency warnings)
- Docker & Docker Compose
- PostgreSQL (or use Docker)
Generate a complete service in 2 minutes!
npm run generate
? What do you want to generate? Service
? Service name: Order
? Operations: validate,process,notify
? Include Prisma model? Yes
? Include API route? Yes
? Include tests? Yes
β¨ Created 14 files with ~600 lines of production code!See docs/GETTING_STARTED.md for full details.
After generating services, automatically create Grafana dashboards:
npm run generate:dashboardsThis scans all orchestrators and generates performance monitoring dashboards automatically!
Pre-built dashboards included:
- System Overview - HTTP metrics, response times, error rates
- Per-Service Dashboards - Auto-generated from orchestrators
- Clone the template
git clone https://github.com/yourusername/fastify-gold-standard-starter.git
cd fastify-gold-standard-starter- Run setup script
./setup.shThe script automatically:
- β Installs dependencies
- β
Creates
.envfile - β Starts Docker services
- β Runs database migrations
- β Generates Grafana dashboards
- Start development server
npm run dev
# Or use make commands:
make devDone! Your API is now running at:
- API: http://localhost:3000/api/v1
- Swagger: http://localhost:3000/documentation
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3001 (admin/admin)
# Start everything (one command!)
make up # Starts Docker + runs migrations + generates dashboards
# Start dev server (in another terminal)
make dev
# Test the API (in another terminal)
make test-api # Automated tests with auth
# Open Grafana
make grafana
# Stop everything
make downLight up your monitoring in 3 steps:
# Terminal 1: Start API
npm run dev
# Terminal 2: Generate realistic traffic
npm run load-test
# Browser: Watch the magic
open http://localhost:3001The load tester will:
- β Authenticate automatically
- β Send randomized requests (realistic traffic patterns)
- β Respect rate limits (no 429 errors)
- β Display live stats (requests, latency, success rate)
Watch your dashboards update in real-time! All operations visible, all metrics accurate, zero configuration.
Public Routes (No Auth):
GET /api/v1/health- Health checkGET /api/v1/ready- Readiness probePOST /api/v1/auth/login- User loginPOST /api/v1/auth/register- User registration
Protected Routes (Auth Required):
GET /api/v1/users/me- Get current userPOST /api/v1/todos- Create todo (Golden Orchestrator pattern) βGET /api/v1/todos- List todosPOST /api/v1/examples- Create example (direct Prisma access)GET /api/v1/examples- List examples (direct Prisma access)
- docs/GETTING_STARTED.md - Setup, first service, commands
- docs/ARCHITECTURE.md - Golden Orchestrator pattern explained
Production-ready Fastify starter with TypeScript, Prisma, Docker, Prometheus & the Golden Orchestrator pattern. Includes CLI generator for instant service scaffolding.
fastify, typescript, starter-template, orchestrator-pattern,
prisma, docker, prometheus, grafana, cli-generator, production-ready
git clone your-repo-url
cd your-repo
./setup.sh
make up
make devThe Golden Orchestrator pattern provides a structured way to handle complex business logic through pipelines.
See docs/ARCHITECTURE.md for complete examples and deep dive.
// Define pipeline context
interface TodoPipelineContext extends OperationContext {
input: CreateTodoInput;
todo?: Todo;
}
// Create orchestrator
class CreateTodoOrchestrator extends BaseOrchestrator<
TodoPipelineContext,
Todo,
CreateTodoInput
> {
protected getPipeline(): PipelineStage<TodoPipelineContext>[] {
return [
{ name: 'validate-input', operation: validateInput, critical: true },
{ name: 'create-todo', operation: createTodo, critical: true },
{ name: 'notify-creation', operation: notifyCreation, critical: false },
];
}
}
// Pure operation function
async function createTodo(context: TodoPipelineContext): Promise<TodoPipelineContext> {
const todo = await prisma.todo.create({
data: context.input
});
context.todo = todo;
return context;
}- Testability: Each operation is a pure function
- Observability: Automatic performance tracking
- Composability: Reuse operations across orchestrators
- Reliability: Critical vs non-critical operations
- Maintainability: Clear separation of concerns
Generate beautiful Grafana dashboards in seconds!
npm run generate:dashboardsCreates production-ready dashboards with:
- β Avg Response Time, Success Rate, P95 Latency, Ops/min
- β Stacked area charts showing operation breakdown
- β Time-range aware sparklines
- β All metrics extracted automatically from your orchestrator code
See docs/AUTOMATIC_DASHBOARDS.md for details.
Simulate production traffic and watch your dashboards light up!
npm run load-testFeatures:
- β Rate-limit aware (respects 100 req/min limit)
- β Randomized traffic (Β±30% jitter for realistic patterns)
- β Authentication built-in
- β Configurable RPS and duration
- β Live stats display
# Custom load
RPS=2 DURATION=5 npm run load-test
# Disable randomization
RANDOMIZE=false npm run load-test- HTTP metrics: Request duration, count, status codes
- Orchestrator metrics: Pipeline duration, stage latency, success rate
- System metrics: Active connections, memory, CPU
- Custom metrics: Business-specific tracking
- System Overview: HTTP performance, P95 latency, error rates, requests/min
- Service Dashboards: Auto-generated per orchestrator with operation breakdown
- Time-range aware: All metrics adapt to selected time range
- Production-ready: 5-30s auto-refresh, proper sparklines
/health- Basic health check/ready- Readiness probe (checks DB connection)
# Run all tests
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run tests with UI
npm run test:ui# Build production image
docker build -t fastify-app .
# Run container
docker run -p 3000:3000 --env-file .env fastify-app# Build the application
npm run build
# Start with PM2
pm2 start dist/server.js --name fastify-appKey environment variables for production:
NODE_ENV=production
PORT=3000
DATABASE_URL=postgresql://user:pass@host:5432/db
JWT_SECRET=your-secret-key
RATE_LIMIT_MAX=100
CORS_ORIGIN=https://yourdomain.comnpm run dev # Start development server
npm run build # Build for production
npm run start # Start production server
npm run typecheck # TypeScript type checking
npm run lint # Run ESLint
npm run format # Format code with Prettier
npm run db:migrate # Run database migrations
npm run db:studio # Open Prisma Studio
npm run docker:up # Start Docker services
npm run docker:down # Stop Docker services- JWT-based authentication
- Rate limiting on all endpoints
- Input validation with TypeBox
- SQL injection protection via Prisma
- XSS protection with Helmet
- CORS properly configured
- Environment variables validation
Show that your project uses the Fastify Gold Standard! Add this badge to your README:
[](https://github.com/DriftOS/fastify-starter)Benefits:
- π Builds backlinks to help others discover this starter
- π Social proof shows you're using production-grade architecture
- π€ Supports the open-source community
Projects and companies using this starter:
- DriftOS - AI-powered branching memory system
- Your Project Here - Submit a PR to be featured!
Using this starter in production? We'd love to feature you! Submit a PR with your project.
Use the Orchestrator Pattern (TodoService) when:
- β Business logic has multiple steps
- β You need performance tracking per operation
- β Operations might fail independently (critical vs non-critical)
- β Logic will grow in complexity
- β You want automatic Grafana dashboards
Use Direct Access (ExampleService - being removed) when:
- β Simple CRUD operations
- β Single database query
- β No complex business logic
- β Performance tracking not needed
Note: The
/api/v1/examplesroutes demonstrate simple CRUD without orchestrators. These will be removed in v2.0. For production apps, we recommend the orchestrator pattern for all business logic to ensure consistent observability.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Fastify - Fast and low overhead web framework
- Prisma - Next-generation ORM
- TypeBox - JSON Schema Type Builder
For support, email hello@driftos.dev or open an issue in the repository.
Built with β€οΈ using the Fastify Gold Standard architecture