Overview
A minimal yet production-ready application built with BlueLibs Runner, Fastify, and MikroORM (PostgreSQL). This example includes:- Fastify HTTP Server with automatic route registration
- MikroORM with PostgreSQL database and migrations
- Authentication with HMAC-signed tokens (cookie or Bearer)
- Authorization Middleware with role-based access control
- Runner Dev Portal for live introspection and GraphQL API
- Health/Readiness Checks for Kubernetes deployments
- Swagger UI with auto-generated OpenAPI docs
- Comprehensive Test Suite with 100% coverage
Architecture
The application demonstrates a clean feature-based structure:What Runs Where
- Runner Dev Portal:
http://localhost:1337(GraphQL, Voyager, Docs) - Fastify HTTP Server:
http://localhost:3000 - Swagger UI:
http://localhost:3000/swagger - PostgreSQL Database: Local or Docker container
Key Code Snippets
HTTP Route Tag
Task with HTTP Endpoint
Fastify Context
MikroORM Entity
How to Run
Database Workflow
src/db/migrations/ and automatically compiled to dist/db/migrations/.
API Endpoints
| Method | Path | Auth | Description |
|---|---|---|---|
| GET | /users | Required + admin | List all users |
| POST | /auth/register | Public | Create account |
| POST | /auth/login | Public | Authenticate user |
| POST | /auth/logout | Public | Clear auth cookie |
| GET | /me | Required | Current user info |
| GET | /healthz | Public | Liveness probe |
| GET | /readyz | Public | DB readiness check |
What to Learn
1. HTTP Pattern with Tags
ThehttpRoute tag pattern separates HTTP concerns from business logic. Tasks remain framework-agnostic while the router handles all HTTP-specific details:
- Input transformation (
bodyvsmerged) - Auth enforcement (
public,optional,required) - Schema validation (Zod → Fastify schemas → OpenAPI)
- Error handling (HTTPError → HTTP status codes)
2. Request-Scoped Context
Fastify context provides request-scoped data without prop drilling:- Parsed authentication (cookie or Bearer token)
- Request-scoped logger with
requestId - Access to raw Fastify request/reply objects
3. Task Middleware
Middleware intercepts task execution for cross-cutting concerns:- Enforce authorization rules
- Log task execution
- Transform inputs
- Modify context
4. ORM Integration
MikroORM provides type-safe database access with migrations:5. Production Patterns
- Health checks:
/healthz(liveness),/readyz(DB connectivity) - Security: CORS, Helmet, HttpOnly cookies, HMAC tokens
- Observability: Request IDs, structured logging, access logs
- Error handling: Consistent error responses with proper HTTP codes
6. Test Utilities
The example includes helper functions for testing:Seeded Users
Fixtures create demo users (password:password):
- Ada Lovelace –
[email protected] - Alan Turing –
[email protected] - Grace Hopper –
[email protected]