Run the automated setup script:
./setup.shThis will:
- ✅ Check Node.js version (requires 18+)
- ✅ Create
.envfile from template - ✅ Install all dependencies
- ✅ Generate Prisma client
- ✅ Start Docker services (PostgreSQL, Prometheus, Grafana)
- ✅ Run database migrations
- ✅ Generate Grafana dashboards
Then start the dev server:
npm run devThat's it! Your API is now running at:
- API: http://localhost:3000/api/v1
- Swagger: http://localhost:3000/documentation
- Metrics: http://localhost:3000/metrics
- Grafana: http://localhost:3001 (admin/admin)
If you prefer manual setup or the script doesn't work:
# 1. Install dependencies
npm install
# 2. Copy environment file
cp .env.example .env
# 3. Generate Prisma client
npx prisma generate
# 4. Start Docker services
npm run docker:up
# 5. Run migrations
npm run db:migrate
# 6. Start dev server
npm run devThe fastest way to create a new service with the Golden Orchestrator pattern:
npm run generate
? What do you want to generate? Service
? Service name: Order
? Service type: CRUD (entity management: users, orders, products)
? Operations: validate,create,notify
? Include Prisma model? Yes
? Include API route? Yes
? Include tests? Yes
✨ CRUD Service created successfully!
✓ Created 14 files (~600 lines)
✓ Complete with tests
✓ Ready in 2 minutes!The generator supports two service patterns:
| Type | Use Case | Default Operations | Prisma |
|---|---|---|---|
| CRUD | Entity management (users, orders, products) | validate, create, notify | ✅ Yes |
| Calculation | Compute operations (scoring, analysis, transforms) | validate, calculate, format | ❌ No |
For scripting or quick generation without prompts:
# CRUD service
node scripts/gen-service.mjs Order crud validate create notify
# Calculation service
node scripts/gen-service.mjs Scoring calculation validate calculate format
# Uses defaults if operations omitted
node scripts/gen-service.mjs User crudThis creates:
src/services/order/
├── index.ts # Service facade
├── orchestrator.ts # Pipeline orchestrator
├── types/index.ts # TypeScript types
├── operations/ # Pure functions
│ ├── validate.ts
│ ├── process.ts
│ └── notify.ts
└── __tests__/ # Co-located tests ⭐
├── operations/
│ ├── validate.test.ts
│ ├── process.test.ts
│ └── notify.test.ts
├── orchestrator.test.ts
└── integration.test.ts
src/routes/order/
└── index.ts # API routes
Edit the generated operations in src/services/order/operations/:
// src/services/order/operations/validate.ts
export async function validate(context: OrderPipelineContext) {
const errors: string[] = [];
// Add your validation logic
if (!context.input.customerId) {
errors.push('Customer ID required');
}
if (errors.length > 0) {
context.errors.push(new Error(`Validation: ${errors.join(', ')}`));
}
return context; // Always return context
}// src/services/order/types/index.ts
export interface CreateOrderInput {
customerId: string;
items: OrderItem[];
total: number;
}npm run db:migrate// src/app.ts
import orderRoutes from './routes/order/index';
// Add to API routes:
await fastify.register(orderRoutes, { prefix: '/orders' });npm test orderGET /api/v1/health- Health checkGET /api/v1/ready- Readiness probePOST /api/v1/auth/login- LoginPOST /api/v1/auth/register- Register
GET /api/v1/users/me- Get current userPOST /api/v1/todos- Create todo (uses Golden Orchestrator ⭐)GET /api/v1/todos- List todosPOST /api/v1/examples- Create example (direct Prisma access)GET /api/v1/examples- List examples
# Start everything (one command!)
make up # Starts Docker + migrations + dashboards
# Start dev server (in another terminal)
make dev
# Open Grafana
make grafana
# Stop everything
make down# Quick Start
make up # 🎯 Start everything
make dev # Start dev server
make grafana # Open Grafana
make down # Stop all services
# Testing
make test # Run all tests
make test-watch # Watch mode
make lint # Run linter
make typecheck # Type check
# Database
make db-migrate # Run migrations
make db-studio # Open Prisma Studio
make db-push # Push schema
make db-reset # Reset DB (WARNING)
# Generators
make generate # Generate service
make dashboards # Generate Grafana dashboards
# Cleanup
make clean # Clean build artifacts
make docker-clean # Remove volumes (WARNING)
# Help
make help # Show all commands# Development
npm run dev # Start dev server
npm run build # Build for production
# Database
npm run db:migrate # Run migrations
npm run db:studio # Open Prisma Studio
# Testing
npm test # Run all tests
npm run test:watch # Watch mode
npm run lint # Run linter
# Docker
npm run docker:up # Start services
npm run docker:down # Stop services
# Generator
npm run generate # Generate serviceRun the complete API test suite:
make test-apiThis tests:
- Health checks
- User registration & authentication
- Protected endpoints
- Todo creation (Golden Orchestrator)
- Performance metrics
Using Swagger UI:
http://localhost:3000/documentation
Using cURL:
# Login
curl -X POST http://localhost:3000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"test@example.com","password":"password123"}'
# Create Todo (with token)
curl -X POST http://localhost:3000/api/v1/todos \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"title":"Test","description":"Test todo","userId":"user-123"}'- ARCHITECTURE.md - Deep dive into the Golden Orchestrator pattern
- ../README.md - Main repository README
The best way to learn is by studying the included example:
src/services/todo/
├── index.ts # Service facade (singleton)
├── orchestrator.ts # Pipeline orchestrator
├── types/index.ts # TypeScript interfaces
├── operations/ # Pure functions
│ ├── validate-input.ts # Operation 1
│ ├── create-todo.ts # Operation 2
│ └── notify-creation.ts # Operation 3
└── __tests__/ # Tests
Key concepts demonstrated:
- Pipeline-based orchestration
- Pure operation functions
- Automatic performance tracking
- Error handling
- Testing patterns
Study this service, then use npm run generate to create your own!
npm install
npm run typechecknpm run docker:up
# Wait for PostgreSQL to be ready
npm run db:migrate# Change PORT in .env file
PORT=3001 npm run devnpm run typecheck
# Fix errors shownGenerate a basic service first, understand the pattern, then add complexity.
Not everything needs the orchestrator pattern. Simple database queries can use direct Prisma access (see /examples route).
Every generated service includes complete tests. Implement the TODOs and you're done!
Every orchestrator automatically tracks per-operation performance. Check Grafana!
Changes to TypeScript files automatically reload the server.
- ✅ Run
npm run generate - ✅ Create your first service
- ✅ Implement the operations
- ✅ Run tests
- ✅ Start building!
Happy coding! 🚀