Overview
This example demonstrates a complete Express.js application showcasing the full power of BlueLibs Runner with:- Custom HTTP Tags for declarative route definitions
- Event-driven Architecture with automatic route registration
- Authentication using Passport and JWT
- SQLite Database with user management
- Context System for request-scoped data
- OpenAPI/Swagger documentation
- Comprehensive Integration Tests
Architecture
The application follows a clean, modular structure:- Resources: Database, Express server, user repository, HTTP route bridge
- Tasks: Register, login, profile, user listing endpoints
- Middleware: JWT authentication and user context setup
- Tags: HTTP route decoration with OpenAPI metadata
- Contexts: Request-scoped data (
UserContext,RequestContext)
Key Code Snippets
Custom HTTP Tag
Task with HTTP Tag
Event-Driven Route Registration
Context System
How to Run
API Endpoints
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| GET | /health | Health check | No |
| POST | /api/auth/register | Register new user | No |
| POST | /api/auth/login | User login | No |
| GET | /api/auth/profile | Get user profile | Yes |
| GET | /api/users | Get all users | Yes |
What to Learn
This example showcases several advanced Runner patterns:1. Declarative Route Definitions
Using tags to declare HTTP routes keeps your task definitions clean and declarative. The route configuration lives alongside the task, making it easy to see the full picture.2. Event-Driven Registration
By hooking intoglobals.events.ready, routes are automatically discovered and registered when the application starts. This eliminates manual route registration boilerplate.
3. Context for Request Scope
ThecreateContext API provides type-safe, request-scoped data without prop drilling. Authentication middleware sets up user context, which tasks can access anywhere in the call chain.
4. Separation of Concerns
- Tasks contain pure business logic
- Resources manage infrastructure (database, HTTP server)
- Middleware handles cross-cutting concerns (auth, logging)
- Tags provide metadata for framework features
5. Type Safety Throughout
Zod schemas provide runtime validation and compile-time types. OpenAPI docs are automatically generated from these schemas, ensuring your documentation stays in sync with your code.6. Testing Strategy
Integration tests demonstrate the complete authentication flow, from registration to protected route access, including validation and error handling.Environment Variables
JWT_SECRET: Secret key for JWT tokens (defaults to ‘your-secret-key’)PORT: The port for the Express HTTP server