FastAPI backend service for Nudge, providing authentication, classroom management, task assignment, real-time telemetry ingestion, Socratic tutoring, and pedagogical analytics.
The API powers the classroom orchestration and AI reasoning layer of Nudge:
- Authentication: Salted bcrypt password hashing with HS256 JWT bearer tokens and role-based permissions (
teacherandstudent). - Classrooms: Dynamic 8-character join codes, student enrollment, and teacher co-administration.
- Tasks & Drafts: Assignment creation, starter graph topology, test cases, and student draft state synchronization.
- Socratic Tutoring Engine: Two-stage pedagogical workflow (
question->unlock hint) preventing direct answer disclosure and enforcing reflective thinking. - Classroom Telemetry & Analytics: Event ingestion (
RUN_SUCCESS,RUN_ERROR), error clustering, and anonymous AI synthesis for lesson planning.
app/
├── api/
│ ├── routes/
│ │ ├── auth.py # Signup, login, JWT token generation
│ │ ├── classes.py # Classrooms, join codes, co-admins
│ │ ├── tasks.py # Problems, starter graphs, test cases
│ │ ├── tutor.py # Socratic questioning and hint unlocking
│ │ └── analytics.py # Classroom telemetry, error clustering, grading
├── core/
│ ├── config.py # Environment settings and JWT secrets
│ └── security.py # Password hashing and token validation
├── db/
│ └── session.py # Async SQLAlchemy engine with asyncpg
└── services/
└── llm.py # OpenAI client with bounded prompt contexts
Create a .env file in the project root:
DATABASE_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/nudge
JWT_SECRET_KEY=your-random-32-byte-hex-secret
CORS_ALLOWED_ORIGINS=["http://localhost:5173"]
# Optional: Required for Socratic AI tutor and analytics synthesis
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-minipip install -r requirements.txtApply database migrations sequentially against your PostgreSQL instance:
psql $DATABASE_URL -f migrations/001_class_admins.sql
psql $DATABASE_URL -f migrations/002_task_theory.sql
psql $DATABASE_URL -f migrations/003_local_password_auth.sql
psql $DATABASE_URL -f migrations/004_class_analytics_insights.sql
psql $DATABASE_URL -f migrations/005_student_analytics_grading.sql
psql $DATABASE_URL -f migrations/006_task_initial_nodes.sqluvicorn app.main:app --reload --port 5000Interactive OpenAPI documentation is accessible at http://localhost:5000/docs.
POST /auth/signup— Register with email, password, full name, and role (student|teacher).POST /auth/login— Returns user profile and short-lived JWT bearer token.
POST /classes— Create a classroom (generates 8-character join code).POST /classes/join— Enroll a student via join code.POST /classes/{class_id}/admins— Appoint a colleague teacher as co-admin.
POST /classes/{class_id}/tasks— Assign a new task with starter graph and test cases.GET /classes/{class_id}/tasks— List tasks configured for the classroom.POST /tasks/{task_id}/draft— Autosave student graph draft state.
POST /tasks/{task_id}/hints/question— Evaluates student's graph failure and returns a diagnostic guiding question.POST /tasks/{task_id}/hints/unlock— Validates student answer and unlocks conceptual hint without code dumping.GET /tasks/{task_id}/tutor-session— Retrieves historical question/answer dialogue.
POST /tasks/{task_id}/telemetry— Ingests live student run/error execution events.GET /classes/{class_id}/analytics— Aggregates error categories, completion rates, and AI pedagogical synthesis.PUT /classes/{class_id}/tasks/{task_id}/students/{student_id}/grade— Assign student grade (0–10) with written feedback.
Run automated unit and integration tests:
pytest -qRun local endpoint latency benchmarks:
python scripts/benchmark_api.py --endpoint class-tasks --class-id <uuid> --iterations 10Built for HackEPS 2026. Distributed under the MIT License.