# make-all/tuya-local architecture

> Architecture diagram of the GitHub repository make-all/tuya-local, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/make-all/tuya-local
- Repository: https://github.com/make-all/tuya-local

## Overview

##### Main Components Overview

The system architecture should be divided into these key layers:

a) Integration Layer
- Config Flow Handler
- Device Management
- Entity Platforms (climate, light, switch, etc.)
- Translation System

b) Protocol Layer
- Tuya Protocol Handlers (v3.1, v3.2, v3.3, v3.4)
- Device Communication
- Data Encryption/Decryption

c) Device Configuration Layer
- Device Type Definitions
- DPS (Data Point Specification) Mappings
- Device Detection Logic

##### Key Relationships to Highlight

**[Home Assistant Core] ←→ [Integration Layer]**
- ↓
- [Protocol Layer]
- ↓
- [Device Config Layer]
- ↓
- [Tuya Devices]

##### Detailed Component Breakdown

a) Integration Layer:
- Config Flow (config_flow.py)
- Device Management (device.py)
- Entity Platforms (*.py files)
- Helpers (helpers/*.py)

b) Protocol Layer:
- Protocol Version Handler
- Communication Manager
- Encryption Service

c) Device Configuration:
- Device Config Parser
- DPS Mapper
- Device Type Detector

##### Data Flow Representation

Following data flows:

**[User Input] → [Config Flow] → [Device Setup]**
**[Device] → [Protocol Handler] → [Entity Updates] → [Home Assistant States]**
**[Device Config] → [Device Detection] → [Entity Creation]**

##### Integration Points

Connections with:
- Home Assistant Core
- Network Layer
- Device Discovery
- Translation System
- HACS Integration

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and classes
    classDef core fill:#2374e1,color:white
    classDef protocol fill:#4caf50,color:white
    classDef config fill:#ff9800,color:white
    classDef external fill:#9e9e9e,color:white
    classDef security fill:#f44336,color:white
    classDef platform fill:#03a9f4,color:white

    %% Main Components
    HA[Home Assistant Core]:::external
    
    subgraph Integration
        Init["Integration Setup"]:::core
        ConfigFlow["Config Flow Handler"]:::core
        DeviceMgmt["Device Management"]:::core
        Const["Constants & Shared Data"]:::core
        Diag["Diagnostics"]:::core
        Trans["Translation System"]:::core
        
        subgraph Platforms
            Climate["Climate Platform"]:::platform
            Light["Light Platform"]:::platform
            Switch["Switch Platform"]:::platform
            Sensor["Sensor Platform"]:::platform
            BinSensor["Binary Sensor Platform"]:::platform
            Fan["Fan Platform"]:::platform
        end
    end

    subgraph Protocol
        ProtocolHandler["Protocol Version Handler"]:::protocol
        CommManager["Communication Manager"]:::protocol
        Encryption["Encryption Service"]:::protocol
    end

    subgraph DeviceConfig
        ConfigParser["Device Config Parser"]:::config
        DPSMapper["DPS Mapper"]:::config
        TypeDetector["Device Type Detector"]:::config
        Helpers["Helper Functions"]:::config
    end

    TuyaDev["Tuya Devices"]:::external

    %% Relationships
    HA <--> Init
    Init --> ConfigFlow
    ConfigFlow --> DeviceMgmt
    DeviceMgmt --> Platforms
    DeviceMgmt --> ProtocolHandler
    ProtocolHandler --> CommManager
    CommManager --> Encryption
    Encryption --> TuyaDev
    ConfigParser --> TypeDetector
    TypeDetector --> DPSMapper
    DPSMapper --> DeviceMgmt
    Helpers --> DeviceMgmt

    %% Click events
    click ConfigFlow "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/config_flow.py"
    click DeviceMgmt "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/device.py"
    click Climate "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/climate.py"
    click Light "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/light.py"
    click Switch "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/switch.py"
    click Sensor "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/sensor.py"
    click BinSensor "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/binary_sensor.py"
    click Fan "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/fan.py"
    click Trans "https://github.com/make-all/tuya-local/tree/main/custom_components/tuya_local/translations"
    click ConfigParser "https://github.com/make-all/tuya-local/tree/main/custom_components/tuya_local/devices"
    click Helpers "https://github.com/make-all/tuya-local/tree/main/custom_components/tuya_local/helpers"
    click Const "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/const.py"
    click Init "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/__init__.py"
    click Diag "https://github.com/make-all/tuya-local/blob/main/custom_components/tuya_local/diagnostics.py"

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Protocol Layer"]:::protocol
        L3["Config Layer"]:::config
        L4["External Systems"]:::external
        L5["Platform Components"]:::platform
    end
```
