github-actions[bot]
deploy: backend from 0338469
d66d64c
|
Raw History Blame Contribute Delete
2.14 kB
# backend/routes/
## Responsibility
FastAPI route modules expose tutoring, curriculum, assessment, teacher, admin, and operational HTTP APIs.
## Design
- Modules define `APIRouter` instances, Pydantic request/response models, endpoint handlers, and local request/auth validation.
- `main.py` imports and mounts the routers; `ROLE_POLICIES` in `backend/main.py` (referenced by symbol, never by line number) controls path/role authorization, with `resolve_required_roles` as the single enforcement point and `backend/tests/role_policy_expectations.py` as the executable contract.
- Handlers use domain services for reusable work, while some routes retain endpoint-specific orchestration and Firestore access.
- Representative routers: `rag_routes`, `ai_insight_routes`, `practice`, `curriculum_routes`, `class_records_router`, `admin_routes`.
## Flow
- `POST /api/rag/lesson` โ†’ `rag_routes` lesson handler โ†’ `rag.curriculum_rag` retrieval + inference client โ†’ Chroma curriculum collection / Claude.
- `POST /api/jev/verify` (teacher/admin only) โ†’ `jev_routes.verify_jev` โ†’ `services.jev_client.verify_lesson_factuality` โ†’ Claude Haiku structured-output judgment.
- `GET /api/curriculum/subjects` and `/subjects/{id}/topics` โ†’ `curriculum_routes` handlers โ†’ `services.curriculum_service` โ†’ Firestore.
- `POST /api/class-records/upload` and `/api/class-records/{uploadId}/ai-report` โ†’ `class_records_router` handlers โ†’ CSV/XLSX parsing, WRI and inference services โ†’ Firestore.
- `POST /api/admin/model-config/profile` โ†’ `admin_model_routes.switch_profile` โ†’ `services.inference_client` runtime profile update; admin handlers are role-guarded.
## Integration
- `main.app.include_router(...)` mounts these route modules and applies shared auth, Firebase startup, and role policy behavior.
- `services.*` owns reusable Firestore, Claude inference, WRI, analytics, email, and quiz operations; `rag.*` owns retrieval and ingestion.
- RAG-facing endpoints connect route validation/orchestration to Chroma retrieval and Claude generation; admin ingestion endpoints coordinate curriculum source files and ingestion.