# johancacerez/metricedge architecture

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

- Interactive diagram: https://gitdiagram.com/johancacerez/metricedge
- Repository: https://github.com/johancacerez/metricedge

## Overview

##### Main Components
- Electron Main Process – represented by src/main/index.js. This is the “brain” of your desktop app responsible for creating windows and handling system events.
- Preload Script – shown in src/preload/index.js. It acts as a secure intermediary, bridging the main process and the renderer process, exposing limited Node APIs to the UI.
- Renderer Process – built with React and encapsulated in the src/renderer directory. It contains the UI (pages, components, context) and also holds a “backend” submodule.
- UI Components – located under src/renderer/src/components and src/renderer/src/pages. These handle user interactions (like Login, Measurement History, Navbar, modals, etc.).
- Application Backend Modules – situated under src/renderer/src/backend with submodules for sensors (sensorController.js, sensorService.js, and even Python files like sensor1.py/sensor2.py) and users (userController.js, userService.js). Also include the dbService.js indicating some database operations.
- Sensor Integration Resources – with Python executables in resources/python and corresponding sensor modules in src/renderer/src/backend/sensor, hinting at inter-process communication or external service calls.

##### Relationships and Interactions
- The Electron main process initializes and spawns the renderer window. It can also communicate with the preload script.
- The preload script securely exposes necessary APIs to the renderer.
- The React-based renderer is responsible for the UI, while delegating certain operations (sensor data, user management, database reads/writes) to its backend modules.
- The backend modules (controllers and services) form business logic layers. For sensor data, the system likely interacts with Python sensor scripts or executables present in both the backend folder and resources. There should be clear directional flows between:
- UI components invoking backend services (through the exposed APIs via preload).
- Sensor modules executing external Python scripts and returning data to the service layers.
- User management modules feeding information to/from any connected data storage (hinted by dbService.js).

##### Architectural Patterns and Design Principles
- Separation of Concerns – Different responsibilities for each layer: Electron main handles the system, preload manages secure data access, React renderer handles UI interactions, and backend folders encapsulate business logic.
- Modular Design – By separating the sensor and user logic into distinct submodules (controllers and services), it follows a logical separation akin to the MVC pattern.
- Inter-Process Communication – The design leverages Electron’s preload process to enable safe communication between the main process and the renderer.

## Diagram (Mermaid)

```mermaid
graph TD
    MP["Main Process"]:::electron
    PL["Preload Module"]:::electron
    RP["Renderer Process"]:::ui
    UIC["UI Components (Components)"]:::ui
    UIP["UI Components (Pages)"]:::ui
    BM["Backend Modules"]:::backend
    SM["Sensor Management"]:::backend
    UM["User Management"]:::backend
    SC["Sensor Controller"]:::backend
    SS["Sensor Service"]:::backend
    S1["Sensor Script 1"]:::backend
    S2["Sensor Script 2"]:::backend
    UC["User Controller"]:::backend
    US["User Service"]:::backend
    DB["DB Service"]:::backend
    ES["External Sensor Services"]:::external
    SE1["Sensor1 Executable"]:::external
    SE2["Sensor2 Executable"]:::external

    MP -->|"initializes"| PL
    PL -->|"createsWindow"| RP
    RP -->|"contains"| UIC
    RP -->|"contains"| UIP
    UIC -->|"triggers"| BM
    UIP -->|"triggers"| BM
    BM -->|"managesSensors"| SM
    BM -->|"managesUsers"| UM
    SM --> SC
    SM --> SS
    SS -->|"calls"| S1
    SS -->|"calls"| S2
    UM --> UC
    UM --> US
    UM --> DB
    SS -->|"executes"| ES
    ES --> SE1
    ES --> SE2

    click MP "https://github.com/johancacerez/metricedge/blob/main/src/main/index.js"
    click PL "https://github.com/johancacerez/metricedge/blob/main/src/preload/index.js"
    click RP "https://github.com/johancacerez/metricedge/tree/main/src/renderer"
    click UIC "https://github.com/johancacerez/metricedge/tree/main/src/renderer/src/components"
    click UIP "https://github.com/johancacerez/metricedge/tree/main/src/renderer/src/pages"
    click SC "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/sensor/sensorController.js"
    click SS "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/sensor/sensorService.js"
    click S1 "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/sensor/sensor1.py"
    click S2 "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/sensor/sensor2.py"
    click UC "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/users/userController.js"
    click US "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/users/userService.js"
    click DB "https://github.com/johancacerez/metricedge/blob/main/src/renderer/src/backend/dbService.js"
    click SE1 "https://github.com/johancacerez/metricedge/blob/main/resources/python/sensor1.exe"
    click SE2 "https://github.com/johancacerez/metricedge/blob/main/resources/python/sensor2.exe"

    classDef electron fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef ui fill:#A2D2FF,stroke:#333,stroke-width:2px;
    classDef backend fill:#C5E1A5,stroke:#333,stroke-width:2px;
    classDef external fill:#FFADAD,stroke:#333,stroke-width:2px;
```
