# piovezan1207/central-4.0-eniac-2022 architecture

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

- Interactive diagram: https://gitdiagram.com/piovezan1207/central-4.0-eniac-2022
- Repository: https://github.com/piovezan1207/central-4.0-eniac-2022

## Overview

##### Project Type and Purpose
- This project is a component of a broader industrial automation system that integrates Amazon Alexa with an industrial plant (Planta Industrial 4.0 FESTO).
- Its role is to serve as the “Central Local” responsible for interpreting API calls (which come from the Alexa Skill and API Intermediária) and managing the control of industrial devices (CLPs and the robotic arm controller) using protocols such as MQTT.
- The system supports both sending commands to the industrial plant and receiving status feedback.

##### Analyzing the File Structure
- Key files such as main.py and import_map.py, along with a package named “project”, indicate that the Python code in this repository implements the central processing logic.
- error_class: likely handles error management.
- mqtt_class: contains mqttClient.py and mqttPublish.py, suggesting the use of MQTT for communication.
- stations_class: includes modules such as generic_station.py, station1.py, station5.py, station7.py, and a stations_superclass.py, implying that the system is designed to interface with various industrial stations.
- Additional modules like order.py and process.py likely manage control flow or command queues.
- There is also a “status_tables” directory containing CSV files with status codes, meaning that the system uses these tables to interpret device states and error messages.

##### Insights from the README
- The README clearly describes a four-part architecture:
a. Alexa Skill – which converts voice commands into HTTP requests.
b. API Intermediária – that passes these requests to the Central Local unit.
c. Central Local – where this Python code resides, handling communication with CLPs and the robotic manipulator.
d. Bidirectional Communication – ensuring commands and status updates are shared.
- Technologies mentioned include Amazon Alexa, a REST API (perhaps implemented in Node.js, Flask, or similar), MQTT for messaging, and protocols for industrial equipment control.

a. Main Components:
- Alexa Skill: This is the front-end for voice commands (although not present in this repo, it’s important to include as part of the overall system).
- API Intermediária: The REST layer that accepts HTTP requests from the Alexa Skill.
- Central Local (this Python-based module): Include sub-components such as:
- MQTT Module: Represent the mqttClient and mqttPublish classes.
- Error Handling Module: Represent the error_class.
- Station Management: Illustrate the stations_class modules (generic station and specific station implementations) to show how different industrial stations are handled.
- Process/Order Modules: Representing command processing and queuing logic.
- Industrial Equipment: At the bottom, include CLPs and the control unit for the manipulator robot.

b. Relationships and Interactions:
- Within Central Local, delineate interactions:
- Subsequent flows to the MQTT module for sending commands.

c. Architectural Patterns / Design Principles:
- Modular design: Clear separation into dedicated modules (error handling, MQTT communication, station control, command processing).
- Layered architecture: Distinct layers from voice command reception (Alexa Skill) to API processing and then centralized local control.
- Use of MQTT for asynchronous communication emphasizes a decoupled message-driven architecture.

d. Relevant Technologies and Frameworks:
- Python for the Central Local module.
- MQTT libraries (as indicated by mqttClient.py and mqttPublish.py).
- CSV-based configuration/status (from the status_tables folder).
- Although external to this repository, include Amazon Alexa and the REST API, which may be implemented using frameworks like Flask or Node.js.

##### Elements
- “MQTT Module” (linking to station commands)
- “Error Handling Module”
- “Station Management – [Station1, Station5, Station7, etc.]”
- “Process / Order Module”
- A “Status Tables” note indicating static configuration or lookup data.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Components
    Alexa["Amazon Alexa Skill"]:::external
    API["API Intermediária"]:::middleware

    %% Industrial Equipment
    IndustrialEquip["Industrial Equipment (CLPs & Robotic Controller)"]:::industrial

    %% External Flow
    Alexa -->|"VoiceCommands/HTTP"| API
    API -->|"ForwardsAPI"| MainPy

    %% Central Local (Python App) Subgraph
    subgraph "Central Local (Python App)"
        MainPy["Main.py"]:::backend
        ProjectCore["Project Core"]:::backend
        ProcessOrder["Process / Order Module"]:::backend
        MQTTModule["MQTT Module"]:::backend
        StationMgmt["Station Management Module"]:::backend
        ErrorHandling["Error Handling Module"]:::backend
        StatusTables["Status Tables"]:::backend
    end

    %% Internal Interactions within Central Local
    MainPy -->|"processCommand"| ProcessOrder
    ProcessOrder -->|"sendCommand"| MQTTModule
    ProcessOrder -->|"manageStation"| StationMgmt
    ProcessOrder -->|"errorFeedback"| ErrorHandling
    StatusTables -->|"lookup"| ProcessOrder
    StatusTables -->|"lookup"| StationMgmt

    %% Connections to Industrial Equipment
    MQTTModule -->|"sendCommands"| IndustrialEquip
    IndustrialEquip -->|"statusFeedback"| MQTTModule

    %% Click Events
    click MainPy "https://github.com/piovezan1207/central-4.0-eniac-2022/blob/main/main.py"
    click ProjectCore "https://github.com/piovezan1207/central-4.0-eniac-2022/tree/main/project/"
    click MQTTModule "https://github.com/piovezan1207/central-4.0-eniac-2022/tree/main/project/program_class/mqtt_class/"
    click ErrorHandling "https://github.com/piovezan1207/central-4.0-eniac-2022/blob/main/project/program_class/error_class/errors.py"
    click StationMgmt "https://github.com/piovezan1207/central-4.0-eniac-2022/tree/main/project/program_class/stations_class/"
    click ProcessOrder "https://github.com/piovezan1207/central-4.0-eniac-2022/blob/main/project/program_class/process.py"
    click StatusTables "https://github.com/piovezan1207/central-4.0-eniac-2022/tree/main/status_tables/"

    %% Styles
    classDef external fill:#ffd1dc,stroke:#c70039,stroke-width:2px;
    classDef middleware fill:#d1e8ff,stroke:#00529b,stroke-width:2px;
    classDef backend fill:#d1ffd8,stroke:#4CAF50,stroke-width:2px;
    classDef industrial fill:#f0f0f0,stroke:#333333,stroke-width:2px;
```
