# esp32-zephyr/esp32_zephyr architecture

> Architecture diagram of the GitHub repository esp32-zephyr/esp32_zephyr, 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/esp32-zephyr/esp32_zephyr
- Repository: https://github.com/esp32-zephyr/esp32_zephyr

## Overview

ESP32 Zephyr is firmware that stores Wi-Fi credentials, connects the board to a network, initializes ADC/PWM, and starts a TCP server for remote commands. The main workflow runs from boot through credential loading and network setup to command handling and hardware or version responses. The README documents TCP clients and service discovery; source excerpts show boot orchestration and command handlers. The server implementation was not sampled, so its connection to command decoding is shown as unverified.

Main entry points: [`src/main.c`](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/main.c) (Firmware startup), [`src/cmd_interpreter.c`](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/cmd_interpreter.c) (Command interpreter), [`src/server.c`](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/server.c) (TCP server), [`src/nvs.c`](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/nvs.c) (Credential storage)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_boot["Boot and connectivity"]
  node_firmware["Firmware startup<br/>[main.c]"]
  node_wifi["Wi-Fi interface<br/>[wifi.c]"]
  node_network(("Wi-Fi network"))
end

subgraph group_commands["TCP command service"]
  node_tcp_server["TCP server<br/>[server.c]"]
  node_command_interpreter["Command interpreter<br/>[cmd_interpreter.c]"]
  node_protocol["Protobuf commands<br/>[cmds.proto]"]
end

subgraph group_hardware["Board peripherals"]
  node_adc["ADC controls<br/>[adc.c]"]
  node_pwm["PWM controls<br/>[pwm.c]"]
end

subgraph group_state["Identity and credentials"]
  node_nvs[("Credential storage<br/>[nvs.c]")]
  node_version["Version identity<br/>[version.h]"]
end

node_tcp_client(("TCP API client"))
node_service_discovery(("Service discovery"))
node_flash[("Device flash")]
node_shell_user(("Device operator"))

node_firmware -->|"prints version"| node_version
node_firmware -->|"loads credentials"| node_nvs
node_firmware -->|"connects with credentials"| node_wifi
node_wifi -->|"connects to"| node_network
node_firmware -->|"initializes"| node_adc
node_firmware -->|"initializes"| node_pwm
node_firmware -->|"creates and starts"| node_tcp_server
node_tcp_client -->|"sends commands"| node_tcp_server
node_tcp_server -.->|"dispatches commands"| node_command_interpreter
node_command_interpreter -->|"encodes and decodes"| node_protocol
node_command_interpreter -->|"reads channels"| node_adc
node_command_interpreter -->|"gets and sets"| node_pwm
node_command_interpreter -->|"reports identity"| node_version
node_shell_user -->|"sets credentials"| node_nvs
node_nvs -->|"reads and writes"| node_flash
node_service_discovery -.->|"locates device"| node_tcp_server

click node_firmware "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/main.c"
click node_wifi "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/wifi.c"
click node_tcp_server "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/server.c"
click node_command_interpreter "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/cmd_interpreter.c"
click node_protocol "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/proto/cmds.proto"
click node_adc "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/adc.c"
click node_pwm "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/pwm.c"
click node_nvs "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/nvs.c"
click node_version "https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/version.h"

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_firmware,node_wifi,node_network,node_tcp_client toneBlue
class node_tcp_server,node_command_interpreter,node_protocol,node_flash toneAmber
class node_adc,node_pwm toneMint
class node_nvs,node_version toneRose
class node_service_discovery,node_shell_user toneIndigo
```

## Components

### Boot and connectivity

- [Firmware startup](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/main.c): `src/main.c`
- [Wi-Fi interface](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/wifi.c): `src/wifi.c`
- **Wi-Fi network**

### TCP command service

- [TCP server](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/server.c): `src/server.c`
- [Command interpreter](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/cmd_interpreter.c): `src/cmd_interpreter.c`
- [Protobuf commands](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/proto/cmds.proto): `proto/cmds.proto`

### Board peripherals

- [ADC controls](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/adc.c): `src/adc.c`
- [PWM controls](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/pwm.c): `src/pwm.c`

### Identity and credentials

- [Credential storage](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/nvs.c): `src/nvs.c`
- [Version identity](https://github.com/esp32-zephyr/esp32_zephyr/blob/main/src/version.h): `src/version.h`

### Other components

- **TCP API client**
- **Service discovery**
- **Device flash**
- **Device operator**

## Connections

- Firmware startup → Version identity: prints version (evidence: `src/main.c`)
- Firmware startup → Credential storage: loads credentials (evidence: `src/main.c`)
- Firmware startup → Wi-Fi interface: connects with credentials (evidence: `src/main.c`)
- Wi-Fi interface → Wi-Fi network: connects to (evidence: `src/wifi.c`)
- Firmware startup → ADC controls: initializes (evidence: `src/main.c`)
- Firmware startup → PWM controls: initializes (evidence: `src/main.c`)
- Firmware startup → TCP server: creates and starts (evidence: `src/main.c`)
- TCP API client → TCP server: sends commands (evidence: `README.md`)
- TCP server → Command interpreter: dispatches commands
- Command interpreter → Protobuf commands: encodes and decodes
- Command interpreter → ADC controls: reads channels (evidence: `src/cmd_interpreter.c`)
- Command interpreter → PWM controls: gets and sets (evidence: `src/cmd_interpreter.c`)
- Command interpreter → Version identity: reports identity (evidence: `src/cmd_interpreter.c`)
- Device operator → Credential storage: sets credentials (evidence: `src/nvs.c`)
- Credential storage → Device flash: reads and writes (evidence: `src/nvs.c`)
- Service discovery → TCP server: locates device
