# omkuthe/zkp2 architecture

> Architecture diagram of the GitHub repository omkuthe/zkp2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/omkuthe/zkp2
- Repository: https://github.com/omkuthe/zkp2

## Overview

#### 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: [`backend/app/main.py`](https://github.com/omkuthe/zkp2/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/models/session.py`](https://github.com/omkuthe/zkp2/blob/main/backend/app/models/session.py) (Attendance domain), [`zkattend-mobile/app/screens/QRScannerScreen.tsx`](https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/screens/QRScannerScreen.tsx) (Attendance screens), [`backend/app/api/routes/zk.py`](https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/zk.py) (ZK verification routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Student Mobile"]
  node_mobile_app["Expo student app<br/>React Native client<br/>[App.tsx]"]
  node_mobile_screens["Attendance screens<br/>mobile UI"]
  node_mobile_api["Mobile API client<br/>HTTP client<br/>[client.ts]"]
  node_mobile_location["Device location<br/>native hook<br/>[useLocation.ts]"]
  node_mobile_prover["WebView proof generator<br/>mobile ZK runtime<br/>[ZKPWebView.tsx]"]
end

subgraph group_web["Manager Portal"]
  node_web_portal["Manager portal<br/>React/Vite client<br/>[App.jsx]"]
  node_web_api["Web API client<br/>HTTP client<br/>[client.js]"]
end

subgraph group_backend["Backend"]
  node_api["FastAPI application<br/>HTTP API<br/>[main.py]"]
  node_role_routes["Role operations<br/>API routes<br/>[manager.py]"]
  node_attendance_routes["QR attendance routes<br/>API routes<br/>[qr.py]"]
  node_zk_routes["ZK verification routes<br/>API routes<br/>[zk.py]"]
  node_attendance_services["Attendance validation<br/>domain services<br/>[qr_service.py]"]
  node_attendance_models["Attendance domain<br/>SQL models<br/>[session.py]"]
  node_database[("SQLite database<br/>SQL persistence<br/>[zkattend.db]")]
  node_push_scheduler["Push scheduler<br/>background service<br/>[push_scheduler.py]"]
end

subgraph group_zk["ZK Proof System"]
  node_proof_bridge["Python proof bridge<br/>ZK orchestration<br/>[proof_generator.py]"]
  node_proof_verifier["Proof verifier<br/>ZK verification<br/>[verifier.py]"]
  node_circuit["QR proof circuit<br/>Circom circuit<br/>[qr_proof.circom]"]
end

node_mobile_app -->|"renders"| node_mobile_screens
node_mobile_screens -->|"uses"| node_mobile_api
node_mobile_screens -->|"requests location"| node_mobile_location
node_mobile_screens -->|"submits QR proof inputs"| node_mobile_prover
node_mobile_api -->|"HTTPS"| node_api
node_web_portal -->|"uses"| node_web_api
node_web_api -->|"HTTPS"| node_api
node_api -->|"routes role workflows"| node_role_routes
node_api -->|"routes check-ins"| node_attendance_routes
node_api -->|"routes proof verification"| node_zk_routes
node_attendance_routes -->|"validates attendance"| node_attendance_services
node_attendance_services -->|"creates sessions and checks"| node_attendance_models
node_role_routes -->|"manages internships"| node_attendance_models
node_attendance_models -->|"persists"| node_database
node_push_scheduler -.->|"uses attendance state"| node_attendance_models
node_mobile_prover -->|"executes bundled circuit"| node_circuit
node_zk_routes -->|"verifies submitted proof"| node_proof_verifier
node_proof_verifier -->|"uses verification artifacts"| node_circuit
node_proof_bridge -->|"generates with artifacts"| node_circuit
node_attendance_services -.->|"requests proof generation"| node_proof_bridge
node_zk_routes -->|"records verified result"| node_attendance_models

click node_mobile_app "https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/App.tsx"
click node_mobile_screens "https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/screens/QRScannerScreen.tsx"
click node_mobile_api "https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/api/client.ts"
click node_mobile_location "https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/hooks/useLocation.ts"
click node_mobile_prover "https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/components/ZKPWebView.tsx"
click node_web_portal "https://github.com/omkuthe/zkp2/blob/main/frontend-web/src/App.jsx"
click node_web_api "https://github.com/omkuthe/zkp2/blob/main/frontend-web/src/api/client.js"
click node_api "https://github.com/omkuthe/zkp2/blob/main/backend/app/main.py"
click node_role_routes "https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/manager.py"
click node_attendance_routes "https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/qr.py"
click node_zk_routes "https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/zk.py"
click node_attendance_services "https://github.com/omkuthe/zkp2/blob/main/backend/app/services/qr_service.py"
click node_attendance_models "https://github.com/omkuthe/zkp2/blob/main/backend/app/models/session.py"
click node_database "https://github.com/omkuthe/zkp2/blob/main/backend/zkattend.db"
click node_push_scheduler "https://github.com/omkuthe/zkp2/blob/main/backend/app/services/push_scheduler.py"
click node_proof_bridge "https://github.com/omkuthe/zkp2/blob/main/backend/app/zk/proof_generator.py"
click node_proof_verifier "https://github.com/omkuthe/zkp2/blob/main/backend/app/zk/verifier.py"
click node_circuit "https://github.com/omkuthe/zkp2/blob/main/backend/circuits/qr_proof/qr_proof.circom"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mobile_app,node_mobile_screens,node_mobile_api,node_mobile_location,node_mobile_prover toneBlue
class node_web_portal,node_web_api toneAmber
class node_api,node_role_routes,node_attendance_routes,node_zk_routes,node_attendance_services,node_attendance_models,node_database,node_push_scheduler toneMint
class node_proof_bridge,node_proof_verifier,node_circuit toneRose
```

## Components

### Student Mobile

- [Expo student app](https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/App.tsx): React Native client · Student attendance entry point. · `zkattend-mobile/App.tsx`
- [Attendance screens](https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/screens/QRScannerScreen.tsx): mobile UI · Login, dashboard, and QR scanning flows. · `zkattend-mobile/app/screens/QRScannerScreen.tsx`
- [Mobile API client](https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/api/client.ts): HTTP client · `zkattend-mobile/app/api/client.ts`
- [Device location](https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/hooks/useLocation.ts): native hook · `zkattend-mobile/app/hooks/useLocation.ts`
- [WebView proof generator](https://github.com/omkuthe/zkp2/blob/main/zkattend-mobile/app/components/ZKPWebView.tsx): mobile ZK runtime · Runs bundled circuit assets in a WebView. · `zkattend-mobile/app/components/ZKPWebView.tsx`

### Manager Portal

- [Manager portal](https://github.com/omkuthe/zkp2/blob/main/frontend-web/src/App.jsx): React/Vite client · Manager login, internship, and oversight UI. · `frontend-web/src/App.jsx`
- [Web API client](https://github.com/omkuthe/zkp2/blob/main/frontend-web/src/api/client.js): HTTP client · `frontend-web/src/api/client.js`

### Backend

- [FastAPI application](https://github.com/omkuthe/zkp2/blob/main/backend/app/main.py): HTTP API · Role and attendance workflow boundary. · `backend/app/main.py`
- [Role operations](https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/manager.py): API routes · Administration, manager, and student operations. · `backend/app/api/routes/manager.py`
- [QR attendance routes](https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/qr.py): API routes · QR challenge and check-in boundary. · `backend/app/api/routes/qr.py`
- [ZK verification routes](https://github.com/omkuthe/zkp2/blob/main/backend/app/api/routes/zk.py): API routes · `backend/app/api/routes/zk.py`
- [Attendance validation](https://github.com/omkuthe/zkp2/blob/main/backend/app/services/qr_service.py): domain services · QR behavior, geofencing, and hash-chain continuity. · `backend/app/services/qr_service.py`
- [Attendance domain](https://github.com/omkuthe/zkp2/blob/main/backend/app/models/session.py): SQL models · Internships, sessions, continuity checks, and anomalies. · `backend/app/models/session.py`
- [SQLite database](https://github.com/omkuthe/zkp2/blob/main/backend/zkattend.db): SQL persistence · Development attendance data store. · `backend/zkattend.db`
- [Push scheduler](https://github.com/omkuthe/zkp2/blob/main/backend/app/services/push_scheduler.py): background service · `backend/app/services/push_scheduler.py`

### ZK Proof System

- [Python proof bridge](https://github.com/omkuthe/zkp2/blob/main/backend/app/zk/proof_generator.py): ZK orchestration · Invokes JavaScript proof generation from backend code. · `backend/app/zk/proof_generator.py`
- [Proof verifier](https://github.com/omkuthe/zkp2/blob/main/backend/app/zk/verifier.py): ZK verification · `backend/app/zk/verifier.py`
- [QR proof circuit](https://github.com/omkuthe/zkp2/blob/main/backend/circuits/qr_proof/qr_proof.circom): Circom circuit · Circuit and proving artifacts establish the proof protocol. · `backend/circuits/qr_proof/qr_proof.circom`

## Connections

- 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
