# rehaan98/stressapplication architecture

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

- Interactive diagram: https://gitdiagram.com/rehaan98/stressapplication
- Repository: https://github.com/rehaan98/stressapplication

## Overview

Psychological Stress AI is a full-stack stress-assessment and self-awareness platform. Users submit questionnaire, physiological, lifestyle, voice, or facial inputs; the platform analyzes stress, presents predictions and explanations, and can offer tailored coping interventions. Other documented capabilities include conversation support, analytics and CSV export, authentication/RBAC, and administration. The map distinguishes the web experience, API, backend services and data, and ML capabilities. Some endpoint-to-service and browser-to-API links are not shown in sampled source; those links are dashed rather than asserted as verified calls.

Main entry points: [`backend/app/api/v1/api.py`](https://github.com/rehaan98/stressapplication/blob/main/backend/app/api/v1/api.py) (Versioned routes), [`ml_engine/predict.py`](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/predict.py) (Stress prediction), [`frontend/src/app`](https://github.com/rehaan98/stressapplication/tree/main/frontend/src/app) (Web pages), [`ml_engine/src/model_trainer.py`](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/model_trainer.py) (Model training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_webapp["Web pages"]
  node_webcomponents["Interactive panels"]
  node_api_client["Browser API client<br/>[api.ts]"]
end

subgraph group_api["API and access"]
  node_app["FastAPI application<br/>[main.py]"]
  node_routes["Versioned routes<br/>[api.py]"]
end

subgraph group_domain["Assessment services"]
  node_auth["Authentication<br/>[auth_service.py]"]
  node_conversation["Conversation support<br/>[manager.py]"]
  node_voice["Voice analysis<br/>[voice_service.py]"]
  node_language["Voice language analysis<br/>[voice_language.py]"]
  node_fusion["Stress modality fusion<br/>[stress_engine.py]"]
  node_facial["Facial emotion analysis<br/>[facial_service.py]"]
  node_multimodal["Multimodal assessment<br/>[multimodal.py]"]
  node_analytics["Analytics and reports"]
end

subgraph group_ml["ML and interventions"]
  node_predictor["Stress prediction<br/>[predict.py]"]
  node_features["Feature engineering"]
  node_preprocessing["Data preprocessing"]
  node_training["Model training<br/>[model_trainer.py]"]
  node_explainability["SHAP and LIME<br/>[explainable_ai.py]"]
  node_ragservice["Coping interventions<br/>[rag_service.py]"]
  node_ragengine["Intervention retrieval<br/>[rag_engine.py]"]
  node_dataset["Synthetic training data"]
end

subgraph group_data["Persistence"]
  node_dbsession["Database sessions<br/>[database.py]"]
  node_models[("Assessment records")]
end

node_user(("Platform user"))

node_user -->|"uses"| node_webapp
node_webapp -.->|"renders"| node_webcomponents
node_webapp -.->|"requests data"| node_api_client
node_api_client -.->|"sends requests"| node_routes
node_app -->|"mounts routes"| node_routes
node_routes -.->|"routes auth"| node_auth
node_routes -.->|"routes conversation"| node_conversation
node_routes -.->|"routes voice"| node_voice
node_routes -.->|"routes facial"| node_facial
node_routes -.->|"routes assessment"| node_multimodal
node_routes -.->|"routes analytics"| node_analytics
node_voice -->|"uses analysis"| node_language
node_fusion -->|"analyzes audio"| node_voice
node_fusion -.->|"wraps visual result"| node_facial
node_multimodal -.->|"combines modalities"| node_fusion
node_predictor -->|"engineers inputs"| node_features
node_predictor -->|"preprocesses inputs"| node_preprocessing
node_predictor -->|"explains prediction"| node_explainability
node_predictor -->|"retrieves interventions"| node_ragengine
node_ragservice -->|"retrieves interventions"| node_ragengine
node_ragservice -->|"reads and logs"| node_models
node_app -->|"initializes tables"| node_dbsession
node_dbsession -->|"provides ORM base"| node_models
node_dataset -->|"supplies training data"| node_training
node_training -->|"engineers training features"| node_features
node_training -->|"preprocesses training data"| node_preprocessing
node_user -.->|"receives stress results"| node_predictor
node_user -.->|"requests coping guidance"| node_ragservice

click node_webapp "https://github.com/rehaan98/stressapplication/tree/main/frontend/src/app"
click node_webcomponents "https://github.com/rehaan98/stressapplication/tree/main/frontend/src/components"
click node_api_client "https://github.com/rehaan98/stressapplication/blob/main/frontend/src/lib/api.ts"
click node_app "https://github.com/rehaan98/stressapplication/blob/main/backend/app/main.py"
click node_routes "https://github.com/rehaan98/stressapplication/blob/main/backend/app/api/v1/api.py"
click node_auth "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/auth_service.py"
click node_conversation "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/conversation/manager.py"
click node_voice "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/voice_service.py"
click node_language "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/voice_language.py"
click node_fusion "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/stress_engine.py"
click node_facial "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/facial_service.py"
click node_multimodal "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/multimodal.py"
click node_analytics "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/analytics_service.py"
click node_predictor "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/predict.py"
click node_features "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/feature_engineering.py"
click node_preprocessing "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/data_preprocessing.py"
click node_training "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/model_trainer.py"
click node_explainability "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/explainable_ai.py"
click node_ragservice "https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/rag_service.py"
click node_ragengine "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/rag_engine.py"
click node_dbsession "https://github.com/rehaan98/stressapplication/blob/main/backend/app/core/database.py"
click node_models "https://github.com/rehaan98/stressapplication/tree/main/backend/app/models"
click node_dataset "https://github.com/rehaan98/stressapplication/blob/main/ml_engine/data/generate_synthetic_stress_dataset.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_webapp,node_webcomponents,node_api_client,node_user toneBlue
class node_app,node_routes toneAmber
class node_auth,node_conversation,node_voice,node_language,node_fusion,node_facial,node_multimodal,node_analytics toneMint
class node_predictor,node_features,node_preprocessing,node_training,node_explainability,node_ragservice,node_ragengine,node_dataset toneRose
class node_dbsession,node_models toneIndigo
```

## Components

### Web experience

- [Web pages](https://github.com/rehaan98/stressapplication/tree/main/frontend/src/app): `frontend/src/app`
- [Interactive panels](https://github.com/rehaan98/stressapplication/tree/main/frontend/src/components): `frontend/src/components`
- [Browser API client](https://github.com/rehaan98/stressapplication/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### API and access

- [FastAPI application](https://github.com/rehaan98/stressapplication/blob/main/backend/app/main.py): `backend/app/main.py`
- [Versioned routes](https://github.com/rehaan98/stressapplication/blob/main/backend/app/api/v1/api.py): `backend/app/api/v1/api.py`

### Assessment services

- [Authentication](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/auth_service.py): `backend/app/services/auth_service.py`
- [Conversation support](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/conversation/manager.py): `backend/app/services/conversation/manager.py`
- [Voice analysis](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/voice_service.py): `backend/app/services/voice_service.py`
- [Voice language analysis](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/voice_language.py): `backend/app/services/voice_language.py`
- [Stress modality fusion](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/stress_engine.py): `backend/app/services/stress_engine.py`
- [Facial emotion analysis](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/facial_service.py): `backend/app/services/facial_service.py`
- [Multimodal assessment](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/multimodal.py): `backend/app/services/multimodal.py`
- [Analytics and reports](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/analytics_service.py): `backend/app/services/analytics_service.py`

### ML and interventions

- [Stress prediction](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/predict.py): `ml_engine/predict.py`
- [Feature engineering](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/feature_engineering.py): `ml_engine/src/feature_engineering.py`
- [Data preprocessing](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/data_preprocessing.py): `ml_engine/src/data_preprocessing.py`
- [Model training](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/model_trainer.py): `ml_engine/src/model_trainer.py`
- [SHAP and LIME](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/explainable_ai.py): `ml_engine/src/explainable_ai.py`
- [Coping interventions](https://github.com/rehaan98/stressapplication/blob/main/backend/app/services/rag_service.py): `backend/app/services/rag_service.py`
- [Intervention retrieval](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/src/rag_engine.py): `ml_engine/src/rag_engine.py`
- [Synthetic training data](https://github.com/rehaan98/stressapplication/blob/main/ml_engine/data/generate_synthetic_stress_dataset.py): `ml_engine/data/generate_synthetic_stress_dataset.py`

### Persistence

- [Database sessions](https://github.com/rehaan98/stressapplication/blob/main/backend/app/core/database.py): `backend/app/core/database.py`
- [Assessment records](https://github.com/rehaan98/stressapplication/tree/main/backend/app/models): `backend/app/models`

### Other components

- **Platform user**

## Connections

- Platform user → Web pages: uses (evidence: `README.md`)
- Web pages → Interactive panels: renders
- Web pages → Browser API client: requests data
- Browser API client → Versioned routes: sends requests
- FastAPI application → Versioned routes: mounts routes (evidence: `backend/app/main.py`)
- Versioned routes → Authentication: routes auth
- Versioned routes → Conversation support: routes conversation
- Versioned routes → Voice analysis: routes voice
- Versioned routes → Facial emotion analysis: routes facial
- Versioned routes → Multimodal assessment: routes assessment
- Versioned routes → Analytics and reports: routes analytics
- Voice analysis → Voice language analysis: uses analysis (evidence: `backend/app/services/voice_service.py`)
- Stress modality fusion → Voice analysis: analyzes audio (evidence: `backend/app/services/stress_engine.py`)
- Stress modality fusion → Facial emotion analysis: wraps visual result
- Multimodal assessment → Stress modality fusion: combines modalities
- Stress prediction → Feature engineering: engineers inputs (evidence: `ml_engine/predict.py`)
- Stress prediction → Data preprocessing: preprocesses inputs (evidence: `ml_engine/predict.py`)
- Stress prediction → SHAP and LIME: explains prediction (evidence: `ml_engine/predict.py`)
- Stress prediction → Intervention retrieval: retrieves interventions (evidence: `ml_engine/predict.py`)
- Coping interventions → Intervention retrieval: retrieves interventions (evidence: `backend/app/services/rag_service.py`)
- Coping interventions → Assessment records: reads and logs (evidence: `backend/app/services/rag_service.py`)
- FastAPI application → Database sessions: initializes tables (evidence: `backend/app/main.py`)
- Database sessions → Assessment records: provides ORM base (evidence: `backend/app/core/database.py`)
- Synthetic training data → Model training: supplies training data (evidence: `ml_engine/src/train_pipeline.py`)
- Model training → Feature engineering: engineers training features (evidence: `ml_engine/src/train_pipeline.py`)
- Model training → Data preprocessing: preprocesses training data (evidence: `ml_engine/src/train_pipeline.py`)
- Platform user → Stress prediction: receives stress results
- Platform user → Coping interventions: requests coping guidance
