# rohithsuresh21/mental-health-digital-twin-ai-assistant architecture

> Architecture diagram of the GitHub repository rohithsuresh21/mental-health-digital-twin-ai-assistant, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rohithsuresh21/mental-health-digital-twin-ai-assistant
- Repository: https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant

## Overview

Mental Health Digital Twin is a local-first mental-health monitoring and early-warning product. The patient workflow is daily check-in or chat import, feature extraction, personal baseline calibration, forecasting and anomaly analysis, clinical risk classification, then explanations and patient-facing results. The graph separates the daily portal and persistent records from the analysis pipeline, and includes the guide and PDF output as documented product capabilities. Some subsystem links rely on README descriptions or the SOURCE INDEX; unsampled implementation details are not inferred.

Main entry points: [`unified_pipeline.py`](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/unified_pipeline.py) (Pipeline Orchestrator), [`daily_portal/routes.py`](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/routes.py) (Daily Portal API), [`User Interface/src/App.tsx`](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/App.tsx) (Patient App), [`app.py`](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/app.py) (Flask API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_portal["Patient Portal"]
  node_ui["Patient App<br/>[App.tsx]"]
  node_intake_ui["Check-in &amp; Import"]
  node_telemetry["Patient Data View"]
  node_data_hook["Patient Data Hook<br/>[usePatientData.ts]"]
end

subgraph group_intake["Data Intake"]
  node_daily_routes["Daily Portal API<br/>[routes.py]"]
  node_parsers["Chat Import Parsers"]
  node_records[("Daily Records<br/>[db.py]")]
  node_dataset["Record Assembly<br/>[dataset.py]"]
end

subgraph group_analysis["Analysis Pipeline"]
  node_features["Feature Extraction"]
  node_baseline["Personal Baseline<br/>[baseline.py]"]
  node_binning["Temporal Binning<br/>[temporal_bin.py]"]
  node_forecast["Risk Forecasting<br/>[tft_model.py]"]
  node_anomaly["Anomaly Ensemble"]
  node_classifier["Risk Classification<br/>[inference.py]"]
  node_orchestrator["Pipeline Orchestrator"]
  node_runner["Analysis Runner<br/>[pipeline_runner.py]"]
end

subgraph group_interpretation["Results &amp; Guidance"]
  node_xai["Feature Explanations<br/>[XAI.py]"]
  node_pdf["Medical Summary PDF<br/>[pdf_generator.py]"]
  node_results["Analysis Results<br/>[ResultsPage.tsx]"]
  node_explain["Explanation View<br/>[ExplainPage.tsx]"]
  node_forecast_view["Forecast View<br/>[ForecastPage.tsx]"]
  node_guide["Offline Guide<br/>[Guide.tsx]"]
end

subgraph group_runtime["Local Runtime"]
  node_flask["Flask API<br/>[app.py]"]
  node_desktop["Desktop Launcher<br/>[server.py]"]
end

node_patient(("Patient"))

node_patient -->|"enters check-ins"| node_intake_ui
node_intake_ui -->|"submits entries"| node_daily_routes
node_patient -->|"imports chats"| node_parsers
node_daily_routes -->|"parses imports"| node_parsers
node_daily_routes -->|"saves entries"| node_records
node_daily_routes -->|"extracts features"| node_features
node_daily_routes -->|"refreshes baseline"| node_baseline
node_dataset -->|"reads entries"| node_records
node_ui -->|"renders portal"| node_intake_ui
node_ui -->|"loads patient data"| node_data_hook
node_data_hook -->|"requests status"| node_daily_routes
node_telemetry -->|"uses patient data"| node_data_hook
node_flask -->|"registers portal API"| node_daily_routes
node_flask -->|"runs analysis"| node_runner
node_runner -->|"uses assembled records"| node_dataset
node_runner -->|"runs pipeline"| node_orchestrator
node_orchestrator -->|"extracts vectors"| node_features
node_orchestrator -->|"normalizes vectors"| node_baseline
node_orchestrator -->|"bins entries"| node_binning
node_orchestrator -->|"forecasts risk"| node_forecast
node_orchestrator -->|"scores anomalies"| node_anomaly
node_orchestrator -.->|"classifies risk"| node_classifier
node_orchestrator -->|"generates attributions"| node_xai
node_flask -->|"generates summary"| node_pdf
node_ui -->|"shows results"| node_results
node_ui -->|"shows explanations"| node_explain
node_ui -->|"shows forecasts"| node_forecast_view
node_ui -->|"opens guide"| node_guide
node_desktop -->|"serves locally"| node_flask

click node_ui "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/App.tsx"
click node_intake_ui "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/components/PatientIntakePortal.tsx"
click node_telemetry "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/components/PatientTelemetry.tsx"
click node_data_hook "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/hooks/usePatientData.ts"
click node_daily_routes "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/routes.py"
click node_parsers "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/tree/main/data_parser"
click node_records "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/db.py"
click node_dataset "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/dataset.py"
click node_features "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/Stage_1/Extract_features.py"
click node_baseline "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_2/baseline.py"
click node_binning "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_2/temporal_bin.py"
click node_forecast "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_3/tft_model.py"
click node_anomaly "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_4/anomaly_pipeline.py"
click node_classifier "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/Stage_5/inference.py"
click node_orchestrator "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/unified_pipeline.py"
click node_runner "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/pipeline_runner.py"
click node_xai "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/XAI/XAI.py"
click node_pdf "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/pdf_generator.py"
click node_results "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/insights/ResultsPage.tsx"
click node_explain "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/insights/ExplainPage.tsx"
click node_forecast_view "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/insights/ForecastPage.tsx"
click node_guide "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/guide/Guide.tsx"
click node_flask "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/app.py"
click node_desktop "https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/desktop/server.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_ui,node_intake_ui,node_telemetry,node_data_hook toneBlue
class node_daily_routes,node_parsers,node_records,node_dataset toneAmber
class node_features,node_baseline,node_binning,node_forecast,node_anomaly,node_classifier,node_orchestrator,node_runner toneMint
class node_xai,node_pdf,node_results,node_explain,node_forecast_view,node_guide toneRose
class node_flask,node_desktop,node_patient toneIndigo
```

## Components

### Patient Portal

- [Patient App](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/App.tsx): `User Interface/src/App.tsx`
- [Check-in & Import](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/components/PatientIntakePortal.tsx): `User Interface/src/components/PatientIntakePortal.tsx`
- [Patient Data View](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/components/PatientTelemetry.tsx): `User Interface/src/components/PatientTelemetry.tsx`
- [Patient Data Hook](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/hooks/usePatientData.ts): `User Interface/src/hooks/usePatientData.ts`

### Data Intake

- [Daily Portal API](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/routes.py): `daily_portal/routes.py`
- [Chat Import Parsers](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/tree/main/data_parser): `data_parser`
- [Daily Records](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/db.py): `daily_portal/db.py`
- [Record Assembly](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/daily_portal/dataset.py): `daily_portal/dataset.py`

### Analysis Pipeline

- [Feature Extraction](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/Stage_1/Extract_features.py): `Stage_1/Extract_features.py`
- [Personal Baseline](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_2/baseline.py): `stage_2/baseline.py`
- [Temporal Binning](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_2/temporal_bin.py): `stage_2/temporal_bin.py`
- [Risk Forecasting](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_3/tft_model.py): `stage_3/tft_model.py`
- [Anomaly Ensemble](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/stage_4/anomaly_pipeline.py): `stage_4/anomaly_pipeline.py`
- [Risk Classification](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/Stage_5/inference.py): `Stage_5/inference.py`
- [Pipeline Orchestrator](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/unified_pipeline.py): `unified_pipeline.py`
- [Analysis Runner](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/pipeline_runner.py): `pipeline_runner.py`

### Results & Guidance

- [Feature Explanations](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/XAI/XAI.py): `XAI/XAI.py`
- [Medical Summary PDF](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/pdf_generator.py): `pdf_generator.py`
- [Analysis Results](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/insights/ResultsPage.tsx): `User Interface/src/insights/ResultsPage.tsx`
- [Explanation View](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/insights/ExplainPage.tsx): `User Interface/src/insights/ExplainPage.tsx`
- [Forecast View](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/insights/ForecastPage.tsx): `User Interface/src/insights/ForecastPage.tsx`
- [Offline Guide](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/User%20Interface/src/guide/Guide.tsx): `User Interface/src/guide/Guide.tsx`

### Local Runtime

- [Flask API](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/app.py): `app.py`
- [Desktop Launcher](https://github.com/rohithsuresh21/mental-health-digital-twin-ai-assistant/blob/main/desktop/server.py): `desktop/server.py`

### Other components

- **Patient**

## Connections

- Patient → Check-in & Import: enters check-ins (evidence: `README.md`)
- Check-in & Import → Daily Portal API: submits entries (evidence: `README.md`)
- Patient → Chat Import Parsers: imports chats (evidence: `README.md`)
- Daily Portal API → Chat Import Parsers: parses imports (evidence: `daily_portal/routes.py`)
- Daily Portal API → Daily Records: saves entries (evidence: `daily_portal/routes.py`)
- Daily Portal API → Feature Extraction: extracts features (evidence: `daily_portal/routes.py`)
- Daily Portal API → Personal Baseline: refreshes baseline (evidence: `daily_portal/routes.py`)
- Record Assembly → Daily Records: reads entries (evidence: `daily_portal/dataset.py`)
- Patient App → Check-in & Import: renders portal (evidence: `User Interface/src/App.tsx`)
- Patient App → Patient Data Hook: loads patient data (evidence: `User Interface/src/App.tsx`)
- Patient Data Hook → Daily Portal API: requests status (evidence: `User Interface/src/hooks/usePatientData.ts`)
- Patient Data View → Patient Data Hook: uses patient data (evidence: `User Interface/src/components/PatientTelemetry.tsx`)
- Flask API → Daily Portal API: registers portal API (evidence: `app.py`)
- Flask API → Analysis Runner: runs analysis (evidence: `app.py`)
- Analysis Runner → Record Assembly: uses assembled records (evidence: `pipeline_runner.py`)
- Analysis Runner → Pipeline Orchestrator: runs pipeline (evidence: `pipeline_runner.py`)
- Pipeline Orchestrator → Feature Extraction: extracts vectors (evidence: `unified_pipeline.py`)
- Pipeline Orchestrator → Personal Baseline: normalizes vectors (evidence: `unified_pipeline.py`)
- Pipeline Orchestrator → Temporal Binning: bins entries (evidence: `unified_pipeline.py`)
- Pipeline Orchestrator → Risk Forecasting: forecasts risk (evidence: `unified_pipeline.py`)
- Pipeline Orchestrator → Anomaly Ensemble: scores anomalies (evidence: `unified_pipeline.py`)
- Pipeline Orchestrator → Risk Classification: classifies risk (evidence: `README.md`)
- Pipeline Orchestrator → Feature Explanations: generates attributions (evidence: `unified_pipeline.py`)
- Flask API → Medical Summary PDF: generates summary (evidence: `app.py`)
- Patient App → Analysis Results: shows results (evidence: `User Interface/src/App.tsx`)
- Patient App → Explanation View: shows explanations (evidence: `User Interface/src/App.tsx`)
- Patient App → Forecast View: shows forecasts (evidence: `User Interface/src/App.tsx`)
- Patient App → Offline Guide: opens guide (evidence: `User Interface/src/App.tsx`)
- Desktop Launcher → Flask API: serves locally (evidence: `desktop/server.py`)
