How abhay-ugale-25/proctor-sandbox works
Purpose and Entry Points
This is a FastAPI backend for proctored coding assessments: it judges untrusted multi-language submissions in Docker and records webcam-derived proctoring anomalies. The API starts at main.py; the independent webcam/MediaPipe process starts at app/ml_engine/main.py.
API and Session Orchestration
REST routes create users and sessions, accept code submissions and proctor logs, end sessions, and retrieve session history. The submission route synchronously bridges API input to the sandbox executor; the proctoring process independently POSTs events back to the API.
• main.py
• app/api/routes.py
• app/api/schemas.py
Persistent Domain Model
SQLAlchemy persists users, exam sessions, submission results, and proctoring events in local SQLite. CodeSubmission and ProctoringLog are associated with Session, making a session the aggregation boundary for judge history and anomaly timeline.
• app/core/models.py
• app/core/database.py
• proctor.db
Sandboxed Judge
run_code() dispatches Python, Java, C, or C++ source to a fresh Docker container. The container is disposable, network-disabled, memory-limited, and returns compile/run output plus pass/fail status to the API for persistence. Docker availability and the prebuilt proctor-sandbox image are required runtime dependencies.
• app/sandbox/executor.py
• app/sandbox/Dockerfile
• app/api/routes.py
Proctoring Capture and Detection Pipeline
A separate local process captures webcam frames and uses the bundled MediaPipe FaceLandmarker model. It calibrates an initial nose-position baseline, derives eye-aspect and gaze ratios, then emits threshold-based drowsiness, distraction, slouching, or no-face detections; this is heuristic CV rather than a trained classifier.
• app/ml_engine/main.py
• app/ml_engine/face_mesh.py
• app/ml_engine/face_landmarker.task
Event Computation and API Logging Boundary
Landmark calculations feed detection state in the camera loop. Detected anomalies pass through a logger that rate-limits each event type with a cooldown before HTTP POSTing to /api/proctor-logs/; the API owns validation and durable storage. The logger currently depends on a configured/hardcoded session identity, coupling the external ML process to an existing API session.
• app/ml_engine/calculations.py
• app/ml_engine/proctor_logger.py
• app/api/routes.py
Runtime Boundaries and External Services
The API runs on FastAPI/Uvicorn with Pydantic, SQLAlchemy, and SQLite. The judge requires the Docker daemon and an Ubuntu-based image containing language toolchains. The proctoring runtime requires a webcam, OpenCV, MediaPipe, and HTTP access to the local API; it is operationally separate from the API server.
Main entry points: routes.py REST routes · main.py Camera loop · executor.py Submission executor · face_mesh.py Face landmarks
Components 15
API service
- FastAPI entry
main.py - REST routes · Sessions, submissions, proctor logs, and history.
app/api/routes.py - Request schemas
app/api/schemas.py
Persistence
- Domain model · Session aggregates submissions and proctoring events.
app/core/models.py - Database access
app/core/database.py - Assessment data
proctor.db
Sandboxed judge
- Submission executor · Runs Python, Java, C, and C++ submissions.
app/sandbox/executor.py - Sandbox image · Disposable network-disabled, memory-limited execution environment.
app/sandbox/Dockerfile - Docker daemon
Proctoring process
- Camera loop · Independent webcam capture and event loop.
app/ml_engine/main.py - Face landmarks · Calibrates nose baseline and extracts face landmarks.
app/ml_engine/face_mesh.py - FaceLandmarker model
app/ml_engine/face_landmarker.task - Anomaly detection · Uses eye-aspect, gaze, and posture ratios.
app/ml_engine/calculations.py - Event logger · Cooldown-limits event types before posting with a configured session identity.
app/ml_engine/proctor_logger.py
Other components
- Webcam
Connections 16
- FastAPI entry → REST routes: serves
- REST routes → Request schemas: validates requests
- REST routes → Domain model: creates and queries
- Domain model → Database access: mapped through
- Database access → Assessment data: persists
- REST routes → Submission executor: judges submissions · Synchronous API-to-executor bridge.
- Submission executor → Docker daemon: creates container
- Docker daemon → Sandbox image: runs
- Submission executor → REST routes: compile/run result
- Webcam → Camera loop: frames
- Camera loop → Face landmarks: extracts landmarks
- FaceLandmarker model → Face landmarks: loaded by
- Face landmarks → Anomaly detection: landmarks and baseline
- Anomaly detection → Camera loop: detection state
- Camera loop → Event logger: detected anomalies
- Event logger → REST routes: POST /api/proctor-logs/ · Uses configured session identity.