# espressif/esp-rainmaker-common architecture

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

- Interactive diagram: https://gitdiagram.com/espressif/esp-rainmaker-common
- Repository: https://github.com/espressif/esp-rainmaker-common

## Overview

ESP RainMaker Common is an ESP-IDF component library of reusable device-side services for RainMaker and Diagnostics. An integrating firmware calls the selected module APIs; the modules provide MQTT transport, device identity/storage and memory helpers, command/console facilities, system controls, time services, and background work. The README establishes the capabilities, while sampled code confirms MQTT subscription retry/event behavior and console commands invoking system-control and time APIs. Several component implementations are unsampled, so their internal links are omitted.

Main entry points: [`components/rmaker_console/src/rmaker_common_cmds.c`](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_console/src/rmaker_common_cmds.c) (Common commands), [`include/esp_rmaker_utils.h`](https://github.com/espressif/esp-rainmaker-common/blob/master/include/esp_rmaker_utils.h) (Utility APIs), [`src/esp-mqtt/esp-mqtt-glue.c`](https://github.com/espressif/esp-rainmaker-common/blob/master/src/esp-mqtt/esp-mqtt-glue.c) (MQTT glue), [`components/rmaker_system_ctrl/src/system_ctrl.c`](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_system_ctrl/src/system_ctrl.c) (System control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_transport["Messaging"]
  node_mqtt["MQTT glue<br/>[esp-mqtt-glue.c]"]
  node_mqtt_client["MQTT broker/client"]
  node_events["Common events<br/>[common_events.c]"]
  node_command_response["Command-response<br/>[cmd_resp.c]"]
end

subgraph group_device["Device Services"]
  node_factory["Factory NVS helpers<br/>[factory.c]"]
  node_system["System control<br/>[system_ctrl.c]"]
  node_time_sync["Time synchronization<br/>[time_sync.c]"]
  node_timezone["Timezone APIs<br/>[timezone.c]"]
end

subgraph group_console["Command Interface"]
  node_console["Console service<br/>[rmaker_console.c]"]
  node_common_commands["Common commands"]
end

subgraph group_runtime["Runtime Utilities"]
  node_work_queue["Work queue<br/>[work_queue.c]"]
  node_memory["Memory allocation"]
  node_utils["Utility APIs<br/>[esp_rmaker_utils.h]"]
  node_ppi["MQTT identity string"]
end

node_firmware(("RainMaker firmware"))

node_firmware -->|"configures"| node_mqtt
node_firmware -->|"uses"| node_factory
node_firmware -->|"uses"| node_command_response
node_firmware -->|"uses"| node_console
node_firmware -->|"controls"| node_system
node_firmware -->|"syncs time"| node_time_sync
node_firmware -->|"sets timezone"| node_timezone
node_firmware -->|"schedules work"| node_work_queue
node_firmware -->|"allocates memory"| node_memory
node_mqtt -->|"communicates"| node_mqtt_client
node_mqtt -->|"posts events"| node_events
node_mqtt -->|"defers retry"| node_work_queue
node_console -->|"registers"| node_common_commands
node_common_commands -->|"invokes controls"| node_system
node_common_commands -->|"reads local time"| node_time_sync
node_common_commands -->|"sets timezone"| node_timezone
node_common_commands -->|"allocates buffers"| node_memory
node_utils -->|"exposes"| node_events
node_utils -->|"exposes"| node_memory
node_utils -->|"exposes"| node_time_sync
node_utils -->|"exposes"| node_system
node_firmware -->|"generates identity"| node_ppi

click node_mqtt "https://github.com/espressif/esp-rainmaker-common/blob/master/src/esp-mqtt/esp-mqtt-glue.c"
click node_events "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_common_events/src/common_events.c"
click node_command_response "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_cmd_resp/src/cmd_resp.c"
click node_factory "https://github.com/espressif/esp-rainmaker-common/blob/master/src/factory.c"
click node_system "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_system_ctrl/src/system_ctrl.c"
click node_time_sync "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_time_sync/src/time_sync.c"
click node_timezone "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_time_sync/src/timezone.c"
click node_console "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_console/src/rmaker_console.c"
click node_common_commands "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_console/src/rmaker_common_cmds.c"
click node_work_queue "https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_work_queue/src/work_queue.c"
click node_memory "https://github.com/espressif/esp-rainmaker-common/blob/master/include/esp_rmaker_mem_alloc.h"
click node_utils "https://github.com/espressif/esp-rainmaker-common/blob/master/include/esp_rmaker_utils.h"
click node_ppi "https://github.com/espressif/esp-rainmaker-common/blob/master/src/create_APN3_PPI_string.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_mqtt,node_mqtt_client,node_events,node_command_response toneBlue
class node_factory,node_system,node_time_sync,node_timezone toneAmber
class node_console,node_common_commands toneMint
class node_work_queue,node_memory,node_utils,node_ppi toneRose
class node_firmware toneIndigo
```

## Components

### Messaging

- [MQTT glue](https://github.com/espressif/esp-rainmaker-common/blob/master/src/esp-mqtt/esp-mqtt-glue.c): `src/esp-mqtt/esp-mqtt-glue.c`
- **MQTT broker/client**
- [Common events](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_common_events/src/common_events.c): `components/rmaker_common_events/src/common_events.c`
- [Command-response](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_cmd_resp/src/cmd_resp.c): `components/rmaker_cmd_resp/src/cmd_resp.c`

### Device Services

- [Factory NVS helpers](https://github.com/espressif/esp-rainmaker-common/blob/master/src/factory.c): `src/factory.c`
- [System control](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_system_ctrl/src/system_ctrl.c): `components/rmaker_system_ctrl/src/system_ctrl.c`
- [Time synchronization](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_time_sync/src/time_sync.c): `components/rmaker_time_sync/src/time_sync.c`
- [Timezone APIs](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_time_sync/src/timezone.c): `components/rmaker_time_sync/src/timezone.c`

### Command Interface

- [Console service](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_console/src/rmaker_console.c): `components/rmaker_console/src/rmaker_console.c`
- [Common commands](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_console/src/rmaker_common_cmds.c): `components/rmaker_console/src/rmaker_common_cmds.c`

### Runtime Utilities

- [Work queue](https://github.com/espressif/esp-rainmaker-common/blob/master/components/rmaker_work_queue/src/work_queue.c): `components/rmaker_work_queue/src/work_queue.c`
- [Memory allocation](https://github.com/espressif/esp-rainmaker-common/blob/master/include/esp_rmaker_mem_alloc.h): `include/esp_rmaker_mem_alloc.h`
- [Utility APIs](https://github.com/espressif/esp-rainmaker-common/blob/master/include/esp_rmaker_utils.h): `include/esp_rmaker_utils.h`
- [MQTT identity string](https://github.com/espressif/esp-rainmaker-common/blob/master/src/create_APN3_PPI_string.c): `src/create_APN3_PPI_string.c`

### Other components

- **RainMaker firmware**

## Connections

- RainMaker firmware → MQTT glue: configures (evidence: `README.md`)
- RainMaker firmware → Factory NVS helpers: uses (evidence: `README.md`)
- RainMaker firmware → Command-response: uses (evidence: `README.md`)
- RainMaker firmware → Console service: uses (evidence: `README.md`)
- RainMaker firmware → System control: controls (evidence: `README.md`)
- RainMaker firmware → Time synchronization: syncs time (evidence: `README.md`)
- RainMaker firmware → Timezone APIs: sets timezone (evidence: `README.md`)
- RainMaker firmware → Work queue: schedules work (evidence: `README.md`)
- RainMaker firmware → Memory allocation: allocates memory (evidence: `README.md`)
- MQTT glue → MQTT broker/client: communicates (evidence: `src/esp-mqtt/esp-mqtt-glue.c`)
- MQTT glue → Common events: posts events (evidence: `src/esp-mqtt/esp-mqtt-glue.c`)
- MQTT glue → Work queue: defers retry (evidence: `src/esp-mqtt/esp-mqtt-glue.c`)
- Console service → Common commands: registers (evidence: `components/rmaker_console/src/rmaker_common_cmds.c`)
- Common commands → System control: invokes controls (evidence: `components/rmaker_console/src/rmaker_common_cmds.c`)
- Common commands → Time synchronization: reads local time (evidence: `components/rmaker_console/src/rmaker_common_cmds.c`)
- Common commands → Timezone APIs: sets timezone (evidence: `components/rmaker_console/src/rmaker_common_cmds.c`)
- Common commands → Memory allocation: allocates buffers (evidence: `components/rmaker_console/src/rmaker_common_cmds.c`)
- Utility APIs → Common events: exposes (evidence: `include/esp_rmaker_utils.h`)
- Utility APIs → Memory allocation: exposes (evidence: `include/esp_rmaker_utils.h`)
- Utility APIs → Time synchronization: exposes (evidence: `include/esp_rmaker_utils.h`)
- Utility APIs → System control: exposes (evidence: `include/esp_rmaker_utils.h`)
- RainMaker firmware → MQTT identity string: generates identity (evidence: `README.md`)
