A production-ready Fastify application built with clean architecture principles, featuring Bun runtime, Drizzle ORM, Redis caching, and BullMQ job queues.
- Fastify Framework - High-performance web framework
- Bun Runtime - Fast JavaScript runtime with built-in bundler
- Drizzle ORM - Type-safe SQL ORM with PostgreSQL
- Redis - In-memory caching and session storage
- BullMQ - Robust queue system for background jobs
- ClickHouse - Analytics database support
- JWT Authentication - Secure token-based authentication
- Role-Based Access Control (RBAC) - Permission management system
- TypeScript - Full type safety
- Clean Architecture - Organized, maintainable codebase
- Bun >= 1.0
- PostgreSQL >= 14
- Redis >= 7
- ClickHouse (optional)
bun installCopy the example environment file and configure it:
cp .env.example .envEdit .env with your configuration:
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/your_database"
REDIS_HOST="localhost"
REDIS_PORT=6379
APP_SECRET="your-secret-key"
APP_JWT_SECRET="your-jwt-secret"# Generate migration files
make db-generate
# Run migrations
make db-migrate
# Or push schema directly (development only)
make db-push
# Run seeders
make db-seedStart the development server:
# Start both server and worker
make dev
# Start API server only
make dev-server
# Start worker only
make dev-workerThe API will be available at http://localhost:8001
src/
├── app.ts # Fastify app initialization
├── serve.ts # Server entry point
├── bull/ # Queue jobs and workers
│ ├── queue/ # Job queue definitions
│ └── worker/ # Job processors
├── libs/ # Shared libraries
│ ├── cache/ # Redis cache utilities
│ ├── config/ # Configuration files
│ ├── database/ # Database setup and migrations
│ │ ├── postgres/ # PostgreSQL with Drizzle
│ │ ├── clickhouse/ # ClickHouse setup
│ │ └── seed/ # Database seeders
│ ├── fastify/ # Fastify plugins and utilities
│ │ ├── plugins/ # Custom plugins
│ │ ├── error/ # Error handlers
│ │ └── di/ # Dependency injection
│ ├── mail/ # Email service
│ ├── types/ # TypeScript types
│ └── utils/ # Utility functions
├── routes/ # API route handlers
│ ├── auth/ # Authentication routes
│ ├── profile/ # User profile routes
│ └── settings/ # Settings routes
└── services/ # Business logic layer
make dev # Start server and worker with hot reload
make dev-server # Start server only with hot reload
make dev-worker # Start worker only with hot reloadmake build # Build the application
make start # Start server and worker
make start-server # Start production server only
make start-worker # Start production worker onlymake lint # Run ESLint
make format # Format code with Prettier
bun run typecheck # Run TypeScript type checkingmake db-generate # Generate migration files from schema
make db-migrate # Run pending migrations
make db-push # Push schema to database (dev only)
make db-pull # Pull schema from database
make db-studio # Open Drizzle Studio UI
make db-drop # Drop all tables (dangerous!)
make db-seed # Run database seedersmake db-clickhouse-migrate # Run ClickHouse migrations
make db-clickhouse-status # Check migration statusmake fresh # Drop, push schema, and seed
make reset # Generate, migrate, and seedOnce the server is running, visit:
- Swagger UI:
http://localhost:8001/documentation - Scalar API Reference:
http://localhost:8001/reference
The application uses JWT-based authentication:
- Register:
POST /auth/register - Login:
POST /auth/login - Use returned token in Authorization header:
Bearer <token>
| Variable | Description | Default |
|---|---|---|
APP_PORT |
Server port | 8001 |
APP_HOST |
Server host | localhost |
APP_ENV |
Environment | development |
DATABASE_URL |
PostgreSQL connection string | - |
REDIS_HOST |
Redis host | localhost |
REDIS_PORT |
Redis port | 6379 |
APP_JWT_SECRET |
JWT signing secret | - |
APP_SECRET |
Application secret key | - |
Run the test suite:
bun testThe project includes GitHub Actions workflow for:
- Linting
- Building server and worker
- Running database migrations
- Running seeders
- Follow the existing code structure
- Use TypeScript strict mode
- Write meaningful commit messages
- Ensure all tests pass before submitting PR
See LICENSE file for details.