# ss0vinicius/electrical-impedance-tomography architecture

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

- Interactive diagram: https://gitdiagram.com/ss0vinicius/electrical-impedance-tomography
- Repository: https://github.com/ss0vinicius/electrical-impedance-tomography

## Overview

##### Analyze the File Structure
- **Top-Level Directories and Files:**
- `.dockerignore` & `Dockerfile`: Used for containerization, likely to streamline deployment or environment setup.
- `README.md`: Documentation and setup instructions.
- `TCC_DANIEL/Prog`: Contains the primary Python application, including GUI components (`AppTie.ui`, `WindowsEIT.ui`) and data handling scripts.
- `TCC_DANIEL/SPI_TEST`: Houses Arduino sketches (`.ino` files), C++ source (`eit.cpp`, `eit.h`), and Python scripts for SPI communication (`dadosSpi.py`).

- **Patterns and Architectural Choices:**
- **Modular Structure:** Separation between the main application (`Prog`) and SPI testing/communication (`SPI_TEST`).
- **Use of PyQt5:** Indicates an MVC-like pattern where the UI is defined separately from the application logic.
- **Data Management:** Multiple CSV files suggest handling of configuration, calibration, or measurement data.

- **Configuration and Deployment:**
- **Docker:** Presence of Docker-related files implies possible container-based deployment or environment replication.
- **Build Scripts:** Although not extensive, installation commands in the README indicate dependency management without elaborate build scripts.

##### Examine the README for Additional Insights
- **Dependencies and Setup:**
- Python 3.11.3 with specific libraries like PyQt5, OpenCV, and spidev.
- Challenges with virtual environments and GUI rendering on Docker or other virtual setups.

- **Hardware Integration:**
- Emphasis on running directly on Raspberry Pi 4.
- Issues with X11 for GUI rendering, highlighting the need for proper graphical environment setup.

- **Project Functionality:**
- GUI-based application (`AppTie.py`, `WindowsEIT.py`) likely for interacting with EIT hardware.
- SPI communication scripts and Arduino code indicating real-time data acquisition and control.

##### User Interface (UI)
- **PyQt5 GUI:** `AppTie.py`, `WindowsEIT.py`, associated `.ui` files.
##### Application Logic
- **EIT Modules:** `EIT` directory containing core processing scripts (`MatEIT.py`, `eit.py`).
- **Data Handling:** Scripts for managing CSV data (`Vobj.csv`, `Jn.csv`, etc.).
##### Hardware Communication
- **SPI Communication:**
- **Python Scripts:** `dadosSpi.py` for interfacing with SPI.
- **Arduino Firmware:** `.ino` files (`SPI_TEST.ino`, `convert.ino`, `func.ino`) handling SPI protocol.
- **C++ Components:** `eit.cpp`, `eit.h` for low-level hardware interactions.
##### Deployment Environment
- **Raspberry Pi 4:** Host machine running the application and managing hardware interfaces.
- **Docker Container:** Defined by `Dockerfile` and `.dockerignore`, though GUI challenges suggest limited use.
##### Data Storage
- **CSV Files:** Located in `DataCSV` and `Prog` directories for storing configuration and measurement data.

##### b. Determine Relationships and Interactions
- **User ↔ PyQt5 GUI:** Users interact with the application through the GUI, triggering actions.
- **GUI ↔ Application Logic:** GUI components communicate with EIT processing scripts to perform operations.
- **Application Logic ↔ SPI Communication:** EIT modules send commands and receive data via SPI.
- **SPI Communication ↔ Arduino Firmware:** Python scripts communicate over SPI to Arduino, which controls hardware.
- **Application ↔ Data Storage:** Reading from and writing to CSV files for data persistence and configuration.

##### c. Highlight Architectural Patterns and Design Principles
- **Modular Architecture:** Clear separation between UI, application logic, and hardware communication.
- **Layered Approach:** UI layer interacts with the application layer, which in turn communicates with the hardware layer.
- **Dependency Management:** Use of Docker and system-level package installations for managing dependencies, despite challenges with virtual environments.

##### d. Include Relevant Technologies, Frameworks, and Libraries
- **Programming Languages:** Python 3.11.3, C++, Arduino C.
- **Frameworks/Libraries:** PyQt5 for GUI, OpenCV for image processing, spidev for SPI communication, RPi.GPIO for GPIO interactions.
- **Deployment Tools:** Docker for containerization.
- **Operating Systems:** Raspberry Pi OS (Raspbian) utilizing X11 for GUI rendering.

##### Detailed Architectural Elements
- **Frontend (PyQt5 GUI):**
- User interacts with the application through windows defined by `.ui` files.
- **Backend (EIT Processing):**
- Processes data, performs computations related to Electrical Impedance Tomography.
- **Communication Layer (SPI):**
- Handles data exchange between Python scripts and Arduino firmware.
- **Hardware Layer:**
- Arduino manages low-level SPI communication and controls EIT hardware.
- **Data Management:**
- CSV files store necessary data for processing and configuration.
- **Deployment:**
- Dockerfile indicates containerization attempts, with a fallback to native Raspberry Pi execution due to GUI constraints.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global entities
    User["User"]:::external

    %% Frontend Layer
    subgraph Frontend [Frontend Layer]
        GUI["PyQt5 GUI"]:::frontend
        AppTiePy["AppTie.py"]:::frontend
        WindowsEITPy["WindowsEIT.py"]:::frontend
        AppTieUI["AppTie.ui"]:::frontend
        WindowsEITUI["WindowsEIT.ui"]:::frontend
    end

    %% Application Logic
    subgraph Backend [Application Logic]
        MatEIT["MatEIT.py"]:::backend
        eit["eit.py"]:::backend
        Comunica["Comunica.py"]:::backend
        comunicaSPI["comunicaSPI.py"]:::backend
    end

    %% Hardware Communication
    subgraph Hardware [Hardware Communication]
        dadosSpi["dadosSpi.py"]:::hardware
        Firmware["Arduino Firmware"]:::hardware
        Firmware -->|Includes| SPI_TEST["SPI_TEST.ino"]:::hardware
        Firmware -->|Includes| convert["convert.ino"]:::hardware
        Firmware -->|Includes| func["func.ino"]:::hardware
        Cpp["C++ Components"]:::hardware
        Cpp -->|Includes| eitCPP["eit.cpp"]:::hardware
        Cpp -->|Includes| eitH["eit.h"]:::hardware
    end

    %% Data Handling and Storage
    subgraph DataStorage [Data Handling and Storage]
        DataCSV["DataCSV/"]:::data
        Cord["Cord.csv"]:::data
        Jn["Jn.csv"]:::data
        Vobj["Vobj.csv"]:::data
        Vobj1["Vobj1.csv"]:::data
        Vobj2["Vobj2.csv"]:::data
        Vobj3["Vobj3.csv"]:::data
        v_ref["v_ref.csv"]:::data
    end

    %% Deployment Environment
    subgraph Deployment [Deployment Environment]
        RaspberryPi["Raspberry Pi 4"]:::deployment
        Dockerfile["Dockerfile"]:::deployment
        dockerignore[".dockerignore"]:::deployment
        README["README.md"]:::deployment
    end

    %% Connections
    User -->|Interacts with| GUI
    GUI -->|Sends commands to| Backend
    Backend -->|Uses| MatEIT
    Backend -->|Uses| eit
    Backend -->|Communicates via| Comunica
    Backend -->|Communicates via| comunicaSPI
    Backend -->|Reads/Writes| DataCSV
    Backend -->|Reads/Writes| Cord
    Backend -->|Reads/Writes| Jn
    Backend -->|Reads/Writes| Vobj
    Backend -->|Reads/Writes| Vobj1
    Backend -->|Reads/Writes| Vobj2
    Backend -->|Reads/Writes| Vobj3
    Backend -->|Reads/Writes| v_ref
    Backend -->|Communicates with| Hardware
    Hardware -->|Communicates via SPI| dadosSpi
    Hardware -->|Controls| Firmware
    Hardware -->|Uses| Cpp
    Deployment -->|Hosts| Frontend
    Deployment -->|Hosts| Backend
    Deployment -->|Hosts| Hardware
    Deployment -->|Data Storage| DataStorage
    Deployment -->|Includes| Dockerfile
    Deployment -->|Includes| dockerignore
    Deployment -->|Includes| README

    %% Click Events
    click AppTiePy "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/AppTie.py"
    click WindowsEITPy "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/WindowsEIT.py"
    click AppTieUI "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/AppTie.ui"
    click WindowsEITUI "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/WindowsEIT.ui"
    click MatEIT "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/MatEIT.py"
    click eit "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/eit.py"
    click Comunica "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/Comunica.py"
    click comunicaSPI "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/EIT/comunicaSPI.py"
    click DataCSV "https://github.com/ss0vinicius/electrical-impedance-tomography/tree/main/TCC_DANIEL/Prog/DataCSV/"
    click Cord "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/Cord.csv"
    click Jn "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/Jn.csv"
    click Vobj "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/Vobj.csv"
    click Vobj1 "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/Vobj1.csv"
    click Vobj2 "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/Vobj2.csv"
    click Vobj3 "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/Vobj3.csv"
    click v_ref "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/Prog/v_ref.csv"
    click dadosSpi "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/SPI_TEST/dadosSpi.py"
    click SPI_TEST "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/SPI_TEST/SPI_TEST.ino"
    click convert "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/SPI_TEST/convert.ino"
    click func "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/SPI_TEST/func.ino"
    click eitCPP "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/SPI_TEST/eit.cpp"
    click eitH "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/TCC_DANIEL/SPI_TEST/eit.h"
    click Dockerfile "https://github.com/ss0vinicius/electrical-impedance-tomography/tree/main/Dockerfile"
    click dockerignore "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/.dockerignore"
    click README "https://github.com/ss0vinicius/electrical-impedance-tomography/blob/main/README.md"

    %% Styles
    classDef frontend fill:#1f77b4,stroke:#333,stroke-width:2px
    classDef backend fill:#2ca02c,stroke:#333,stroke-width:2px
    classDef hardware fill:#d62728,stroke:#333,stroke-width:2px
    classDef data fill:#ff7f0e,stroke:#333,stroke-width:2px
    classDef deployment fill:#7f7f7f,stroke:#333,stroke-width:2px
    classDef external fill:#f0f0f0,stroke:#333,stroke-width:2px
```
