# amritanshu-pandey/otel-sungrow-receiver architecture

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

- Interactive diagram: https://gitdiagram.com/amritanshu-pandey/otel-sungrow-receiver
- Repository: https://github.com/amritanshu-pandey/otel-sungrow-receiver

## Overview

##### Main Components
- Go Application (main.go): Represents the core service that performs the Modbus communication, metrics collection, scaling/rounding logic, and exposes metrics via an HTTP endpoint.
- Configuration Module (config.yaml): Provides the settings, such as Modbus parameters and metric definitions, which the application reads on startup.
- Modbus Communication: The component responsible for connecting to the Sungrow inverter (via Modbus TCP) and reading registers.
- Metrics Export Endpoint: The built-in HTTP server that serves the metrics in Prometheus format (default port 9100).
- Prometheus: An external system configured to scrape the HTTP endpoint, as indicated by the example configuration in the README.
- Containerization Setup: The Dockerfile and docker-compose.yaml illustrate how the application is packaged and deployed.
- Grafana Dashboards: The JSON file in the grafana-dashboards directory shows a predefined dashboard for visualizing the metrics.

##### Out the Relationships and Data Flow
- The Go Application initializes by loading configuration parameters from config.yaml.
- It then establishes a Modbus TCP connection to the Sungrow inverter to poll registers on a predefined interval.
- Collected metrics (after potential scaling and formatting) are served via an HTTP server in a format understandable by Prometheus.
- Prometheus periodically scrapes these metrics from the exporter’s HTTP endpoint.
- Grafana uses the scraped/promoted metrics data from Prometheus to display visual dashboards for monitoring.
- The containerization piece (Dockerfile/docker-compose.yaml) encapsulates the entire setup, allowing for easy deployment in containerized environments.

##### Important Architectural Patterns
- Separation of Concerns: The configuration, communication, and metrics-serving functionalities are clearly separated.
- Polling/Streaming Data Collection: The system follows a periodic polling pattern to read data from the inverter.
- Open Telemetry Receiver Support (future intention) ensures modularity so the system can be extended to support other telemetry backends besides Prometheus.
- Containerization ensures portability and environment consistency.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Internal Components
  Config["config.yaml"]:::internal
  App["Go Application\n(Modbus Client, HTTP Server)"]:::internal

  %% External Components
  Inverter["Sungrow Inverter"]:::external
  Prom["Prometheus"]:::external
  Graf["Grafana Dashboard"]:::external

  %% Containerization Components
  Cont["Containerization Setup"]:::container
  Dockerfile["Dockerfile"]:::container
  DockerCompose["docker-compose.yaml"]:::container

  %% Data Flow
  Config -->|"loads"| App
  App -->|"polls_Modbus_TCP"| Inverter
  App -->|"serves_metrics"| Prom
  Prom -->|"provides_data_to"| Graf
  Cont --> App
  Cont --- Dockerfile
  Cont --- DockerCompose

  %% Click Events
  click App "https://github.com/amritanshu-pandey/otel-sungrow-receiver/blob/master/main.go"
  click Config "https://github.com/amritanshu-pandey/otel-sungrow-receiver/blob/master/config.yaml"
  click Dockerfile "https://github.com/amritanshu-pandey/otel-sungrow-receiver/tree/master/Dockerfile"
  click DockerCompose "https://github.com/amritanshu-pandey/otel-sungrow-receiver/blob/master/docker-compose.yaml"
  click Graf "https://github.com/amritanshu-pandey/otel-sungrow-receiver/blob/master/grafana-dashboards/overview.json"

  %% Style Definitions
  classDef internal fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
  classDef external fill:#FFE082,stroke:#FF6F00,stroke-width:2px;
  classDef container fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
```
