# yuvraj-dhepe/hackhpi2025-tone-down architecture

> Architecture diagram of the GitHub repository yuvraj-dhepe/hackhpi2025-tone-down, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/yuvraj-dhepe/hackhpi2025-tone-down
- Repository: https://github.com/yuvraj-dhepe/hackhpi2025-tone-down

## Overview

##### A React Native frontend (found under the ToneDown directory).
2. A Flask backend (under flask_backend) that serves as the API between the mobile app and the statistical modeling.
3. A statistical modeling module (located in the backend directory) which uses Bayesian hierarchical models (including a Stan model) for personalized intervention recommendations.

##### Main Components
- Frontend (React Native):
- ToneDown app as the mobile client.
- UI components such as screens, navigational components (Expo Router), and assets (images, fonts).
- Mention supporting modules like storage and utility files.

- Backend (Flask API Server):
- Flask backend (flask_backend directory) responsible for handling API requests.
- Components like routing (app.py), middleware (e.g., use of Flask-CORS), and data processing using libraries like Pandas.

- Statistical Modeling:
- Statistical module as a separate service/component.
- Files such as backend_wrapper.py, single_user_sampler.py, hierarchical_sampler.py, and the Stan model (hier_reg.stan).
- Integration with CmdStan for Bayesian inference.

##### Communication Flows
- Optionally, include feedback loops where the statistical model outputs updated recommendations that the Backend then communicates back to the Frontend.

##### Architectural Patterns
- That the project uses a clear separation of concerns:
- A decoupled mobile client (React Native, Expo) from the server (Flask).
- A clear data-processing and statistical modeling layer.
- Mention that data flows via RESTful API endpoints and that asynchronous data storage (using AsyncStorage and SecureStore on the frontend) is used.

##### Relevant Technologies
- Under the Frontend side, list “React Native, Expo Router, AsyncStorage, Secure Store.”
- For the Backend, add “Flask, Flask-CORS, Pandas, JSON.”
- For the Statistical Modeling, list “CmdStan, Stan modeling language, Python (wrappers), Bayesian Hierarchical Models.”

## Diagram (Mermaid)

```mermaid
graph TD

%% Frontend Layer
subgraph "Mobile Frontend (React Native)"
    FE_Main["Mobile App (React Native)"]:::frontend
    FE_UI["UI Components&Navigation (ExpoRouter)"]:::frontend
    FE_Assets["Assets (Images&Fonts)"]:::frontend
    FE_Storage["AsyncStorage&SecureStore"]:::frontend
end

%% Backend Layer
subgraph "Backend API Server (Flask)"
    BE_API["API Server (Flask)"]:::backend
    BE_Routes["Routing (app.py)"]:::backend
    BE_Middleware["Middleware (Flask-CORS)"]:::backend
    BE_Data["Data Processing (Pandas&JSON)"]:::backend
end

%% Statistical Modeling Layer
subgraph "Statistical Modeling Service"
    SM_Service["Statistical Modeling Module"]:::modeling
    SM_Wrapper["Wrapper (backend_wrapper.py)"]:::modeling
    SM_Hierarchical["Hierarchical Sampler (hierarchical_sampler.py)"]:::modeling
    SM_Single["Single-user Sampler (single_user_sampler.py)"]:::modeling
    SM_Stan["Stan Model (hier_reg.stan)"]:::modeling
    SM_Tech["CmdStan&BayesianModels"]:::modeling
end

%% Data Flow Connections
FE_Main -->|"APIRequest"| BE_API
BE_API -->|"ModelingCall"| SM_Service
SM_Service -->|"InferenceResults"| BE_API
BE_API -->|"Response"| FE_Main

%% Internal Frontend Connections
FE_Main --> FE_UI
FE_Main --> FE_Assets
FE_Main --> FE_Storage

%% Internal Backend Connections
BE_API --> BE_Routes
BE_API --> BE_Middleware
BE_API --> BE_Data

%% Internal Statistical Modeling Connections
SM_Service --> SM_Wrapper
SM_Service --> SM_Hierarchical
SM_Service --> SM_Single
SM_Service --> SM_Stan
SM_Service --> SM_Tech

%% Click Events
click FE_Main "https://github.com/yuvraj-dhepe/hackhpi2025-tone-down/tree/main/ToneDown/"
click BE_Routes "https://github.com/yuvraj-dhepe/hackhpi2025-tone-down/blob/main/flask_backend/app.py"
click SM_Wrapper "https://github.com/yuvraj-dhepe/hackhpi2025-tone-down/blob/main/backend/backend_wrapper.py"
click SM_Hierarchical "https://github.com/yuvraj-dhepe/hackhpi2025-tone-down/blob/main/backend/hierarchical_sampler.py"
click SM_Single "https://github.com/yuvraj-dhepe/hackhpi2025-tone-down/blob/main/backend/single_user_sampler.py"
click SM_Stan "https://github.com/yuvraj-dhepe/hackhpi2025-tone-down/blob/main/backend/hier_reg/hier_reg.stan"

%% Styles
classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
classDef backend fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
classDef modeling fill:#FFE0B2,stroke:#E65100,stroke-width:2px;
```
