# ankan00v/lpu-smart-campus architecture

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

- Interactive diagram: https://gitdiagram.com/ankan00v/lpu-smart-campus
- Repository: https://github.com/ankan00v/lpu-smart-campus

## Overview

#### Purpose and Entry Points
LPU Smart Campus is a production-style campus operations platform: attendance and remedial workflows, food ordering, academic administration/RMS, identity controls, realtime updates, and AI support. The FastAPI application starts at `app/main.py`; it assembles API domains from `app/routers/`. The browser SPA enters through `web/index.html` and `web/app.js`, with backend-served UI/static routes.

#### API Composition and Domain Boundaries
Routers are the primary HTTP authorization and product boundaries: authentication, attendance, remedial, food, messaging, resources/admin, enterprise, AI, identity, and realtime. Core paths: `app/routers/auth.py`, `app/routers/attendance.py`, `app/routers/remedial.py`. Supporting operations are separated into `app/routers/food.py`, `app/routers/admin.py`, and `app/routers/enterprise.py`; router handlers delegate to domain services rather than being the intended persistence boundary.

#### Academic Attendance and Recovery
Attendance accepts scheduled, time-windowed student submissions, verifies faces, persists ledger state, supports faculty review, and derives risk interventions. `app/face_verification.py` handles multi-frame/anti-spoof verification; `app/attendance_ledger.py` owns attendance records; `app/attendance_recovery.py` produces watch/high/critical recovery plans and may feed administrative/RMS actions. Academic policy and default scheduling logic reside in `app/academic_policy.py` and `app/default_timetable.py`.

#### Remedial and Messaging Lifecycle
Faculty creates section-scoped remedial classes, distributes codes/messages, and students validate codes before face-verified attendance. The workflow records class/attendance history and exposes faculty section status. Principal boundary: `app/routers/remedial.py`; associated delivery and recovery behavior: `app/routers/messages.py`, `app/recovery_email_template.py`. This shares identity, face verification, SQL persistence, asynchronous dispatch, and realtime publication with normal attendance.

#### Identity, Security, and Enterprise Governance
OTP-first authentication, sessions, roles, MFA, and identity consistency are centered in `app/routers/auth.py`, `app/auth_utils.py`, and `app/id_alignment.py`. Identity Shield case/graph functionality is isolated in `app/routers/identity_shield.py` and `app/identity_shield.py`. Enterprise endpoints cover SSO/SCIM, encryption rotation, compliance exports, DR, and capacity/SLA controls through `app/routers/enterprise.py` and `app/enterprise_controls.py`.

#### Persistence and Async/Realtime Runtime
PostgreSQL is the transactional system of record, represented by `app/database.py` and `app/models.py`. MongoDB holds auth plus mirrored/event/analytics-oriented views via `app/mongo.py`; alignment and snapshot consistency are explicit operational concerns. Redis provides rate-limit/cache primitives and cross-instance fanout through `app/redis_dual_client.py` and `app/realtime_bus.py`. Durable work is dispatched through an outbox/worker boundary (`app/outbox.py`, `app/workers.py`) for OTP, notifications, re-verification, and recomputation. SSE is exposed by `app/routers/realtime.py`; clients consume it in `web/modules/realtime-event-bus.js`.

#### Client, Integrations, and Deployment
The vanilla-JS SPA lazy-loads live workflow routes such as `web/routes/attendance-live.js`, `web/routes/remedial-live.js`, and `web/routes/admin-live.js`. Food operations include payment intent/webhook safety in `app/routers/food.py`, with Razorpay as the declared payment integration. AI assistance is split between Copilot and Saarthi (`app/copilot_ai.py`, `app/saarthi_service.py`) with environment-driven providers. Strict production runtime requires Redis and workers; the container topology is defined in `deploy/docker-compose.strict.yml`, while telemetry and health/metrics controls live in `app/observability.py` and `app/runtime_infra.py`.

Main entry points: [`app/main.py`](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/main.py) (FastAPI application), [`app/attendance_ledger.py`](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/attendance_ledger.py) (Attendance ledger), [`web/app.js`](https://github.com/ankan00v/lpu-smart-campus/blob/main/web/app.js) (Vanilla JS SPA), [`deploy/docker-compose.strict.yml`](https://github.com/ankan00v/lpu-smart-campus/blob/main/deploy/docker-compose.strict.yml) (Strict production topology)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser Client"]
  node_spa["Vanilla JS SPA<br/>browser client<br/>[app.js]"]
  node_spa_routes["Live workflow routes<br/>SPA route modules<br/>[attendance-live.js]"]
  node_sse_client["Realtime event client<br/>SSE consumer"]
end

subgraph group_api["FastAPI API"]
  node_main["FastAPI application<br/>application entry<br/>[main.py]"]
  node_auth_api["Auth API<br/>router<br/>[auth.py]"]
  node_attendance_api["Attendance API<br/>router<br/>[attendance.py]"]
  node_remedial_api["Remedial API<br/>router<br/>[remedial.py]"]
  node_operations_apis["Operations APIs<br/>routers<br/>[enterprise.py]"]
  node_realtime_api["Realtime API<br/>SSE router<br/>[realtime.py]"]
  node_identity_api["Identity Shield API<br/>router<br/>[identity_shield.py]"]
end

subgraph group_domain["Domain Services"]
  node_attendance_ledger["Attendance ledger<br/>domain service"]
  node_face_verification["Face verification<br/>verification service"]
  node_recovery["Attendance recovery<br/>risk service"]
  node_identity_controls["Identity controls<br/>identity services<br/>[identity_shield.py]"]
  node_ai_services["Copilot &amp; Saarthi<br/>AI services<br/>[copilot_ai.py]"]
end

subgraph group_runtime["Data &amp; Runtime"]
  node_postgres[("PostgreSQL<br/>transactional system of record<br/>[database.py]")]
  node_mongo[("MongoDB<br/>auth and analytics views<br/>[mongo.py]")]
  node_redis_bus["Redis realtime bus<br/>cache and fanout<br/>[realtime_bus.py]"]
  node_outbox_workers["Outbox workers<br/>durable async processing<br/>[workers.py]"]
  node_production_topology{{"Strict production topology<br/>container deployment"}}
end

node_spa -->|"HTTP and static UI"| node_main
node_spa -->|"lazy-loads"| node_spa_routes
node_spa -->|"starts"| node_sse_client
node_sse_client -->|"SSE"| node_realtime_api
node_main -->|"mounts"| node_auth_api
node_main -->|"mounts"| node_attendance_api
node_main -->|"mounts"| node_remedial_api
node_main -->|"mounts"| node_operations_apis
node_main -->|"mounts"| node_realtime_api
node_main -->|"mounts"| node_identity_api
node_auth_api -->|"auth state"| node_mongo
node_auth_api -->|"aligns identities"| node_identity_controls
node_attendance_api -->|"verifies submission"| node_face_verification
node_attendance_api -->|"records and reviews"| node_attendance_ledger
node_remedial_api -->|"verifies attendance"| node_face_verification
node_remedial_api -->|"records history"| node_attendance_ledger
node_attendance_ledger -->|"persists"| node_postgres
node_attendance_ledger -->|"supplies risk data"| node_recovery
node_recovery -->|"queues interventions"| node_outbox_workers
node_operations_apis -->|"transactional operations"| node_postgres
node_identity_api -->|"case and graph actions"| node_identity_controls
node_ai_services -.->|"uses campus context"| node_postgres
node_outbox_workers -->|"publishes events"| node_redis_bus
node_redis_bus -->|"fans out events"| node_realtime_api
node_production_topology -->|"runs"| node_main
node_production_topology -->|"runs"| node_outbox_workers
node_production_topology -->|"requires"| node_redis_bus

click node_spa "https://github.com/ankan00v/lpu-smart-campus/blob/main/web/app.js"
click node_spa_routes "https://github.com/ankan00v/lpu-smart-campus/blob/main/web/routes/attendance-live.js"
click node_sse_client "https://github.com/ankan00v/lpu-smart-campus/blob/main/web/modules/realtime-event-bus.js"
click node_main "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/main.py"
click node_auth_api "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/auth.py"
click node_attendance_api "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/attendance.py"
click node_remedial_api "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/remedial.py"
click node_operations_apis "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/enterprise.py"
click node_realtime_api "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/realtime.py"
click node_identity_api "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/identity_shield.py"
click node_attendance_ledger "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/attendance_ledger.py"
click node_face_verification "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/face_verification.py"
click node_recovery "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/attendance_recovery.py"
click node_identity_controls "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/identity_shield.py"
click node_ai_services "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/copilot_ai.py"
click node_postgres "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/database.py"
click node_mongo "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/mongo.py"
click node_redis_bus "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/realtime_bus.py"
click node_outbox_workers "https://github.com/ankan00v/lpu-smart-campus/blob/main/app/workers.py"
click node_production_topology "https://github.com/ankan00v/lpu-smart-campus/blob/main/deploy/docker-compose.strict.yml"

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_spa,node_spa_routes,node_sse_client toneBlue
class node_main,node_auth_api,node_attendance_api,node_remedial_api,node_operations_apis,node_realtime_api,node_identity_api toneAmber
class node_attendance_ledger,node_face_verification,node_recovery,node_identity_controls,node_ai_services toneMint
class node_postgres,node_mongo,node_redis_bus,node_outbox_workers,node_production_topology toneRose
```

## Components

### Browser Client

- [Vanilla JS SPA](https://github.com/ankan00v/lpu-smart-campus/blob/main/web/app.js): browser client · Lazy-loads live campus workflows. · `web/app.js`
- [Live workflow routes](https://github.com/ankan00v/lpu-smart-campus/blob/main/web/routes/attendance-live.js): SPA route modules · `web/routes/attendance-live.js`
- [Realtime event client](https://github.com/ankan00v/lpu-smart-campus/blob/main/web/modules/realtime-event-bus.js): SSE consumer · `web/modules/realtime-event-bus.js`

### FastAPI API

- [FastAPI application](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/main.py): application entry · Assembles routers and serves backend UI/static routes. · `app/main.py`
- [Auth API](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/auth.py): router · OTP, sessions, roles, and MFA boundary. · `app/routers/auth.py`
- [Attendance API](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/attendance.py): router · Scheduled student submissions and faculty review. · `app/routers/attendance.py`
- [Remedial API](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/remedial.py): router · Section remedial lifecycle and code validation. · `app/routers/remedial.py`
- [Operations APIs](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/enterprise.py): routers · Food, admin, and enterprise operations. · `app/routers/enterprise.py`
- [Realtime API](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/realtime.py): SSE router · `app/routers/realtime.py`
- [Identity Shield API](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/routers/identity_shield.py): router · `app/routers/identity_shield.py`

### Domain Services

- [Attendance ledger](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/attendance_ledger.py): domain service · Owns attendance records and ledger state. · `app/attendance_ledger.py`
- [Face verification](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/face_verification.py): verification service · Multi-frame and anti-spoof checks. · `app/face_verification.py`
- [Attendance recovery](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/attendance_recovery.py): risk service · Derives watch, high, and critical intervention plans. · `app/attendance_recovery.py`
- [Identity controls](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/identity_shield.py): identity services · Maintains identity alignment and Shield cases. · `app/identity_shield.py`
- [Copilot & Saarthi](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/copilot_ai.py): AI services · `app/copilot_ai.py`

### Data & Runtime

- [PostgreSQL](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/database.py): transactional system of record · `app/database.py`
- [MongoDB](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/mongo.py): auth and analytics views · Stores auth plus mirrored/event-oriented views. · `app/mongo.py`
- [Redis realtime bus](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/realtime_bus.py): cache and fanout · Provides rate limits, cache, and cross-instance fanout. · `app/realtime_bus.py`
- [Outbox workers](https://github.com/ankan00v/lpu-smart-campus/blob/main/app/workers.py): durable async processing · Dispatches OTP, notifications, re-verification, and recomputation. · `app/workers.py`
- [Strict production topology](https://github.com/ankan00v/lpu-smart-campus/blob/main/deploy/docker-compose.strict.yml): container deployment · Requires Redis and workers. · `deploy/docker-compose.strict.yml`

## Connections

- Vanilla JS SPA → FastAPI application: HTTP and static UI
- Vanilla JS SPA → Live workflow routes: lazy-loads
- Vanilla JS SPA → Realtime event client: starts
- Realtime event client → Realtime API: SSE
- FastAPI application → Auth API: mounts
- FastAPI application → Attendance API: mounts
- FastAPI application → Remedial API: mounts
- FastAPI application → Operations APIs: mounts
- FastAPI application → Realtime API: mounts
- FastAPI application → Identity Shield API: mounts
- Auth API → MongoDB: auth state
- Auth API → Identity controls: aligns identities
- Attendance API → Face verification: verifies submission
- Attendance API → Attendance ledger: records and reviews
- Remedial API → Face verification: verifies attendance
- Remedial API → Attendance ledger: records history
- Attendance ledger → PostgreSQL: persists
- Attendance ledger → Attendance recovery: supplies risk data
- Attendance recovery → Outbox workers: queues interventions
- Operations APIs → PostgreSQL: transactional operations
- Identity Shield API → Identity controls: case and graph actions
- Copilot & Saarthi → PostgreSQL: uses campus context
- Outbox workers → Redis realtime bus: publishes events
- Redis realtime bus → Realtime API: fans out events
- Strict production topology → FastAPI application: runs
- Strict production topology → Outbox workers: runs
- Strict production topology → Redis realtime bus: requires
