# floholzer/elektrolade architecture

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

- Interactive diagram: https://gitdiagram.com/floholzer/elektrolade
- Repository: https://github.com/floholzer/elektrolade

## Overview

##### Project Type and Primary Purpose
- This is a distributed full-stack system designed for generating invoices for customers of electric charging stations.
- It uses a mix of technologies: Java Spring Boot for REST-APIs, JavaFX for the UI, and RabbitMQ for inter-service communication.
- The system incorporates several microservices and Dockerized databases, which together implement a workflow from UI request to invoice PDF generation.

##### Main Components
a. User Interface:
- JavaFX-based UI (StationUI) that accepts customer IDs and displays/downloads generated PDF invoices.
b. REST API:
- StationAPI – a Spring Boot-based service that processes HTTP requests initiated by the UI.
c. Message Queue:
- RabbitMQ – responsible for coordinating communication among services via various queues (e.g., start_queue, stations_info_queue, job_notify_queue, station_data_queue, pdf_data_queue).
d. Microservices:
- DataCollectionDispatcher: Handles incoming data collection tasks and directs data dispatch.
- DataCollectionReceiver: Receives and processes data sent from various collection points.
- PDFgenerator: Processes invoice data and generates PDF files.
- StationDataCollector: Collects data from individual station databases.
e. Databases (all deployed via Docker):
- Customer Database – contains customer details.
- Stations Database – holds overall station information.
- Individual Station Databases (three separate databases) – contain detailed customer station data.

##### Relationships and Interactions
- The UI sends an HTTP request to the StationAPI when a user initiates an invoice generation, which then triggers a chain of events:
- StationAPI communicates with the message broker (RabbitMQ) by publishing messages to the appropriate queues.
- The DataCollectionDispatcher picks up messages from the queue, organizes and dispatches data gathering jobs.
- The StationDataCollector reaches out to individual station databases to fetch necessary data.
- DataCollectionReceiver processes incoming data and consolidates it.
- Once data is ready, the PDFgenerator receives the message (through a designated queue) and creates the PDF invoice.
- The UI is then notified (or polls) to download the generated invoice from the file system.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Each service (API, UI, data collectors, PDF generator) is modular and deployed independently, enabling scalability.
- Message-Driven Communication: Use of RabbitMQ illustrates asynchronous communication between microservices.
- Containerization: The use of Docker for the databases infers a containerized deployment approach.
- Separation of Concerns: The division between UI, API, data collection, and PDF generation underlines a clear separation of responsibilities.

##### Relevant Technologies and Frameworks
- Spring Boot for REST API development.
- JavaFX for the frontend user interface.
- RabbitMQ for the messaging queue mechanism.
- Maven for build and dependency management (as seen in multiple Maven wrapper files).
- Docker (and docker-compose) for orchestrating database containers.

##### Final Assembly
- Drill down to detail internal interactions among the backend microservices.
- Asynchronous design; illustrate that while the REST API responds immediately, the data processing is handled asynchronously by various dispatcher and receiver services.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface"
        UI["StationUI"]:::UI
    end

    %% API Layer
    subgraph "API Components"
        API["StationAPI"]:::API
    end

    %% Message Queue Layer
    subgraph "Message Broker (RabbitMQ)"
        MQ["RabbitMQ"]:::MQ
    end

    %% Microservices Layer
    subgraph "Backend Microservices"
        DCD["DataCollectionDispatcher"]:::Micro
        SDC["StationDataCollector"]:::Micro
        DCR["DataCollectionReceiver"]:::Micro
        PDF["PDFgenerator"]:::Micro
    end

    %% Databases Layer
    subgraph "Docker Databases"
        CDB["Customer Database"]:::DB
        SDB["Stations Database"]:::DB
        IS1["Individual Station DB1 [Station 1]"]:::DB
        IS2["Individual Station DB2 [Station 2]"]:::DB
        IS3["Individual Station DB3 [Station 3]"]:::DB
    end

    %% Interactions
    UI -->|"HTTP_request"| API
    API -->|"publish_invoice_request"| MQ
    API -->|"fetch_customer_info"| CDB
    CDB -->|"customer_data"| API

    MQ -->|"start_queue"| DCD
    DCD -->|"invoke"_to| SDC
    SDC -->|"fetch_data"| IS1
    SDC -->|"fetch_data"| IS2
    SDC -->|"fetch_data"| IS3
    SDC -->|"fetch_station_info"| SDB
    DCD -->|"collect_data"| DCR
    DCR -->|"invoice_data"| PDF
    PDF -->|"invoice_ready"| UI

    %% Styles
    classDef UI fill:#cce5ff,stroke:#339,stroke-width:2px;
    classDef API fill:#d1e7dd,stroke:#0f5132,stroke-width:2px;
    classDef Micro fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef DB fill:#f8d7da,stroke:#842029,stroke-width:2px;
    classDef MQ fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/floholzer/elektrolade/tree/main/StationUI/"
    click API "https://github.com/floholzer/elektrolade/tree/main/StationAPI/"
    click DCD "https://github.com/floholzer/elektrolade/tree/main/Services/DataCollectionDispatcher/"
    click DCR "https://github.com/floholzer/elektrolade/tree/main/Services/DataCollectionReceiver/"
    click PDF "https://github.com/floholzer/elektrolade/tree/main/Services/PDFgenerator/"
    click SDC "https://github.com/floholzer/elektrolade/tree/main/Services/StationDataCollector/"
    click CDB "https://github.com/floholzer/elektrolade/tree/main/Data/customer_db/"
    click SDB "https://github.com/floholzer/elektrolade/tree/main/Data/stations_db/"
    click IS1 "https://github.com/floholzer/elektrolade/tree/main/Data/station_1_db/"
    click IS2 "https://github.com/floholzer/elektrolade/tree/main/Data/station_2_db/"
    click IS3 "https://github.com/floholzer/elektrolade/tree/main/Data/station_3_db/"
```
