# milanvives/hacs-twinpool architecture

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

- Interactive diagram: https://gitdiagram.com/milanvives/hacs-twinpool
- Repository: https://github.com/milanvives/hacs-twinpool

## Overview

##### Project type and purpose
- This is a Home Assistant custom integration (Python “plugin”) named **twinpool_sensor**.
- Purpose: fetch pH, flow, and redox readings from a WiFi pool sensor (via a cloud or LAN API) and expose them as Home Assistant Sensor entities.

##### File structure
- **custom_components/twinpool_sensor/** – all integration code lives here.
- manifest.json: integration metadata (name, version, requirements, HA core version).
- config_flow.py: handles the UI‐driven setup (email/password/domain).
- sensor.py: main logic creating Sensor entities and polling the pool API.
- const.py: API endpoints, default IO mappings, and other constants.
- strings.json & translations/: UI label definitions.
- No separate “frontend” or “backend” folders: it plugs directly into HA core.
- No build scripts; uses Python and Home Assistant’s runtime.

##### README for additional insights
- Uses secure login over HTTP(S) to external pool API.
- Runtime hooks into Home Assistant’s integration registry.
- Installed via HACS or manually dropped in custom_components.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User and Distribution
    User["User"]:::dist
    HACS["HACS Repository"]:::dist
    Manual["Manual Install (copy to custom_components)"]:::dist

    %% Home Assistant Core container
    subgraph "Home Assistant Core" 
        HA["Home Assistant Core"]:::ha
        ConfigEntries(("Config Entries")):::storage

        %% Integration subgraph
        subgraph "twinpool_sensor Integration"
            Init["__init__.py"]:::integration
            Manifest["manifest.json"]:::integration
            HacsMeta["hacs.json"]:::integration
            ConfigFlow["config_flow.py"]:::integration
            Const["const.py"]:::integration
            SensorMod["sensor.py"]:::integration
            Strings["strings.json"]:::integration
            Translations["translations/"]:::integration
        end
    end

    %% External Service
    External["External Pool API<br/>(Cloud / LAN)"]:::external

    %% User Interactions
    User -->|install via HACS| HACS
    User -->|manual install| Manual
    HACS -->|integrates| HA
    Manual -->|integrates| HA

    User -->|configure integration| ConfigFlow
    ConfigFlow -->|stores credentials| ConfigEntries

    %% Data Flow
    SensorMod -->|"uses API Client"| Const
    Const -->|"HTTP GET /sensor/data<br/>JSON"| External
    External -->|"JSON response"| SensorMod
    SensorMod -->|"update entities"| HA
    HA -->|render sensors| User

    %% Localization Flow
    ConfigFlow -->|UI labels| Strings
    ConfigFlow -->|translations| Translations

    %% Click Events
    click Init "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/__init__.py"
    click Manifest "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/manifest.json"
    click HacsMeta "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/hacs.json"
    click ConfigFlow "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/config_flow.py"
    click Const "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/const.py"
    click SensorMod "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/sensor.py"
    click Strings "https://github.com/milanvives/hacs-twinpool/blob/main/custom_components/twinpool_sensor/strings.json"
    click Translations "https://github.com/milanvives/hacs-twinpool/tree/main/custom_components/twinpool_sensor/translations/"
    click HA "https://github.com/milanvives/hacs-twinpool/tree/main/custom_components/twinpool_sensor/"
    click README "https://github.com/milanvives/hacs-twinpool/blob/main/README.md"

    %% Styles
    classDef ha fill:#D0E8FF,stroke:#1E88E5,color:#0D47A1;
    classDef integration fill:#C8E6C9,stroke:#388E3C,color:#1B5E20;
    classDef external fill:#FFE0B2,stroke:#FB8C00,color:#E65100;
    classDef dist fill:#E0E0E0,stroke:#9E9E9E,color:#424242;
    classDef storage fill:#E1BEE7,stroke:#8E24AA,color:#4A148C;
```
