Production backend for FieldTrack workforce operations.
This service is implemented with Fastify + TypeScript, Supabase (Postgres), Redis, and BullMQ workers.
The API provides multi-tenant endpoints for:
- authentication and identity (
/auth/*) - attendance and location tracking
- expenses and approvals
- admin dashboards, analytics, and operational tooling
- webhook and API key management
All tenant data access is scoped by organization_id derived from authenticated identity.
Core stack:
- Fastify 5 + TypeScript (ESM)
- Supabase Postgres clients (anon + service role)
- Redis + BullMQ
- OpenTelemetry + Prometheus metrics
- Zod validation
Runtime layout:
src/routes: route registration and system routessrc/modules: domain modules (auth, attendance, expenses, analytics, admin, etc.)src/middleware: auth and role guardssrc/db: tenant-scoped query helperssrc/workers: queue workers and scheduled jobs
Workers started by src/workers/startup.ts:
- distance worker
- analytics worker
- webhook worker
- snapshot worker
Scheduled jobs:
- snapshot reconciliation job (
reconcile_snapshot_tables()every 5 minutes) - retry-intent cleanup job
- JWT and API key auth (
Authorization: Bearer ...orX-API-Key) - strict role-based authorization (
ADMIN,EMPLOYEE) - attendance lifecycle (
check-inandcheck-out) with async post-processing - location ingest (single + batch)
- expense lifecycle with admin review and CSV export
- admin SSE stream at
/admin/events - queue/system/internal admin observability endpoints
Environment is validated by src/config/env.ts at startup.
Required baseline variables:
APP_ENVPORTSUPABASE_URLSUPABASE_ANON_KEYSUPABASE_SERVICE_ROLE_KEYSUPABASE_JWT_SECRETREDIS_URLAPI_BASE_URLAPP_BASE_URLCORS_ORIGIN
Common optional variables:
FRONTEND_BASE_URLMETRICS_SCRAPE_TOKENTEMPO_ENDPOINTWORKERS_ENABLED
Prerequisites:
- Node.js 24+
- npm
- Redis
- Supabase project
Commands:
npm install
npm run devUseful scripts:
npm run devnpm run buildnpm startnpm run typechecknpm run lintnpm test
System endpoints:
GET /GET /healthGET /readyGET /metricsGET /openapi.jsonGET /docs
Full endpoint contract and examples: docs/API_REFERENCE.md.
Production deploy is driven by GitHub Actions and scripts/deploy.sh.
High-level flow:
- CodeQL deep scan gate
- validate + tests
- docker build, vulnerability scan, push to GHCR
- VPS readiness check
- blue-green deploy
- health and smoke checks
- rollback on failure
Liveness gate is /health (not /ready).
See docs/DEPLOYMENT.md for detailed CI/CD and rollback behavior.
docs/API_REFERENCE.mddocs/ARCHITECTURE.mddocs/DEPLOYMENT.mddocs/ROLLBACK_SYSTEM.mddocs/env-contract.mddocs/infra-contract.md