# mery1738/sprint0 architecture

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

- Interactive diagram: https://gitdiagram.com/mery1738/sprint0
- Repository: https://github.com/mery1738/sprint0

## Overview

##### Project Type and Purpose
- This is an end-to-end BLE-based IoT measurement system (full-stack + hardware) that:
- Captures sensor data on an Arduino iBeacon device via BLE
- Uses an Android app to receive BLE data and forward it via HTTP
- Hosts a Node.js/Express REST API that persists measurements in SQLite
- Provides a web client (HTML/CSS/JS) to display the latest measurement

##### Main Components
a. Hardware & Firmware (Arduino)
- Sketch files under src/arduino/HolaMundoIBeacon (.ino & .h)
- Emits BLE advertisements with measurement payloads
b. Mobile App (Android)
- Java code in src/telefono/app/src/main/java/com/example/mery/beaconapp
- Listens for BLE adverts, builds JSON payloads, issues HTTP POST to /medicion
c. Backend / REST API
- src/servidor/servidorREST/mainServidorREST.js (Express server)
- src/servidor/servidorREST/ReglasREST.js (route definitions)
- src/servidor/logica/Logica.js (DB logic layer)
d. Database (SQLite)
- src/servidor/bd/datos.db (actual DB file)
- src/servidor/bd/crearTablas.sql (schema)
e. Web Client
- src/cliente/index.html, style.css, LogicaFake.js
- Polls GET /ultimaMedicion, updates UI
f. Tests (Mocha/Chai/jsdom/Supertest)
- Organized under servidor/logica/test and servidor/servidorREST/test

##### Interactions & Data Flows
1. BLE (Bluetooth LE)
- Arduino iBeacon → Android App scanner
2. HTTP POST /medicion
- Android App → REST API (Express)
3. Persistence
- Express → SQLite via Logica.js
4. HTTP GET /ultimaMedicion
- Web Client → REST API → returns JSON
5. UI Rendering
- Web Client parses JSON, updates HTML

##### Architectural Patterns & Design Principles
- Layered architecture:
- Presentation Layers (Mobile, Web)
- API Layer (Express controllers/routes)
- Business Logic Layer (Logica.js)
- Data Layer (SQLite)
- Separation of concerns: hardware code, mobile UI/logic, server API/logic, client UI
- Single-responsibility modules: each folder/file holds one concern

##### Detailed Capturing of Architectural Elements
- Drill down into server: show “ReglasREST.js” feeding into “Logica.js”
- SQLite file path under “SQLite Database”
- Test harness components off to the side
- Network configuration note: Android’s endpoint configurable (e.g., 10.0.2.2)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Hardware Layer
    subgraph "Hardware & Firmware"
        direction TB
        Arduino["Arduino BLE Sensor"]:::hardware
    end

    %% Mobile Layer
    subgraph "Mobile App (Android)"
        direction TB
        AndroidApp["Android App"]:::mobile
    end

    %% Server Layer
    subgraph "Node.js/Express Server"
        direction TB
        ExpressServer["Express Server"]:::server
        ReglasREST["ReglasREST.js"]:::server
        Logica["Logica.js"]:::server
        ExpressServer -->|"routes defined in"| ReglasREST
        ReglasREST -->|"calls logic in"| Logica
    end

    %% Database Layer
    subgraph "Data Layer"
        direction TB
        SQLiteDB["SQLite Database"]:::database
    end

    %% Web Client Layer
    subgraph "Web Client"
        direction TB
        WebClient["Web Client"]:::client
    end

    %% Tests
    subgraph "Tests"
        direction TB
        LogicTests["testLogica.js"]:::test
        APITests["testAPI.js"]:::test
        UITests["testUI.js"]:::test
    end

    %% Interactions
    Arduino -->|BLE| AndroidApp
    AndroidApp -->|"HTTP POST /medicion (JSON)"| ExpressServer
    ExpressServer -->|"SQL INSERT via Logica.js"| SQLiteDB
    WebClient -->|"HTTP GET /ultimaMedicion"| ExpressServer
    ExpressServer -->|"JSON response"| WebClient

    %% Test connections
    LogicTests -->|validates| Logica
    APITests -->|tests endpoints| ReglasREST
    UITests -->|tests UI endpoint| ReglasREST

    %% Click Events
    click Arduino "https://github.com/mery1738/sprint0/tree/main/src/arduino/HolaMundoIBeacon"
    click AndroidApp "https://github.com/mery1738/sprint0/tree/main/src/telefono/app/src/main/java/com/example/mery/beaconapp"
    click ExpressServer "https://github.com/mery1738/sprint0/blob/main/src/servidor/servidorREST/mainServidorREST.js"
    click ReglasREST "https://github.com/mery1738/sprint0/blob/main/src/servidor/servidorREST/ReglasREST.js"
    click Logica "https://github.com/mery1738/sprint0/blob/main/src/servidor/logica/Logica.js"
    click SQLiteDB "https://github.com/mery1738/sprint0/blob/main/src/servidor/bd/datos.db"
    click WebClient "https://github.com/mery1738/sprint0/blob/main/src/cliente/index.html"
    click LogicTests "https://github.com/mery1738/sprint0/blob/main/src/servidor/logica/test/testLogica.js"
    click APITests "https://github.com/mery1738/sprint0/blob/main/src/servidor/servidorREST/test/testAPI.js"
    click UITests "https://github.com/mery1738/sprint0/blob/main/src/servidor/servidorREST/test/testUI.js"

    %% Styles
    classDef hardware fill:#e0f2f1,stroke:#00695c,color:#00695c;
    classDef mobile fill:#e3f2fd,stroke:#1565c0,color:#1565c0;
    classDef server fill:#fff3e0,stroke:#ef6c00,color:#e65100;
    classDef database fill:#eceff1,stroke:#37474f,color:#37474f;
    classDef client fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c;
    classDef test fill:#fbe9e7,stroke:#d84315,color:#bf360c;
```
