# mrsheldont/protecvida architecture

> Architecture diagram of the GitHub repository mrsheldont/protecvida, 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/mrsheldont/protecvida
- Repository: https://github.com/mrsheldont/protecvida

## Overview

##### Main Components
- BLE & Device Layer: Although not directly shown in the file structure, the README explains that the application connects to BLE-enabled devices for monitoring vital signs. Represent these external devices (e.g., wearables, smartwatches) as one component.
- API Layer (Flask-API): In the file tree, notice the “Flask-API” folder that contains the main application logic (configuration, models, routes, utilities). This layer is responsible for handling requests coming from the BLE devices (directly or via an intermediary mobile app) and for serving RESTful endpoints.
- (Optionally) Notification & External Services: From the README, it’s clear that one of the core features is alerting family members in emergencies. Represent any external notification systems or third-party services that may be used for sending alerts (e.g., SMS gateways, push notification services).

##### Relationships and Interactions
- Data flow from the Database back to the API, such as fetching patient profiles, filter conditions, and historical vital signs for analysis or generating alerts.

##### Architectural Patterns and Design Principles
- Modular Design: The Flask API is clearly separated into configuration, models, routes, and utility modules – indicating a modular backend design.
- MVC-Like Structure: Even though it’s a Flask (micro-framework) project, the separation of “routes” (controllers) and “models” (data representations) shows an MVC-like approach.
- API-Driven Communication: Emphasize that the design is RESTful, with clear endpoints (defined in routes.py) to interact with the database and handle device data.

##### Relevant Technologies and Frameworks
- Flask: The core web framework used for building the API.
- SQL Database: Represented by the SQL file in the “Database” directory; annotate with your choice of SQL engine (e.g., PostgreSQL, MySQL), if known, or simply “SQL Database.”
- BLE Communication: Although the handling of BLE is mentioned in the README, note that the communication occurs with devices directly or via an intermediary – a component that sits outside of the Flask-API codebase.
- Any external notification service integrations (if applicable) should also be highlighted, showing how alerts propagate outwards.

- Use clear labels for each component: "BLE/Device Layer", "Flask API", "SQL Database", "Notification Service" (if applicable).

- Use of configuration files (like “config.py”), important initialization routines (from __init__.py), and how extensions are initialized using “extensions.py”.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% BLE/Device Layer
    subgraph "BLE/Device Layer"
        BLE["BLE Devices (wearables, smartwatches)"]:::external
    end

    %% Flask API Layer
    subgraph "Flask API Layer"
        Config["Configuration (config.py)"]:::backend
        Models["Models (models.py)"]:::backend
        Routes["Routes/Endpoints (routes.py)"]:::backend
        Utils["Utilities (utils.py)"]:::backend
        Run["Application Runner (run.py)"]:::backend
    end

    %% Database Layer
    subgraph "Database Layer"
        SQLDB["SQL Database (ProtectVida.sql)"]:::database
    end

    %% External Notification Service
    subgraph "External Services"
        Notification["Notification Service"]:::external
    end

    %% Connections between layers
    BLE -->|"SensorData(oxigenación,ritmo-cardiaco,etc.)"| Routes
    Routes -->|"CRUDoperations"| SQLDB
    SQLDB -->|"DataFetch"| Routes
    Routes -->|"AlertDispatch"| Notification

    %% Internal Flask API module connections
    Config --> Models
    Models --> Routes
    Routes --> Utils
    Run --> Config

    %% Click Events
    click Config "https://github.com/mrsheldont/protecvida/blob/main/Flask-API/app/config.py"
    click Models "https://github.com/mrsheldont/protecvida/blob/main/Flask-API/app/models.py"
    click Routes "https://github.com/mrsheldont/protecvida/blob/main/Flask-API/app/routes.py"
    click Utils "https://github.com/mrsheldont/protecvida/blob/main/Flask-API/app/utils.py"
    click Run "https://github.com/mrsheldont/protecvida/blob/main/Flask-API/run.py"
    click SQLDB "https://github.com/mrsheldont/protecvida/blob/main/Database/ProtectVida.sql"

    %% Styles
    classDef external fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef backend fill:#bbdefb,stroke:#1565c0,stroke-width:2px;
    classDef database fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
