| 03-api-layer |
01 |
api |
| express |
| firebase-auth |
| typescript |
| postgres |
| admin-routes |
|
| phase |
provides |
| 02-backend-services |
HealthCheckModel.findLatestByService, AlertEventModel.findActive/acknowledge, document_processing_events table |
|
| phase |
provides |
| 01-data-foundation |
service_health_checks, alert_events, document_processing_events tables and models |
|
|
| requireAdminEmail middleware (404 for non-admin, next() for admin) |
| getAnalyticsSummary() aggregate query function with configurable time range |
| GET /admin/health — latest health check for all four monitored services |
| GET /admin/analytics — processing summary with uploads/success/failure/avg-time |
| GET /admin/alerts — active alert events |
| POST /admin/alerts/:id/acknowledge — mark alert acknowledged |
|
| 04-frontend |
| consumes all four admin endpoints for admin dashboard |
|
|
| added |
patterns |
|
|
| Admin routes use router-level middleware chain (addCorrelationId + verifyFirebaseToken + requireAdminEmail) |
| requireAdminEmail reads env vars inside function body (Firebase Secrets timing) |
| Fail-closed pattern |
| if no admin email configured, deny all with logged warning |
|
| getPostgresPool() for aggregate SQL (Supabase JS client does not support COUNT/AVG) |
| PostgreSQL parameterized interval with $1::interval explicit cast |
| Response envelope { success, data, correlationId } on all admin endpoints |
|
|
| created |
modified |
| backend/src/middleware/requireAdmin.ts |
| backend/src/routes/admin.ts |
|
| backend/src/services/analyticsService.ts |
| backend/src/index.ts |
|
|
| requireAdminEmail returns 404 (not 403) for non-admin users — does not reveal admin routes exist |
| Env vars read inside function body, not module level — Firebase Secrets not available at module load time |
| getPostgresPool() used for aggregate SQL (COUNT/AVG) — Supabase JS client does not support these operations |
| Service names in health endpoint hardcoded to match healthProbeService: document_ai, llm_api, supabase, firebase_auth |
|
| Admin auth chain: addCorrelationId → verifyFirebaseToken → requireAdminEmail (router-level, applied once) |
| Admin 404 pattern: non-admin users and unconfigured admin get 404 to obscure admin surface |
|
|
8min |
2026-02-24 |