# yakutozcan/http2mqtt architecture

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

- Interactive diagram: https://gitdiagram.com/yakutozcan/http2mqtt
- Repository: https://github.com/yakutozcan/http2mqtt

## Overview

##### Project Type and Purpose
- The project is a lightweight bridge written in Go that converts HTTP requests into MQTT messages.
- Its primary function is to expose an HTTP endpoint (using Echo) and, upon receiving requests, forward them as messages to an MQTT broker (using the Eclipse Paho MQTT client).
- The project is simple, following a single-service architecture with no separate frontend or complex layering.

##### Analyzing the File Structure
- Top-Level Files:
- main.go: Contains the application’s entry point and wiring of components.
- config.yml: Provides configuration parameters (likely for HTTP server settings, MQTT broker address, topics, etc.), which are loaded via Viper.
- go.mod and go.sum: Define project dependencies (e.g., Echo, Gommon, Viper, and MQTT client).
- The absence of separate directories suggests that the code is kept minimal, with components defined in single or few files rather than using multiple modules.

##### Key Architectural Components
a. HTTP Server:
- Built using the Echo web framework; responsible for receiving HTTP requests.
b. Configuration Module:
- Uses Viper to load and manage application settings from config.yml.
c. HTTP-to-MQTT Bridge Logic:
- Contains the transformation logic where the HTTP request data is prepared for conversion.
d. MQTT Client:
- Leverages the Eclipse Paho MQTT Go client to connect to an MQTT broker and publish messages.
e. External MQTT Broker (External service):
- Represented as an external endpoint where the MQTT messages are sent.

##### Relationships and Interactions
- An HTTP request flows into the HTTP server.
- The HTTP server (handled by Echo) processes the request by possibly consulting the configuration (loaded via Viper) to determine settings.
- The request is transformed into an MQTT-compatible message by the core bridge logic.
- The transformed message is then published to an external MQTT broker via the MQTT client.

##### Architectural Patterns and Design Principles
- Separation of Concerns: The responsibilities for handling HTTP interactions and MQTT publishing are clearly divided.
- External Configuration: Viper allows for dynamic configuration of the HTTP server and MQTT connection parameters.
- Minimalism: The minimalist approach is evident from the project’s file layout, focusing on essential functionalities.

- “HTTP Server (Echo)” for the endpoint.
- “Configuration Module (Viper/config.yml)” for managing settings.
- “Bridge Logic” for the transformation layer.
- “MQTT Client (Paho)” for publishing messages.
- “External MQTT Broker” to denote the receiving endpoint.
- From the “HTTP Client” to the “HTTP Server.”
- From the “HTTP Server” to “Bridge Logic.”
- From “Bridge Logic” to “MQTT Client.”
- From “MQTT Client” to “External MQTT Broker.”

## Diagram (Mermaid)

```mermaid
flowchart TD
    HTTPClient["HTTP Client"]:::internal
    HTTPServer["HTTP Server (Echo)"]:::internal
    BridgeLogic["Bridge Logic"]:::internal
    MQTTClient["MQTT Client (Paho)"]:::internal
    ExternalMQTT["External MQTT Broker"]:::external
    Config["Configuration Module (Viper)"]:::internal

    HTTPClient -->|"sends"| HTTPServer
    HTTPServer -->|"forwards"| BridgeLogic
    BridgeLogic -->|"transforms"| MQTTClient
    MQTTClient -->|"publishes"| ExternalMQTT

    HTTPServer -->|"uses"| Config
    MQTTClient -->|"uses"| Config

    click HTTPServer "https://github.com/yakutozcan/http2mqtt/blob/master/main.go"
    click BridgeLogic "https://github.com/yakutozcan/http2mqtt/blob/master/main.go"
    click MQTTClient "https://github.com/yakutozcan/http2mqtt/blob/master/main.go"
    click Config "https://github.com/yakutozcan/http2mqtt/blob/master/config.yml"

    classDef internal fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#333,stroke-width:2px,stroke-dasharray: 5,5;
```
