# aarzusharma07/safespace---ai-stress-detection architecture

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

- Interactive diagram: https://gitdiagram.com/aarzusharma07/safespace---ai-stress-detection
- Repository: https://github.com/aarzusharma07/safespace---ai-stress-detection

## Overview

SafeSpace combines account access with separate webcam, voice, survey, and physiological-sensor experiences. The central user workflow is to enter the web app, submit one or more modalities for analysis, and view or retrieve stress-related results; webcam and survey services explicitly persist results, while the sampled voice service returns a prediction. The README documents the multimodal design, but the repository contains multiple Flask entry points and the sampled services do not establish one unified end-to-end result pipeline. Some branches are therefore shown only where source or README evidence supports them.

Main entry points: [`login.php`](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/login.php) (Login), [`config.php`](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/config.php) (DB connection), [`home.php`](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/home.php) (Home dashboard), [`templates/webcam.html`](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/templates/webcam.html) (Webcam interface)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_accounts["Accounts and access"]
  node_auth_pages["Account forms<br/>[login.html]"]
  node_login["Login<br/>[login.php]"]
  node_register["Registration<br/>[register.php]"]
  node_db_config["DB connection<br/>[config.php]"]
  node_account_store[("Accounts database")]
  node_home["Home dashboard<br/>[home.php]"]
end

subgraph group_analysis["Stress analysis"]
  node_webcam_ui["Webcam interface<br/>[webcam.html]"]
  node_webcam_service["Webcam inference<br/>[app.py]"]
  node_webcam_api["Frame detection API<br/>[server.py]"]
  node_voice_service["Voice stress analysis"]
  node_keras_helpers["Keras custom ops<br/>[custom_objects.py]"]
  node_emotion_model["Emotion recognition<br/>[emotiondetect.py]"]
end

subgraph group_results["Results and surveys"]
  node_survey_ui["Survey interface<br/>[survey.html]"]
  node_stress_form["Stress form API<br/>[app.py]"]
  node_survey_api["Survey and latest results API<br/>[survey_api.py]"]
  node_results_store[("Detection results database")]
end

subgraph group_sensors["Physiological sensors"]
  node_sensor_ui["Sensor dashboard<br/>[hardware.html]"]
  node_sensor_bridge["MQTT and Socket.IO bridge<br/>[script.js]"]
end

node_person(("User"))
node_mqtt_broker(("MQTT broker"))

node_person -->|"uses"| node_auth_pages
node_auth_pages -->|"submits to"| node_login
node_login -->|"includes"| node_db_config
node_register -->|"includes"| node_db_config
node_db_config -->|"connects to"| node_account_store
node_login -->|"queries"| node_account_store
node_register -->|"queries and inserts"| node_account_store
node_login -->|"redirects to"| node_home
node_person -->|"opens"| node_home
node_home -->|"links to"| node_webcam_ui
node_person -->|"uses"| node_webcam_ui
node_webcam_ui -->|"served by"| node_webcam_service
node_person -->|"uploads frame"| node_webcam_api
node_webcam_api -->|"inserts detections"| node_results_store
node_person -->|"submits audio"| node_voice_service
node_voice_service -->|"loads custom ops"| node_keras_helpers
node_person -.->|"uses webcam"| node_emotion_model
node_person -->|"submits survey"| node_survey_ui
node_survey_ui -.->|"posts answers"| node_survey_api
node_person -->|"submits responses"| node_stress_form
node_stress_form -->|"inserts prediction"| node_results_store
node_survey_api -->|"updates and reads"| node_results_store
node_person -->|"views sensor data"| node_sensor_ui
node_sensor_ui -->|"receives events"| node_sensor_bridge
node_mqtt_broker -->|"publishes messages"| node_sensor_bridge

click node_auth_pages "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/login.html"
click node_login "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/login.php"
click node_register "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/register.php"
click node_db_config "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/config.php"
click node_home "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/home.php"
click node_webcam_ui "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/templates/webcam.html"
click node_webcam_service "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/templates/app.py"
click node_webcam_api "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/server.py"
click node_voice_service "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/read_and_predict.py"
click node_keras_helpers "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/custom_objects.py"
click node_emotion_model "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/emotiondetect.py"
click node_survey_ui "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/static/survey.html"
click node_stress_form "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/app.py"
click node_survey_api "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/survey_api.py"
click node_sensor_ui "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/public/hardware.html"
click node_sensor_bridge "https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/script.js"

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_auth_pages,node_login,node_register,node_db_config,node_account_store,node_home,node_person toneBlue
class node_webcam_ui,node_webcam_service,node_webcam_api,node_voice_service,node_keras_helpers,node_emotion_model toneAmber
class node_survey_ui,node_stress_form,node_survey_api,node_results_store toneMint
class node_sensor_ui,node_sensor_bridge toneRose
class node_mqtt_broker toneIndigo
```

## Components

### Accounts and access

- [Account forms](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/login.html): `login.html`
- [Login](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/login.php): `login.php`
- [Registration](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/register.php): `register.php`
- [DB connection](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/config.php): `config.php`
- **Accounts database**
- [Home dashboard](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/home.php): `home.php`

### Stress analysis

- [Webcam interface](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/templates/webcam.html): `templates/webcam.html`
- [Webcam inference](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/templates/app.py): `templates/app.py`
- [Frame detection API](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/server.py): `server.py`
- [Voice stress analysis](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/read_and_predict.py): `read_and_predict.py`
- [Keras custom ops](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/custom_objects.py): `custom_objects.py`
- [Emotion recognition](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/emotiondetect.py): `emotiondetect.py`

### Results and surveys

- [Survey interface](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/static/survey.html): `static/survey.html`
- [Stress form API](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/app.py): `app.py`
- [Survey and latest results API](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/survey_api.py): `survey_api.py`
- **Detection results database**

### Physiological sensors

- [Sensor dashboard](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/public/hardware.html): `public/hardware.html`
- [MQTT and Socket.IO bridge](https://github.com/aarzusharma07/safespace---ai-stress-detection/blob/main/script.js): `script.js`

### Other components

- **User**
- **MQTT broker**

## Connections

- User → Account forms: uses (evidence: `README.md`)
- Account forms → Login: submits to (evidence: `login.php`)
- Login → DB connection: includes (evidence: `login.php`)
- Registration → DB connection: includes (evidence: `register.php`)
- DB connection → Accounts database: connects to (evidence: `config.php`)
- Login → Accounts database: queries (evidence: `login.php`)
- Registration → Accounts database: queries and inserts (evidence: `register.php`)
- Login → Home dashboard: redirects to (evidence: `login.php`)
- User → Home dashboard: opens (evidence: `home.php`)
- Home dashboard → Webcam interface: links to (evidence: `home.php`)
- User → Webcam interface: uses (evidence: `README.md`)
- Webcam interface → Webcam inference: served by (evidence: `templates/app.py`)
- User → Frame detection API: uploads frame (evidence: `server.py`)
- Frame detection API → Detection results database: inserts detections (evidence: `server.py`)
- User → Voice stress analysis: submits audio (evidence: `read_and_predict.py`)
- Voice stress analysis → Keras custom ops: loads custom ops (evidence: `read_and_predict.py`)
- User → Emotion recognition: uses webcam (evidence: `README.md`)
- User → Survey interface: submits survey (evidence: `README.md`)
- Survey interface → Survey and latest results API: posts answers
- User → Stress form API: submits responses (evidence: `app.py`)
- Stress form API → Detection results database: inserts prediction (evidence: `app.py`)
- Survey and latest results API → Detection results database: updates and reads (evidence: `survey_api.py`)
- User → Sensor dashboard: views sensor data (evidence: `README.md`)
- Sensor dashboard → MQTT and Socket.IO bridge: receives events (evidence: `script.js`)
- MQTT broker → MQTT and Socket.IO bridge: publishes messages (evidence: `script.js`)
