# theanomicg/risely-smartattend architecture

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

- Interactive diagram: https://gitdiagram.com/theanomicg/risely-smartattend
- Repository: https://github.com/theanomicg/risely-smartattend

## Overview

1. **Repository shape**
   SmartAttend is a three-part monorepo: a **Python kiosk client** (`kiosk/`), a **FastAPI backend** (`server/`), and a **React/Tailwind teacher dashboard** (`dashboard/`). The root also contains Docker Compose files and OS-specific startup scripts that act as the operational boundary for local development.

2. **Primary domain concept**
   The key cross-system identifier is **`class_id`**. It ties together kiosk check-in/out events, teacher dashboard views, attendance logs, alerts, and camera configuration so all subsystems refer to the same academic class record.

3. **Kiosk edge client**
   The kiosk is the classroom capture endpoint running on a Raspberry Pi or similar device. Its job is to use a local camera, capture face data for check-in/check-out, and send those events to the backend over HTTP. It is intentionally separate from the dashboard so classroom capture can continue even if the UI is not in use.

4. **Backend API and orchestration**
   The backend is the system’s central coordinator. `server/app/main.py` exposes FastAPI routes, while supporting modules handle authentication, configuration, database access, face processing, WebSocket broadcasting, and runtime monitoring. This is the only component that talks directly to PostgreSQL and to stored enrollment photos.

5. **Attendance and presence processing**
   Attendance logic is split into dedicated services under `server/app/services/`. One service handles attendance recording, another performs face matching, and another manages presence state. This separation suggests a flow where captured face embeddings are matched first, then attendance/session state is updated, then events are exposed to downstream consumers.

6. **Face recognition and storage boundary**
   Student enrollment photos are stored on disk under `server/storage/enrollment_photos/` by default, while face embeddings live in PostgreSQL with the `vector` extension. That means the backend keeps a dual representation: image files for review and vector rows for similarity matching. The face-processing layer uses DeepFace/OpenCV, with the current spec expecting 128-dimensional embeddings.

7. **Database layer**
   PostgreSQL is the authoritative persistence layer for attendance records, student/class metadata, and vector search data. `server/sql/init.sql` and `server/app/db.py` indicate an explicit schema/bootstrap path, and the repo assumes `pgvector` is enabled. The database is started separately via Compose or helper scripts, reinforcing that it is an infrastructure dependency rather than an embedded store.

8. **Teacher dashboard**
   The dashboard is a browser-based React app built with Vite and Tailwind. It provides the teacher-facing operational view, including attendance logs, status banners, resource lists, and a teacher/admin panel. It does not own business logic; it consumes backend APIs and WebSocket updates through `dashboard/src/api.js`.

9. **Admin and classroom operations**
   The admin panel appears to manage operational resources such as cameras and enrollment photo review. The README notes that camera RTSP URLs are masked in list responses and that the admin panel shows camera runtime health from the backend monitoring loop. This indicates an admin boundary focused on configuration and observability rather than student attendance entry.

10. **Real-time updates and monitoring**
   `server/app/ws.py` and `server/app/monitoring.py` point to two real-time concerns: pushing state to the dashboard and tracking backend/camera health. The dashboard likely subscribes to live updates for attendance and monitoring, while the backend schedules periodic checks using APScheduler. This creates a feedback loop for camera availability and classroom presence status.

11. **Authentication boundary**
   Authentication is optional and token-based. `TEACHER_TOKEN` and `ADMIN_TOKEN` can be enabled in the backend, and the dashboard can inject corresponding tokens through environment variables. In local development, auth can be disabled, which keeps the default architecture simple while still supporting protected deployments.

12. **Runtime and deployment topology**
   The repo is designed to run either as separate local processes or via Docker Compose. Canonical startup scripts live in `scripts/`, the backend is a Python 3.11/FastAPI service, the dashboard is a Node/Vite frontend, and the kiosk is another Python process. The result is a loosely coupled system: edge capture, central processing, and browser-based supervision.

13. **Main data flow**
   The end-to-end flow is: kiosk captures a face event → backend matches the face against stored embeddings → attendance/session state is persisted in PostgreSQL → backend optionally publishes live updates over WebSocket → dashboard renders attendance and monitoring views. Enrollment photos and camera health data support this flow but live at different boundaries: photos on disk, embeddings in the database, and camera status in the monitoring subsystem.

Main entry points: [`server/app/main.py`](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/main.py) (API entry), [`dashboard/src/components/TeacherDashboard.jsx`](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/TeacherDashboard.jsx) (Teacher view), [`compose.yaml`](https://github.com/theanomicg/risely-smartattend/blob/master/compose.yaml) (Compose/launch), [`dashboard/src/App.jsx`](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/App.jsx) (Dashboard app)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ops["Operations"]
  node_compose["Compose/launch<br/>orchestration<br/>[compose.yaml]"]
end

subgraph group_kiosk["Kiosk"]
  node_kiosk_main["Kiosk client<br/>edge client<br/>[main.py]"]
end

subgraph group_server["Backend"]
  node_server_main["API entry<br/>fastapi app<br/>[main.py]"]
  node_server_auth["Auth<br/>[auth.py]"]
  node_server_config["Config<br/>[config.py]"]
  node_server_db[("Postgres<br/>database layer<br/>[db.py]")]
  node_server_models["Domain models<br/>schema model<br/>[models.py]"]
  node_server_schemas["API schemas<br/>contracts<br/>[schemas.py]"]
  node_server_face{{"Face pipeline<br/>vision processing<br/>[face.py]"}}
  node_server_match["Matching<br/>similarity service<br/>[matching.py]"]
  node_server_attendance["Attendance<br/>recording service<br/>[attendance.py]"]
  node_server_presence["Presence<br/>state service<br/>[presence.py]"]
  node_server_ws["WebSocket<br/>realtime channel<br/>[ws.py]"]
  node_server_monitoring(("Monitoring<br/>health loop<br/>[monitoring.py]"))
  node_server_storage[("Photo store<br/>file storage<br/>[storage.py]")]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_main["Dashboard app<br/>react shell<br/>[App.jsx]"]
  node_dashboard_api["API client<br/>frontend client<br/>[api.js]"]
  node_teacher_dashboard["Teacher view<br/>ui container"]
  node_attendance_log["Attendance log<br/>ui panel<br/>[AttendanceLog.jsx]"]
  node_status_banner["Status banner<br/>ui panel<br/>[StatusBanner.jsx]"]
  node_resource_lists["Resource lists<br/>ui panel<br/>[ResourceLists.jsx]"]
  node_admin_panel["Admin panel<br/>ui panel<br/>[AdminPanel.jsx]"]
end

node_compose -->|"starts"| node_kiosk_main
node_compose -->|"starts"| node_server_main
node_compose -->|"starts"| node_dashboard_main
node_compose -->|"provisions"| node_server_db
node_kiosk_main -->|"events"| node_server_main
node_dashboard_main -->|"uses"| node_dashboard_api
node_dashboard_main -->|"renders"| node_teacher_dashboard
node_dashboard_main -->|"renders"| node_admin_panel
node_teacher_dashboard -->|"contains"| node_attendance_log
node_teacher_dashboard -->|"contains"| node_status_banner
node_teacher_dashboard -->|"contains"| node_resource_lists
node_teacher_dashboard -->|"contains"| node_admin_panel
node_dashboard_api -->|"calls"| node_server_main
node_server_main -->|"guards"| node_server_auth
node_server_main -->|"reads"| node_server_config
node_server_main -->|"persists"| node_server_db
node_server_main -->|"uses"| node_server_models
node_server_main -->|"serializes"| node_server_schemas
node_server_main -->|"routes"| node_server_face
node_server_main -->|"publishes"| node_server_ws
node_server_main -->|"observes"| node_server_monitoring
node_server_face -->|"feeds"| node_server_match
node_server_face -->|"reads"| node_server_storage
node_server_match -->|"queries"| node_server_db
node_server_match -->|"triggers"| node_server_attendance
node_server_attendance -->|"writes"| node_server_db
node_server_attendance -->|"updates"| node_server_presence
node_server_presence -->|"broadcasts"| node_server_ws
node_server_monitoring -->|"broadcasts"| node_server_ws

click node_compose "https://github.com/theanomicg/risely-smartattend/blob/master/compose.yaml"
click node_kiosk_main "https://github.com/theanomicg/risely-smartattend/blob/master/kiosk/main.py"
click node_server_main "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/main.py"
click node_server_auth "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/auth.py"
click node_server_config "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/config.py"
click node_server_db "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/db.py"
click node_server_models "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/models.py"
click node_server_schemas "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/schemas.py"
click node_server_face "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/face.py"
click node_server_match "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/services/matching.py"
click node_server_attendance "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/services/attendance.py"
click node_server_presence "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/services/presence.py"
click node_server_ws "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/ws.py"
click node_server_monitoring "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/monitoring.py"
click node_server_storage "https://github.com/theanomicg/risely-smartattend/blob/master/server/app/storage.py"
click node_dashboard_main "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/App.jsx"
click node_dashboard_api "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/api.js"
click node_teacher_dashboard "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/TeacherDashboard.jsx"
click node_attendance_log "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/AttendanceLog.jsx"
click node_status_banner "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/StatusBanner.jsx"
click node_resource_lists "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/ResourceLists.jsx"
click node_admin_panel "https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/AdminPanel.jsx"

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_compose toneBlue
class node_kiosk_main toneAmber
class node_server_main,node_server_auth,node_server_config,node_server_db,node_server_models,node_server_schemas,node_server_face,node_server_match,node_server_attendance,node_server_presence,node_server_ws,node_server_monitoring,node_server_storage toneMint
class node_dashboard_main,node_dashboard_api,node_teacher_dashboard,node_attendance_log,node_status_banner,node_resource_lists,node_admin_panel toneRose
```

## Components

### Operations

Local runtime and deployment boundary.

- [Compose/launch](https://github.com/theanomicg/risely-smartattend/blob/master/compose.yaml): orchestration · Root scripts and compose files start the three runtimes and database. · `compose.yaml`

### Kiosk

Edge capture client on the classroom device.

- [Kiosk client](https://github.com/theanomicg/risely-smartattend/blob/master/kiosk/main.py): edge client · Camera-based classroom capture process that sends attendance events to the backend. · `kiosk/main.py`

### Backend

FastAPI coordinator, persistence, and real-time services.

- [API entry](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/main.py): fastapi app · FastAPI application entry point that wires routes and services. · `server/app/main.py`
- [Auth](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/auth.py): token auth · Optional teacher/admin token boundary for protected deployments. · `server/app/auth.py`
- [Config](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/config.py): runtime config · Environment-driven settings for deployment, auth, and feature flags. · `server/app/config.py`
- [Postgres](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/db.py): database layer · Authoritative database access and bootstrap path for attendance and metadata. · `server/app/db.py`
- [Domain models](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/models.py): schema model · Core attendance, class, student, and camera domain objects. · `server/app/models.py`
- [API schemas](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/schemas.py): contracts · Request and response shapes exposed by the backend API. · `server/app/schemas.py`
- [Face pipeline](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/face.py): vision processing · OpenCV/DeepFace-based face handling for recognition and embeddings. · `server/app/face.py`
- [Matching](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/services/matching.py): similarity service · Compares captured embeddings against stored enrollment embeddings. · `server/app/services/matching.py`
- [Attendance](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/services/attendance.py): recording service · Persists check-in and check-out events and class attendance records. · `server/app/services/attendance.py`
- [Presence](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/services/presence.py): state service · Maintains live presence/session state for downstream consumers. · `server/app/services/presence.py`
- [WebSocket](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/ws.py): realtime channel · Broadcasts live attendance and status updates to the dashboard. · `server/app/ws.py`
- [Monitoring](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/monitoring.py): health loop · Tracks backend and camera runtime health for operational visibility. · `server/app/monitoring.py`
- [Photo store](https://github.com/theanomicg/risely-smartattend/blob/master/server/app/storage.py): file storage · Disk boundary for enrollment photos used by recognition and review. · `server/app/storage.py`

### Dashboard

Teacher-facing React UI and API client.

- [Dashboard app](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/App.jsx): react shell · Frontend shell that assembles the teacher and admin views. · `dashboard/src/App.jsx`
- [API client](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/api.js): frontend client · Browser-side backend integration for REST and live updates. · `dashboard/src/api.js`
- [Teacher view](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/TeacherDashboard.jsx): ui container · Primary operational screen for attendance and classroom status. · `dashboard/src/components/TeacherDashboard.jsx`
- [Attendance log](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/AttendanceLog.jsx): ui panel · Displays attendance events and classroom records. · `dashboard/src/components/AttendanceLog.jsx`
- [Status banner](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/StatusBanner.jsx): ui panel · Shows live state and health summaries to the teacher. · `dashboard/src/components/StatusBanner.jsx`
- [Resource lists](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/ResourceLists.jsx): ui panel · Operational lists for cameras and enrollment-related resources. · `dashboard/src/components/ResourceLists.jsx`
- [Admin panel](https://github.com/theanomicg/risely-smartattend/blob/master/dashboard/src/components/AdminPanel.jsx): ui panel · Teacher/admin controls for operational resources and review. · `dashboard/src/components/AdminPanel.jsx`

## Connections

- Compose/launch → Kiosk client: starts · Launches the edge capture client.
- Compose/launch → API entry: starts · Launches the backend API service.
- Compose/launch → Dashboard app: starts · Launches the browser frontend.
- Compose/launch → Postgres: provisions · Brings up the PostgreSQL dependency.
- Kiosk client → API entry: events · Sends check-in and check-out requests over HTTP.
- Dashboard app → API client: uses · UI shell delegates backend communication to the API client.
- Dashboard app → Teacher view: renders · Composes the main operational classroom view.
- Dashboard app → Admin panel: renders · Includes the admin/operator controls.
- Teacher view → Attendance log: contains · Shows attendance history and current records.
- Teacher view → Status banner: contains · Shows live status and health banners.
- Teacher view → Resource lists: contains · Shows operational resource listings.
- Teacher view → Admin panel: contains · Surfaces administrative classroom operations.
- API client → API entry: calls · Consumes backend REST and real-time endpoints.
- API entry → Auth: guards · Applies optional teacher/admin token checks.
- API entry → Config: reads · Loads runtime configuration and feature flags.
- API entry → Postgres: persists · Central API boundary writes and reads authoritative state.
- API entry → Domain models: uses · Shares domain objects across the application boundary.
- API entry → API schemas: serializes · Shapes API inputs and outputs.
- API entry → Face pipeline: routes · Directs image/embedding processing requests.
- API entry → WebSocket: publishes · Streams live updates to connected clients.
- API entry → Monitoring: observes · Exposes health and runtime state.
- Face pipeline → Matching: feeds · Produces embeddings for similarity matching.
- Face pipeline → Photo store: reads · Uses enrollment photos from disk.
- Matching → Postgres: queries · Looks up stored embeddings and related metadata.
- Matching → Attendance: triggers · Matched identity flows into attendance recording.
- Attendance → Postgres: writes · Stores attendance events and class records.
- Attendance → Presence: updates · Refreshes session and presence state after recording.
- Presence → WebSocket: broadcasts · Pushes live presence changes to the dashboard.
- Monitoring → WebSocket: broadcasts · Sends runtime health updates to clients.
