# alcytorres/pure_health architecture

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

- Interactive diagram: https://gitdiagram.com/alcytorres/pure_health
- Repository: https://github.com/alcytorres/pure_health

## Overview

##### Project Type & Overall Purpose
- The README clearly outlines both the user-facing features (dynamic calendar, date range filtering, statistical insights) and backend functionalities (data processing via Python libraries and CSV data storage).

##### Analyzing the File Structure
- Top-level Files:
- README.md: Provides project overview and installation/use instructions.
- app.py: The primary Flask application file handling server startup and route definitions.
- steps.py: Likely contains logic for step data analysis and/or ML prediction routines.
- CSV files (steps_data.csv, sleep_data.csv, hydration_data.csv, calorie_intake_data.csv, step_predictions.csv): Data storage and prediction files.
- Directories:
- static: Contains frontend JavaScript (script.js) and CSS (style.css), which support interactive and visual components.
- templates: Contains HTML files such as index.html, which are used by Flask to render views.
- Test Files: test.html, test.js, test.css, test.py may be used for testing components or UI prototypes.

##### Main Components of the System
A. Frontend Client:
- Web Browser: Where the UI (HTML/CSS/JS from the templates and static folders) loads and interacts with the user.
- Dynamic Visualizations: Handled using Chart.js integrated within the front-end JS.
B. Backend Server:
- Flask Application (app.py): Manages incoming HTTP requests, routing, and rendering web pages.
- Route Handlers/Controllers: Serve requests for different features such as steps, sleep, hydration, and calories.
- Machine Learning Component (steps.py): Processes step data, performs predictions (using Pandas, Scikit-learn, NumPy), and updates step_predictions.csv.
C. Data Storage:
- CSV Files: Act as a lightweight database for storing raw health data and prediction results.
D. External Dependencies:
- Python libraries: Flask (web framework), Pandas, Scikit-learn, NumPy (for data and ML).
- Node.js and npm modules (like Chart.js) for enhancing the user interface.

##### Relationships and Interactions
- User Interaction: The client browser makes HTTP requests to the Flask server.
- Flask Server Flow:
- app.py routes the requests to the appropriate controllers.
- Depending on the endpoint, controllers either render an HTML template or process data (read from CSV files, perform ML predictions).
- Data Flow:
- The backend reads from CSV files (steps_data.csv, sleep_data.csv, etc.) to feed data to views.
- For steps data, the ML module in steps.py generates predictions and writes to step_predictions.csv.
- Frontend Visualization: Static files (script.js, style.css) work with Chart.js to render interactive graphs based on the processed data from the Flask endpoints.

##### Additional Details
- Configuration or installation aspects lightly as annotations if needed, such as the dependency on Node.js/npm for charting support.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Client Layer
    subgraph "Client Layer"
        A("Frontend UI (HTML, CSS, JavaScript, Chart.js)"):::frontend
    end

    %% Frontend Assets
    subgraph "Frontend Assets"
        A1("HTML Template"):::frontendAsset
        A2("JavaScript"):::frontendAsset
        A3("CSS Styles"):::frontendAsset
    end
    A1 -.-> A
    A2 -.-> A
    A3 -.-> A

    %% Server/Backend Layer
    subgraph "Server/Backend Layer"
        B("Flask Server (app.py)"):::backend
        C("Route Handlers & Template Rendering"):::backend
        D("Machine Learning Module (steps.py)"):::backend
        B --> C
        B --> D
    end

    %% Backend Components
    subgraph "Backend Components"
        B1("Main Flask Application"):::backendComponent
    end
    B1 -.-> B

    subgraph "ML Component"
        D1("Step Prediction Logic"):::mlComponent
    end
    D1 -.-> D

    %% Data Storage Layer
    subgraph "Data Storage Layer"
        E("Steps Data (steps_data.csv)"):::datastore
        F("Sleep Data (sleep_data.csv)"):::datastore
        G("Hydration Data (hydration_data.csv)"):::datastore
        H("Calorie Intake Data (calorie_intake_data.csv)"):::datastore
        I("Step Predictions (step_predictions.csv)"):::datastore
    end

    subgraph "CSV Data Files"
        E1("Steps Data"):::csv
        F1("Sleep Data"):::csv
        G1("Hydration Data"):::csv
        H1("Calorie Intake Data"):::csv
        I1("Step Predictions"):::csv
    end
    E1 -.-> E
    F1 -.-> F
    G1 -.-> G
    H1 -.-> H
    I1 -.-> I

    %% External Dependencies
    subgraph "External Dependencies"
         X("Python Libraries (Flask, Pandas, Scikit-Learn, NumPy)"):::external
         Y("Frontend Libraries (Chart.js via Node/npm)"):::external
    end

    %% Documentation
    subgraph "Documentation"
        DDoc("Project Overview"):::doc
    end

    %% Data Flow Arrows
    A -->|"HTTP_request"| B
    C -->|"renders"| A
    C -->|"reads"| E
    C -->|"reads"| F
    C -->|"reads"| G
    C -->|"reads"| H
    D -->|"reads"| E
    E -->|"supplies_data"| D
    D -->|"writes"| I

    %% Error Logging Annotation
    note1["Error Logging (Console)"]:::backend
    B --> note1

    %% Click Events for Frontend Assets
    click A1 "https://github.com/alcytorres/pure_health/blob/main/templates/index.html"
    click A2 "https://github.com/alcytorres/pure_health/blob/main/static/script.js"
    click A3 "https://github.com/alcytorres/pure_health/blob/main/static/style.css"

    %% Click Events for Backend Components
    click B1 "https://github.com/alcytorres/pure_health/blob/main/app.py"
    
    %% Click Events for ML Component
    click D1 "https://github.com/alcytorres/pure_health/blob/main/steps.py"

    %% Click Events for CSV Files
    click E1 "https://github.com/alcytorres/pure_health/blob/main/steps_data.csv"
    click F1 "https://github.com/alcytorres/pure_health/blob/main/sleep_data.csv"
    click G1 "https://github.com/alcytorres/pure_health/blob/main/hydration_data.csv"
    click H1 "https://github.com/alcytorres/pure_health/blob/main/calorie_intake_data.csv"
    click I1 "https://github.com/alcytorres/pure_health/blob/main/step_predictions.csv"

    %% Click Event for Documentation
    click DDoc "https://github.com/alcytorres/pure_health/blob/main/README.md"

    %% Class Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef frontendAsset fill:#B0E0E6,stroke:#000,stroke-width:1px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef backendComponent fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef mlComponent fill:#98FB98,stroke:#000,stroke-width:1px;
    classDef datastore fill:#FFDAB9,stroke:#000,stroke-width:2px;
    classDef csv fill:#FFEFD5,stroke:#000,stroke-width:1px;
    classDef external fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef doc fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
