# shubham-pande-ai/focusai architecture

> Architecture diagram of the GitHub repository shubham-pande-ai/focusai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shubham-pande-ai/focusai
- Repository: https://github.com/shubham-pande-ai/focusai

## Overview

FocusAI captures webcam-derived facial features in the browser, streams telemetry to a FastAPI backend for attention and emotion analysis, and persists results for live dashboards and an agentic analytics assistant. The README documents the browser-to-backend flow and major capabilities; sampled backend code confirms stream processing, storage, authentication, session management, and agent tooling. Frontend network wiring and several API implementations were not sampled, so those links are documented rather than asserted from source.

Main entry points: [`backend/main.py`](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/main.py) (FastAPI app), [`backend/websocket/stream.py`](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/websocket/stream.py) (Telemetry WebSocket), [`frontend/src/app/page.tsx`](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/page.tsx) (FocusAI portal), [`frontend/src/components/WebcamTracker.tsx`](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/components/WebcamTracker.tsx) (Webcam tracker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser experience"]
  node_web_app["FocusAI portal<br/>[page.tsx]"]
  node_user_dashboard["User dashboard<br/>[page.tsx]"]
  node_admin_dashboard["Admin dashboard<br/>[page.tsx]"]
  node_webcam_tracker["Webcam tracker<br/>[WebcamTracker.tsx]"]
  node_face_model["Face landmark model"]
  node_wasm_vision["Vision WASM"]
end

subgraph group_api["Backend services"]
  node_app_server["FastAPI app<br/>[main.py]"]
  node_auth_api["Authentication API<br/>[auth.py]"]
  node_user_api["User management API<br/>[users.py]"]
  node_session_api["Session API<br/>[sessions.py]"]
  node_taxonomy_api["Workspace taxonomy API<br/>[taxonomy.py]"]
  node_telemetry_api["Telemetry and chat API<br/>[routes.py]"]
  node_analytics_api["Analytics API<br/>[analytics.py]"]
end

subgraph group_analysis["Telemetry analysis"]
  node_websocket_stream["Telemetry WebSocket<br/>[stream.py]"]
  node_geometry["Geometry helpers<br/>[math.py]"]
  node_emotion_engine["Expression analysis<br/>[analyzer.py]"]
  node_attention_engine["Attention scoring<br/>[scorer.py]"]
end

subgraph group_data_ai["Data and AI"]
  node_relational_models["Accounts and sessions<br/>[relational.py]"]
  node_telemetry_models["Telemetry models<br/>[timescale.py]"]
  node_db_connection["Database connection<br/>[connection.py]"]
  node_agent["ReAct analysis agent<br/>[master_agent.py]"]
  node_timescale_db[("TimescaleDB")]
  node_postgres_db[("PostgreSQL")]
end

node_participant(("Participant"))
node_administrator(("Admin or host"))
node_groq["Groq LLM"]

node_participant -->|"opens"| node_web_app
node_administrator -->|"opens"| node_web_app
node_web_app -.->|"authenticates"| node_auth_api
node_web_app -.->|"routes to"| node_user_dashboard
node_web_app -.->|"routes to"| node_admin_dashboard
node_participant -->|"provides video"| node_webcam_tracker
node_webcam_tracker -.->|"loads"| node_face_model
node_webcam_tracker -->|"processes locally"| node_wasm_vision
node_webcam_tracker -->|"sends feature vectors"| node_websocket_stream
node_user_dashboard -.->|"polls metrics"| node_app_server
node_admin_dashboard -.->|"requests insights"| node_app_server
node_app_server -->|"registers router"| node_auth_api
node_app_server -->|"registers router"| node_user_api
node_app_server -->|"registers router"| node_session_api
node_app_server -->|"registers router"| node_taxonomy_api
node_app_server -->|"registers router"| node_telemetry_api
node_app_server -->|"registers router"| node_analytics_api
node_app_server -->|"registers router"| node_websocket_stream
node_auth_api -->|"queries"| node_relational_models
node_session_api -->|"manages sessions"| node_relational_models
node_auth_api -.->|"validates credentials"| node_postgres_db
node_websocket_stream -->|"uses"| node_geometry
node_websocket_stream -->|"detects expressions"| node_emotion_engine
node_websocket_stream -->|"scores focus"| node_attention_engine
node_emotion_engine -->|"uses"| node_geometry
node_websocket_stream -->|"writes telemetry"| node_telemetry_models
node_websocket_stream -->|"opens sessions"| node_db_connection
node_telemetry_models -.->|"stores time series"| node_timescale_db
node_relational_models -.->|"stores accounts"| node_postgres_db
node_telemetry_api -->|"gets agent"| node_agent
node_agent -->|"queries telemetry"| node_db_connection
node_agent -->|"uses model"| node_groq
node_analytics_api -.->|"queries data"| node_db_connection
node_telemetry_api -.->|"reads metrics"| node_timescale_db
node_admin_dashboard -.->|"chats with agent"| node_telemetry_api

click node_web_app "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/page.tsx"
click node_user_dashboard "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/user/page.tsx"
click node_admin_dashboard "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/admin/page.tsx"
click node_webcam_tracker "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/components/WebcamTracker.tsx"
click node_face_model "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/public/models/face_landmarker.task"
click node_wasm_vision "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/public/wasm/vision_wasm_internal.js"
click node_app_server "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/main.py"
click node_auth_api "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/auth.py"
click node_user_api "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/users.py"
click node_session_api "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/sessions.py"
click node_taxonomy_api "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/taxonomy.py"
click node_telemetry_api "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/routes.py"
click node_analytics_api "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/analytics.py"
click node_websocket_stream "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/websocket/stream.py"
click node_geometry "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/utils/math.py"
click node_emotion_engine "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/services/emotion/analyzer.py"
click node_attention_engine "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/services/attention/scorer.py"
click node_relational_models "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/models/relational.py"
click node_telemetry_models "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/models/timescale.py"
click node_db_connection "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/database/connection.py"
click node_agent "https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/services/agents/master_agent.py"

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_web_app,node_user_dashboard,node_admin_dashboard,node_webcam_tracker,node_face_model,node_wasm_vision toneBlue
class node_app_server,node_auth_api,node_user_api,node_session_api,node_taxonomy_api,node_telemetry_api,node_analytics_api toneAmber
class node_websocket_stream,node_geometry,node_emotion_engine,node_attention_engine toneMint
class node_relational_models,node_telemetry_models,node_db_connection,node_agent,node_timescale_db,node_postgres_db toneRose
class node_participant,node_administrator,node_groq toneIndigo
```

## Components

### Browser experience

- [FocusAI portal](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/page.tsx): `frontend/src/app/page.tsx`
- [User dashboard](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/user/page.tsx): `frontend/src/app/user/page.tsx`
- [Admin dashboard](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/app/admin/page.tsx): `frontend/src/app/admin/page.tsx`
- [Webcam tracker](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/src/components/WebcamTracker.tsx): `frontend/src/components/WebcamTracker.tsx`
- [Face landmark model](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/public/models/face_landmarker.task): `frontend/public/models/face_landmarker.task`
- [Vision WASM](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/frontend/public/wasm/vision_wasm_internal.js): `frontend/public/wasm/vision_wasm_internal.js`

### Backend services

- [FastAPI app](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/main.py): `backend/main.py`
- [Authentication API](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/auth.py): `backend/api/auth.py`
- [User management API](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/users.py): `backend/api/users.py`
- [Session API](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/sessions.py): `backend/api/sessions.py`
- [Workspace taxonomy API](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/taxonomy.py): `backend/api/taxonomy.py`
- [Telemetry and chat API](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/routes.py): `backend/api/routes.py`
- [Analytics API](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/api/analytics.py): `backend/api/analytics.py`

### Telemetry analysis

- [Telemetry WebSocket](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/websocket/stream.py): `backend/websocket/stream.py`
- [Geometry helpers](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/utils/math.py): `backend/utils/math.py`
- [Expression analysis](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/services/emotion/analyzer.py): `backend/services/emotion/analyzer.py`
- [Attention scoring](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/services/attention/scorer.py): `backend/services/attention/scorer.py`

### Data and AI

- [Accounts and sessions](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/models/relational.py): `backend/models/relational.py`
- [Telemetry models](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/models/timescale.py): `backend/models/timescale.py`
- [Database connection](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/database/connection.py): `backend/database/connection.py`
- [ReAct analysis agent](https://github.com/shubham-pande-ai/focusai/blob/shubham-feature/backend/services/agents/master_agent.py): `backend/services/agents/master_agent.py`
- **TimescaleDB**
- **PostgreSQL**

### Other components

- **Participant**
- **Admin or host**
- **Groq LLM**

## Connections

- Participant → FocusAI portal: opens (evidence: `README.md`)
- Admin or host → FocusAI portal: opens (evidence: `README.md`)
- FocusAI portal → Authentication API: authenticates (evidence: `README.md`)
- FocusAI portal → User dashboard: routes to
- FocusAI portal → Admin dashboard: routes to
- Participant → Webcam tracker: provides video (evidence: `README.md`)
- Webcam tracker → Face landmark model: loads (evidence: `README.md`)
- Webcam tracker → Vision WASM: processes locally (evidence: `README.md`)
- Webcam tracker → Telemetry WebSocket: sends feature vectors (evidence: `README.md`)
- User dashboard → FastAPI app: polls metrics (evidence: `README.md`)
- Admin dashboard → FastAPI app: requests insights (evidence: `README.md`)
- FastAPI app → Authentication API: registers router (evidence: `backend/main.py`)
- FastAPI app → User management API: registers router (evidence: `backend/main.py`)
- FastAPI app → Session API: registers router (evidence: `backend/main.py`)
- FastAPI app → Workspace taxonomy API: registers router (evidence: `backend/main.py`)
- FastAPI app → Telemetry and chat API: registers router (evidence: `backend/main.py`)
- FastAPI app → Analytics API: registers router (evidence: `backend/main.py`)
- FastAPI app → Telemetry WebSocket: registers router (evidence: `backend/main.py`)
- Authentication API → Accounts and sessions: queries (evidence: `backend/api/auth.py`)
- Session API → Accounts and sessions: manages sessions (evidence: `backend/api/sessions.py`)
- Authentication API → PostgreSQL: validates credentials (evidence: `README.md`)
- Telemetry WebSocket → Geometry helpers: uses (evidence: `backend/websocket/stream.py`)
- Telemetry WebSocket → Expression analysis: detects expressions (evidence: `backend/websocket/stream.py`)
- Telemetry WebSocket → Attention scoring: scores focus (evidence: `backend/websocket/stream.py`)
- Expression analysis → Geometry helpers: uses (evidence: `backend/services/emotion/analyzer.py`)
- Telemetry WebSocket → Telemetry models: writes telemetry (evidence: `backend/websocket/stream.py`)
- Telemetry WebSocket → Database connection: opens sessions (evidence: `backend/websocket/stream.py`)
- Telemetry models → TimescaleDB: stores time series (evidence: `README.md`)
- Accounts and sessions → PostgreSQL: stores accounts (evidence: `README.md`)
- Telemetry and chat API → ReAct analysis agent: gets agent (evidence: `backend/api/routes.py`)
- ReAct analysis agent → Database connection: queries telemetry (evidence: `backend/services/agents/master_agent.py`)
- ReAct analysis agent → Groq LLM: uses model (evidence: `backend/services/agents/master_agent.py`)
- Analytics API → Database connection: queries data (evidence: `backend/api/analytics.py`)
- Telemetry and chat API → TimescaleDB: reads metrics (evidence: `README.md`)
- Admin dashboard → Telemetry and chat API: chats with agent (evidence: `README.md`)
