This PR implements four production features for the AstroML API: model registry with version rollback, batch fraud scoring scheduler, real-time WebSocket streaming, and JWT/API-key authentication with rate limiting.
These features are required for production deployment — managing model checkpoints safely, keeping fraud alerts up-to-date without manual scoring, powering the live dashboard, and securing all API endpoints.
- #237 Model Registry & Versioning — Mounted
/api/v1/modelsroutes; models register with{name}_v{timestamp}versioning, store checkpoints locally, and activation invalidates the scorer cache for rollback. - #238 Batch Scoring Scheduler — Fixed lifespan wiring to use the async session factory; scheduler scores active accounts every 5 minutes, writes to
api_fraud_alerts, purges alerts older than 90 days, and broadcasts new alerts over WebSocket. - #239 Real-time WebSocket Endpoint — Added
/api/v1/ws/transactionsand/api/v1/ws/alertswith token auth, 30s heartbeat ping/pong, per-connection rate limiting, and frontendsubscribeToIncomingTransactionsintegration. - #240 Authentication & API Keys — JWT login/refresh, API key generation with scoped permissions, auth middleware (401/429), and default admin seeding; auth disabled in test suite via
AUTH_ENABLED=false.
- Auth —
POST /api/v1/auth/loginwith{"username":"admin","password":"admin123"}→ receive JWT. Call/api/v1/fraud/alertswithout token → 401. - Model registry —
POST /api/v1/modelswith a.pthpath → 201.POST /api/v1/models/{id}/activate→ statusactive.GET /api/v1/models/{id}/metrics→ stored metrics. - Batch scheduler — Start API; wait 5 min (or set
BATCH_INTERVAL_SECONDS=10). Check logs for batch metrics and new rows inapi_fraud_alerts. - WebSocket — Connect to
ws://localhost:8000/api/v1/ws/transactions?token=<jwt>. Receive{"type":"transaction","data":{...}}messages. Sendpongin response toping. - Frontend — Open dashboard; real-time transaction chart should populate when new transactions arrive.
- Fraud alert schema unified on
api_fraud_alerts(risk_score,detected_atfields). Clients using the oldfraud_alertstable fields should migrate. - API endpoints require authentication when
AUTH_ENABLED=true(default). SetAUTH_ENABLED=falsefor local dev without tokens.
Closes Traqora#237 Closes Traqora#238 Closes Traqora#239 Closes Traqora#240
- Code builds successfully
- Tests added/updated
- No console errors
- Documentation updated (if needed)