Skip to content

About

FastAPI backend service for low-code programming environment Nudge.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

27 Commits

Folders and files

Repository files navigation

Nudge API

FastAPI backend service for Nudge, providing authentication, classroom management, task assignment, real-time telemetry ingestion, Socratic tutoring, and pedagogical analytics.


Overview

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 (teacher and student).
  • 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.

Architecture

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

Quickstart

1. Environment Setup

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-mini

2. Install Dependencies

pip install -r requirements.txt

3. Database Migrations

Apply 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.sql

4. Run the Server

uvicorn app.main:app --reload --port 5000

Interactive OpenAPI documentation is accessible at http://localhost:5000/docs.


Core API Endpoints

Authentication

  • 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.

Classroom Management

  • 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.

Tasks & Graphs

  • 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.

Socratic AI Tutoring

  • 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.

Classroom Analytics & Grading

  • 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.

Testing & Benchmarks

Run automated unit and integration tests:

pytest -q

Run local endpoint latency benchmarks:

python scripts/benchmark_api.py --endpoint class-tasks --class-id <uuid> --iterations 10

License

Built for HackEPS 2026. Distributed under the MIT License.

About

FastAPI backend service for low-code programming environment Nudge.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages