# tuya/tuya-iot-core-sdk architecture

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

- Interactive diagram: https://gitdiagram.com/tuya/tuya-iot-core-sdk
- Repository: https://github.com/tuya/tuya-iot-core-sdk

## Overview

Tuya IoT Core SDK is an embedded C client for connecting devices to Tuya IoT Core. The documented workflow configures device credentials, connects and services an MQTT client, then exchanges TuyaLink messages; capabilities also include activation, sub-device management, and OTA. The graph combines those documented capabilities with sampled implementation evidence. Some domain components are represented at their exact enclosing directory because their implementation was not sampled; their internal links are omitted where source evidence is unavailable.

Main entry points: [`src/tuyalink_core.c`](https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuyalink_core.c) (TuyaLink messaging), [`middleware/http_client_wrapper.c`](https://github.com/tuya/tuya-iot-core-sdk/blob/main/middleware/http_client_wrapper.c) (HTTP adapter), [`middleware/mqtt_client_wrapper.c`](https://github.com/tuya/tuya-iot-core-sdk/blob/main/middleware/mqtt_client_wrapper.c) (MQTT adapter), [`interface`](https://github.com/tuya/tuya-iot-core-sdk/tree/main/interface) (Platform interfaces)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_device["Device workflow"]
  node_activation["Device activation<br/>[tuya_endpoint.c]"]
  node_tuya_core["TuyaLink messaging<br/>[tuyalink_core.c]"]
  node_model["Thing data model<br/>[tuyalink_core.h]"]
  node_subdevices["Sub-device operations<br/>[tuyalink_core.c]"]
  node_ota["OTA updates"]
  node_endpoint_config["Device endpoint config<br/>[tuya_endpoint.h]"]
end

subgraph group_protocol["Protocol clients"]
  node_mqtt_adapter["MQTT adapter"]
  node_mqtt_engine["MQTT engine<br/>[core_mqtt.c]"]
  node_http_adapter["HTTP adapter"]
  node_http_engine["HTTP engine<br/>[core_http_client.c]"]
  node_json["JSON parser<br/>[core_json.c]"]
end

subgraph group_platform["Platform adapters"]
  node_tls_network["POSIX TLS network"]
  node_network_adapter["POSIX network adapter<br/>[network_wrapper.c]"]
  node_storage[("Local storage<br/>[storage_wrapper.c]")]
  node_platform_api["Platform interfaces"]
end

subgraph group_security["Security and utilities"]
  node_crypto["Mbed TLS<br/>[ssl_tls.c]"]
  node_cipher["Cipher wrapper<br/>[cipher_wrapper.c]"]
end

node_developer(("Device developer"))
node_tuya_cloud(("Tuya IoT Core"))

node_developer -->|"provides credentials"| node_endpoint_config
node_developer -->|"initializes client"| node_tuya_core
node_tuya_core -->|"uses MQTT API"| node_mqtt_adapter
node_mqtt_adapter -->|"initializes client"| node_mqtt_engine
node_tuya_core -->|"parses messages"| node_json
node_model -->|"defines messages"| node_tuya_core
node_subdevices -->|"sends operations"| node_tuya_core
node_tuya_core -->|"exchanges messages"| node_tuya_cloud
node_tuya_core -->|"reports properties"| node_model
node_activation -->|"uses local storage"| node_storage
node_http_adapter -->|"sends requests"| node_http_engine
node_http_adapter -->|"connects TLS"| node_tls_network
node_mqtt_adapter -->|"uses system API"| node_platform_api
node_http_adapter -->|"uses system API"| node_platform_api
node_network_adapter -.->|"implements network API"| node_platform_api
node_tls_network -->|"uses TLS"| node_crypto
node_cipher -.->|"uses cryptography"| node_crypto
node_ota -.->|"supports OTA"| node_tuya_cloud

click node_activation "https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuya_endpoint.c"
click node_tuya_core "https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuyalink_core.c"
click node_model "https://github.com/tuya/tuya-iot-core-sdk/blob/main/include/tuyalink_core.h"
click node_subdevices "https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuyalink_core.c"
click node_ota "https://github.com/tuya/tuya-iot-core-sdk/tree/main/src"
click node_endpoint_config "https://github.com/tuya/tuya-iot-core-sdk/blob/main/include/tuya_endpoint.h"
click node_mqtt_adapter "https://github.com/tuya/tuya-iot-core-sdk/blob/main/middleware/mqtt_client_wrapper.c"
click node_mqtt_engine "https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/coreMQTT/source/core_mqtt.c"
click node_http_adapter "https://github.com/tuya/tuya-iot-core-sdk/blob/main/middleware/http_client_wrapper.c"
click node_http_engine "https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/coreHTTP/source/core_http_client.c"
click node_json "https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/coreJSON/source/core_json.c"
click node_tls_network "https://github.com/tuya/tuya-iot-core-sdk/blob/main/platform/posix/mbedtls_sockets_wrapper.c"
click node_network_adapter "https://github.com/tuya/tuya-iot-core-sdk/blob/main/platform/posix/network_wrapper.c"
click node_storage "https://github.com/tuya/tuya-iot-core-sdk/blob/main/platform/posix/storage_wrapper.c"
click node_platform_api "https://github.com/tuya/tuya-iot-core-sdk/tree/main/interface"
click node_crypto "https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/mbedtls/library/ssl_tls.c"
click node_cipher "https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/cipher_wrapper.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_activation,node_tuya_core,node_model,node_subdevices,node_ota,node_endpoint_config toneBlue
class node_mqtt_adapter,node_mqtt_engine,node_http_adapter,node_http_engine,node_json toneAmber
class node_tls_network,node_network_adapter,node_storage,node_platform_api toneMint
class node_crypto,node_cipher toneRose
class node_developer,node_tuya_cloud toneIndigo
```

## Components

### Device workflow

- [Device activation](https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuya_endpoint.c): `src/tuya_endpoint.c`
- [TuyaLink messaging](https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuyalink_core.c): `src/tuyalink_core.c`
- [Thing data model](https://github.com/tuya/tuya-iot-core-sdk/blob/main/include/tuyalink_core.h): `include/tuyalink_core.h`
- [Sub-device operations](https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/tuyalink_core.c): `src/tuyalink_core.c`
- [OTA updates](https://github.com/tuya/tuya-iot-core-sdk/tree/main/src): `src`
- [Device endpoint config](https://github.com/tuya/tuya-iot-core-sdk/blob/main/include/tuya_endpoint.h): `include/tuya_endpoint.h`

### Protocol clients

- [MQTT adapter](https://github.com/tuya/tuya-iot-core-sdk/blob/main/middleware/mqtt_client_wrapper.c): `middleware/mqtt_client_wrapper.c`
- [MQTT engine](https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/coreMQTT/source/core_mqtt.c): `libraries/coreMQTT/source/core_mqtt.c`
- [HTTP adapter](https://github.com/tuya/tuya-iot-core-sdk/blob/main/middleware/http_client_wrapper.c): `middleware/http_client_wrapper.c`
- [HTTP engine](https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/coreHTTP/source/core_http_client.c): `libraries/coreHTTP/source/core_http_client.c`
- [JSON parser](https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/coreJSON/source/core_json.c): `libraries/coreJSON/source/core_json.c`

### Platform adapters

- [POSIX TLS network](https://github.com/tuya/tuya-iot-core-sdk/blob/main/platform/posix/mbedtls_sockets_wrapper.c): `platform/posix/mbedtls_sockets_wrapper.c`
- [POSIX network adapter](https://github.com/tuya/tuya-iot-core-sdk/blob/main/platform/posix/network_wrapper.c): `platform/posix/network_wrapper.c`
- [Local storage](https://github.com/tuya/tuya-iot-core-sdk/blob/main/platform/posix/storage_wrapper.c): `platform/posix/storage_wrapper.c`
- [Platform interfaces](https://github.com/tuya/tuya-iot-core-sdk/tree/main/interface): `interface`

### Security and utilities

- [Mbed TLS](https://github.com/tuya/tuya-iot-core-sdk/blob/main/libraries/mbedtls/library/ssl_tls.c): `libraries/mbedtls/library/ssl_tls.c`
- [Cipher wrapper](https://github.com/tuya/tuya-iot-core-sdk/blob/main/src/cipher_wrapper.c): `src/cipher_wrapper.c`

### Other components

- **Device developer**
- **Tuya IoT Core**

## Connections

- Device developer → Device endpoint config: provides credentials (evidence: `README.md`)
- Device developer → TuyaLink messaging: initializes client (evidence: `README.md`)
- TuyaLink messaging → MQTT adapter: uses MQTT API (evidence: `src/tuyalink_core.c`)
- MQTT adapter → MQTT engine: initializes client (evidence: `middleware/mqtt_client_wrapper.c`)
- TuyaLink messaging → JSON parser: parses messages (evidence: `src/tuyalink_core.c`)
- Thing data model → TuyaLink messaging: defines messages (evidence: `src/tuyalink_core.c`)
- Sub-device operations → TuyaLink messaging: sends operations (evidence: `src/tuyalink_core.c`)
- TuyaLink messaging → Tuya IoT Core: exchanges messages (evidence: `README.md`)
- TuyaLink messaging → Thing data model: reports properties (evidence: `README.md`)
- Device activation → Local storage: uses local storage (evidence: `src/tuya_endpoint.c`)
- HTTP adapter → HTTP engine: sends requests (evidence: `middleware/http_client_wrapper.c`)
- HTTP adapter → POSIX TLS network: connects TLS (evidence: `middleware/http_client_wrapper.c`)
- MQTT adapter → Platform interfaces: uses system API (evidence: `middleware/mqtt_client_wrapper.c`)
- HTTP adapter → Platform interfaces: uses system API (evidence: `middleware/http_client_wrapper.c`)
- POSIX network adapter → Platform interfaces: implements network API
- POSIX TLS network → Mbed TLS: uses TLS (evidence: `platform/posix/mbedtls_sockets_wrapper.c`)
- Cipher wrapper → Mbed TLS: uses cryptography
- OTA updates → Tuya IoT Core: supports OTA (evidence: `README.md`)
