How omkuthe/zkp2 works
Purpose and Entry Points
ZKAttend is an internship attendance system using QR check-ins, geofencing, hash-chain continuity, and zero-knowledge proofs to validate student presence without exposing raw proof secrets. It has three clients: a FastAPI backend (backend/app/main.py), a React/Vite manager portal (frontend-web/src/main.jsx, frontend-web/src/App.jsx), and an Expo/React Native student mobile app (zkattend-mobile/App.tsx, zkattend-mobile/index.ts).
API and Role Boundaries
The backend groups HTTP APIs by stakeholder and workflow: authentication, administration, managers, students, internships, QR attendance, and ZK verification. Route modules at backend/app/api/routes/auth.py, backend/app/api/routes/qr.py, and backend/app/api/routes/zk.py form the critical client-facing boundary; role-specific operations reside in backend/app/api/routes/admin.py, backend/app/api/routes/manager.py, and backend/app/api/routes/student.py.
Persistence and Attendance Domain
SQL-backed persistence is initialized through backend/app/core/database.py; runtime settings come from backend/app/core/config.py. The core domain models cover students, companies, internship definitions/assignments, attendance sessions, continuity checks, and anomalies: backend/app/models/student.py, backend/app/models/internship.py, backend/app/models/session.py, backend/app/models/continuity_check.py, and backend/app/models/anomaly.py. backend/zkattend.db indicates a checked-in SQLite development database, with backend/seed_db.py for population.
Attendance Validation Pipeline
A likely check-in flow is: manager/internship context creates or presents a QR challenge; the mobile student scans it; the app obtains location and produces a proof; backend verifies and persists the resulting session/check. QR-specific behavior is split between backend/app/services/qr_service.py and backend/app/api/routes/qr.py. Location constraints are evaluated in backend/app/services/geofence.py; session integrity and sequential attendance continuity are maintained through backend/app/services/hash_chain.py and backend/app/models/continuity_check.py.
Zero-Knowledge Proof Boundary
Proof production and verification are a cross-runtime subsystem. The backend invokes JavaScript proof generation from Python (backend/app/zk/proof_generator.py, backend/app/zk/generate_proof.js) and verifies proofs in backend/app/zk/verifier.py. Circuit source and proving artifacts are in backend/circuits/qr_proof/qr_proof.circom and backend/circuits/qr_proof/build/. This depends on Circom/snarkjs-style WASM, zkey, verification-key, and Powers of Tau artifacts, including backend/circuits/ptau/powersOfTau28_hez_final_14.ptau.
Mobile Student Client
The Expo app owns device-facing attendance actions: login, dashboard, QR scanning, location access, and client-side proof execution. Its primary screens are zkattend-mobile/app/screens/LoginScreen.tsx, zkattend-mobile/app/screens/DashboardScreen.tsx, and zkattend-mobile/app/screens/QRScannerScreen.tsx; API calls pass through zkattend-mobile/app/api/client.ts. Native/mobile constraints are isolated in zkattend-mobile/app/hooks/useLocation.ts and zkattend-mobile/app/native/environment.ts. ZK generation is hosted in a WebView (zkattend-mobile/app/components/ZKPWebView.tsx, zkattend-mobile/webview/proof_generator.html) using bundled circuit assets under zkattend-mobile/assets/circuits/.
Manager Web Client and Operations
The web portal is focused on manager authentication, internship creation/detail, student oversight, and dashboard monitoring: frontend-web/src/pages/ManagerLogin.jsx, frontend-web/src/pages/ManagerCreateInternship.jsx, and frontend-web/src/pages/ManagerInternshipDetail.jsx. It consumes backend APIs via frontend-web/src/api/client.js. Background or timed notification/push behavior is represented by backend/app/services/push_scheduler.py; operational reset is available through backend/reset_sessions.py.
Main entry points: main.py FastAPI application · session.py Attendance domain · QRScannerScreen.tsx Attendance screens · zk.py ZK verification routes
Components 18
Student Mobile
- Expo student app · Student attendance entry point.
zkattend-mobile/App.tsx - Attendance screens · Login, dashboard, and QR scanning flows.
zkattend-mobile/app/screens/QRScannerScreen.tsx - Mobile API client
zkattend-mobile/app/api/client.ts - Device location
zkattend-mobile/app/hooks/useLocation.ts - WebView proof generator · Runs bundled circuit assets in a WebView.
zkattend-mobile/app/components/ZKPWebView.tsx
Manager Portal
- Manager portal · Manager login, internship, and oversight UI.
frontend-web/src/App.jsx - Web API client
frontend-web/src/api/client.js
Backend
- FastAPI application · Role and attendance workflow boundary.
backend/app/main.py - Role operations · Administration, manager, and student operations.
backend/app/api/routes/manager.py - QR attendance routes · QR challenge and check-in boundary.
backend/app/api/routes/qr.py - ZK verification routes
backend/app/api/routes/zk.py - Attendance validation · QR behavior, geofencing, and hash-chain continuity.
backend/app/services/qr_service.py - Attendance domain · Internships, sessions, continuity checks, and anomalies.
backend/app/models/session.py - SQLite database · Development attendance data store.
backend/zkattend.db - Push scheduler
backend/app/services/push_scheduler.py
ZK Proof System
- Python proof bridge · Invokes JavaScript proof generation from backend code.
backend/app/zk/proof_generator.py - Proof verifier
backend/app/zk/verifier.py - QR proof circuit · Circuit and proving artifacts establish the proof protocol.
backend/circuits/qr_proof/qr_proof.circom
Connections 21
- Expo student app → Attendance screens: renders
- Attendance screens → Mobile API client: uses
- Attendance screens → Device location: requests location
- Attendance screens → WebView proof generator: submits QR proof inputs
- Mobile API client → FastAPI application: HTTPS
- Manager portal → Web API client: uses
- Web API client → FastAPI application: HTTPS
- FastAPI application → Role operations: routes role workflows
- FastAPI application → QR attendance routes: routes check-ins
- FastAPI application → ZK verification routes: routes proof verification
- QR attendance routes → Attendance validation: validates attendance
- Attendance validation → Attendance domain: creates sessions and checks
- Role operations → Attendance domain: manages internships
- Attendance domain → SQLite database: persists
- Push scheduler → Attendance domain: uses attendance state
- WebView proof generator → QR proof circuit: executes bundled circuit
- ZK verification routes → Proof verifier: verifies submitted proof
- Proof verifier → QR proof circuit: uses verification artifacts
- Python proof bridge → QR proof circuit: generates with artifacts
- Attendance validation → Python proof bridge: requests proof generation
- ZK verification routes → Attendance domain: records verified result