# anszom/rethink architecture

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

- Interactive diagram: https://gitdiagram.com/anszom/rethink
- Repository: https://github.com/anszom/rethink

## Overview

rethink is a local replacement for LG ThinQ’s cloud service: it receives appliance traffic, translates device state and commands into Home Assistant-compatible MQTT, and optionally forwards traffic to LG’s cloud for coexistence or reverse engineering. The main stages are ThinQ connectivity, device/model interpretation, and Home Assistant publication; management exposes runtime controls. The bridge has separate authentication and forwarding responsibilities. Some runtime entry-point and protocol files were not sampled, so those links rely on README statements or are omitted where the caller is not evidenced.

Main entry points: [`bridge/index.ts`](https://github.com/anszom/rethink/blob/master/bridge/index.ts) (Bridge coordinator), [`cloud/devmgr.ts`](https://github.com/anszom/rethink/blob/master/cloud/devmgr.ts) (Device manager), [`management/index.ts`](https://github.com/anszom/rethink/blob/master/management/index.ts) (Management API), [`cloud/thinq2/device.ts`](https://github.com/anszom/rethink/blob/master/cloud/thinq2/device.ts) (ThinQ2 connection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and management"]
  node_runtime["Cloud service<br/>[rethink-cloud.ts]"]
  node_management["Management API<br/>[index.ts]"]
  node_device_manager["Device manager<br/>[devmgr.ts]"]
  node_config["Runtime configuration<br/>[config.ts]"]
end

subgraph group_protocol["ThinQ protocols"]
  node_mqtt_broker["Device MQTT broker<br/>[mqtt-broker.ts]"]
  node_t1["ThinQ1 connection<br/>[device.ts]"]
  node_t2["ThinQ2 connection<br/>[device.ts]"]
  node_clip["CLIP messages<br/>[clip.ts]"]
end

subgraph group_translation["Device translation"]
  node_device_adapters["Appliance adapters"]
  node_adapter_base["Adapter base<br/>[base.ts]"]
  node_ha_bridge["Home Assistant translation<br/>[ha_bridge.ts]"]
  node_ha_mqtt["Home Assistant MQTT<br/>[homeassistant.ts]"]
end

subgraph group_bridge["LG cloud bridge"]
  node_bridge_api["ThinQ API client<br/>[thinqApi.ts]"]
  node_oauth["OAuth2<br/>[oauth2.ts]"]
  node_bridge_service["Bridge coordinator<br/>[index.ts]"]
  node_bridge_t1["ThinQ1 forwarding"]
  node_bridge_t2["ThinQ2 forwarding"]
end

node_user(("Operator"))
node_appliance(("LG appliances"))
node_ha(("Home Assistant"))
node_lgcloud(("LG ThinQ cloud"))

node_user -->|"controls"| node_management
node_appliance -->|"connects to"| node_runtime
node_runtime -.->|"emulates ThinQ1"| node_t1
node_runtime -.->|"emulates ThinQ2"| node_t2
node_t2 -->|"uses broker"| node_mqtt_broker
node_t2 -->|"parses messages"| node_clip
node_t1 -.->|"registers devices"| node_device_manager
node_t2 -->|"registers devices"| node_device_manager
node_device_manager -->|"announces devices"| node_ha_bridge
node_ha_bridge -->|"selects model adapter"| node_device_adapters
node_device_adapters -->|"extends base"| node_adapter_base
node_ha_bridge -->|"translates properties"| node_ha_mqtt
node_ha_mqtt -->|"publishes MQTT"| node_ha
node_ha -->|"sends commands"| node_ha_mqtt
node_management -->|"manages devices"| node_device_manager
node_management -->|"observes status"| node_ha_bridge
node_management -->|"controls bridge"| node_bridge_service
node_bridge_service -->|"tracks devices"| node_device_manager
node_bridge_service -->|"authenticates and adds"| node_bridge_api
node_bridge_api -->|"requests tokens"| node_oauth
node_bridge_service -->|"forwards ThinQ1"| node_bridge_t1
node_bridge_service -.->|"forwards ThinQ2"| node_bridge_t2
node_bridge_t1 -->|"forwards traffic"| node_lgcloud
node_bridge_t2 -->|"forwards traffic"| node_lgcloud
node_config -->|"configures connection"| node_ha_mqtt

click node_runtime "https://github.com/anszom/rethink/blob/master/rethink-cloud.ts"
click node_management "https://github.com/anszom/rethink/blob/master/management/index.ts"
click node_device_manager "https://github.com/anszom/rethink/blob/master/cloud/devmgr.ts"
click node_mqtt_broker "https://github.com/anszom/rethink/blob/master/cloud/mqtt-broker.ts"
click node_t1 "https://github.com/anszom/rethink/blob/master/cloud/thinq1/device.ts"
click node_t2 "https://github.com/anszom/rethink/blob/master/cloud/thinq2/device.ts"
click node_clip "https://github.com/anszom/rethink/blob/master/cloud/thinq2/clip.ts"
click node_device_adapters "https://github.com/anszom/rethink/tree/master/cloud/devices"
click node_adapter_base "https://github.com/anszom/rethink/blob/master/cloud/devices/base.ts"
click node_ha_bridge "https://github.com/anszom/rethink/blob/master/cloud/ha_bridge.ts"
click node_ha_mqtt "https://github.com/anszom/rethink/blob/master/cloud/homeassistant.ts"
click node_config "https://github.com/anszom/rethink/blob/master/util/config.ts"
click node_bridge_api "https://github.com/anszom/rethink/blob/master/bridge/thinqApi.ts"
click node_oauth "https://github.com/anszom/rethink/blob/master/bridge/oauth2.ts"
click node_bridge_service "https://github.com/anszom/rethink/blob/master/bridge/index.ts"
click node_bridge_t1 "https://github.com/anszom/rethink/blob/master/bridge/thinq1connection.ts"
click node_bridge_t2 "https://github.com/anszom/rethink/blob/master/bridge/thinq2connection.ts"

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_runtime,node_management,node_device_manager,node_config toneBlue
class node_mqtt_broker,node_t1,node_t2,node_clip toneAmber
class node_device_adapters,node_adapter_base,node_ha_bridge,node_ha_mqtt toneMint
class node_bridge_api,node_oauth,node_bridge_service,node_bridge_t1,node_bridge_t2 toneRose
class node_user,node_appliance,node_ha,node_lgcloud toneIndigo
```

## Components

### Runtime and management

- [Cloud service](https://github.com/anszom/rethink/blob/master/rethink-cloud.ts): `rethink-cloud.ts`
- [Management API](https://github.com/anszom/rethink/blob/master/management/index.ts): `management/index.ts`
- [Device manager](https://github.com/anszom/rethink/blob/master/cloud/devmgr.ts): `cloud/devmgr.ts`
- [Runtime configuration](https://github.com/anszom/rethink/blob/master/util/config.ts): `util/config.ts`

### ThinQ protocols

- [Device MQTT broker](https://github.com/anszom/rethink/blob/master/cloud/mqtt-broker.ts): `cloud/mqtt-broker.ts`
- [ThinQ1 connection](https://github.com/anszom/rethink/blob/master/cloud/thinq1/device.ts): `cloud/thinq1/device.ts`
- [ThinQ2 connection](https://github.com/anszom/rethink/blob/master/cloud/thinq2/device.ts): `cloud/thinq2/device.ts`
- [CLIP messages](https://github.com/anszom/rethink/blob/master/cloud/thinq2/clip.ts): `cloud/thinq2/clip.ts`

### Device translation

- [Appliance adapters](https://github.com/anszom/rethink/tree/master/cloud/devices): `cloud/devices`
- [Adapter base](https://github.com/anszom/rethink/blob/master/cloud/devices/base.ts): `cloud/devices/base.ts`
- [Home Assistant translation](https://github.com/anszom/rethink/blob/master/cloud/ha_bridge.ts): `cloud/ha_bridge.ts`
- [Home Assistant MQTT](https://github.com/anszom/rethink/blob/master/cloud/homeassistant.ts): `cloud/homeassistant.ts`

### LG cloud bridge

- [ThinQ API client](https://github.com/anszom/rethink/blob/master/bridge/thinqApi.ts): `bridge/thinqApi.ts`
- [OAuth2](https://github.com/anszom/rethink/blob/master/bridge/oauth2.ts): `bridge/oauth2.ts`
- [Bridge coordinator](https://github.com/anszom/rethink/blob/master/bridge/index.ts): `bridge/index.ts`
- [ThinQ1 forwarding](https://github.com/anszom/rethink/blob/master/bridge/thinq1connection.ts): `bridge/thinq1connection.ts`
- [ThinQ2 forwarding](https://github.com/anszom/rethink/blob/master/bridge/thinq2connection.ts): `bridge/thinq2connection.ts`

### Other components

- **Operator**
- **LG appliances**
- **Home Assistant**
- **LG ThinQ cloud**

## Connections

- Operator → Management API: controls (evidence: `README.md`)
- LG appliances → Cloud service: connects to (evidence: `README.md`)
- Cloud service → ThinQ1 connection: emulates ThinQ1
- Cloud service → ThinQ2 connection: emulates ThinQ2
- ThinQ2 connection → Device MQTT broker: uses broker (evidence: `cloud/thinq2/device.ts`)
- ThinQ2 connection → CLIP messages: parses messages (evidence: `cloud/thinq2/device.ts`)
- ThinQ1 connection → Device manager: registers devices (evidence: `cloud/devmgr.ts`)
- ThinQ2 connection → Device manager: registers devices (evidence: `cloud/devmgr.ts`)
- Device manager → Home Assistant translation: announces devices (evidence: `cloud/ha_bridge.ts`)
- Home Assistant translation → Appliance adapters: selects model adapter (evidence: `cloud/ha_bridge.ts`)
- Appliance adapters → Adapter base: extends base (evidence: `cloud/devices/F3P2CYUBE__.ts`)
- Home Assistant translation → Home Assistant MQTT: translates properties (evidence: `cloud/ha_bridge.ts`)
- Home Assistant MQTT → Home Assistant: publishes MQTT (evidence: `README.md`)
- Home Assistant → Home Assistant MQTT: sends commands (evidence: `cloud/homeassistant.ts`)
- Management API → Device manager: manages devices (evidence: `management/index.ts`)
- Management API → Home Assistant translation: observes status (evidence: `management/index.ts`)
- Management API → Bridge coordinator: controls bridge (evidence: `management/index.ts`)
- Bridge coordinator → Device manager: tracks devices (evidence: `bridge/index.ts`)
- Bridge coordinator → ThinQ API client: authenticates and adds (evidence: `bridge/index.ts`)
- ThinQ API client → OAuth2: requests tokens (evidence: `bridge/thinqApi.ts`)
- Bridge coordinator → ThinQ1 forwarding: forwards ThinQ1 (evidence: `bridge/index.ts`)
- Bridge coordinator → ThinQ2 forwarding: forwards ThinQ2 (evidence: `bridge/index.ts`)
- ThinQ1 forwarding → LG ThinQ cloud: forwards traffic (evidence: `README.md`)
- ThinQ2 forwarding → LG ThinQ cloud: forwards traffic (evidence: `README.md`)
- Runtime configuration → Home Assistant MQTT: configures connection (evidence: `cloud/homeassistant.ts`)
