# solomai/esp32-tapgate architecture

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

- Interactive diagram: https://gitdiagram.com/solomai/esp32-tapgate
- Repository: https://github.com/solomai/esp32-tapgate

## Overview

TapGate combines an ESP32 gate-control device with a MAUI client. A client discovers/connects or configures a transport, then sends secured protocol messages; firmware receives them through the channel manager, handles enrollment and authorized commands, and can actuate the gate. BLE, Wi-Fi AP, and MQTT are distinct transport branches; client service management and firmware client/device state are supporting layers. The excerpts show channel dispatch, client persistence, and client transport management, but not the full message-validation or relay path, so uncertain links are omitted or marked unverified.

Main entry points: [`tapgate_firmware/main/channels/channel_manager.cpp`](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/channel_manager.cpp) (Channel manager), [`tapgate_firmware/main/main.cpp`](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/main.cpp) (Message handler), [`tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs`](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs) (Service manager), [`tapgate_firmware/main/channels/ble/ble_channel.cpp`](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/ble/ble_channel.cpp) (BLE channel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile client"]
  node_mobile_ui["Mobile app UI<br/>[MainPage.xaml.cs]"]
  node_client_services["Service manager<br/>[ServiceManager.cs]"]
end

subgraph group_client_transport["Client transports"]
  node_ble_client["BLE client<br/>[BleService.cs]"]
  node_ap_client["AP client<br/>[ApService.cs]"]
  node_mqtt_client["MQTT client<br/>[MqttService.cs]"]
end

subgraph group_device_transport["Device transports"]
  node_channel_manager["Channel manager"]
  node_ble_device["BLE channel<br/>[ble_channel.cpp]"]
  node_ap_device["AP channel<br/>[ap_channel.cpp]"]
  node_mqtt_device["MQTT channel<br/>[mqtt_channel.cpp]"]
end

subgraph group_device_core["Device core"]
  node_firmware_main["Message handler<br/>[main.cpp]"]
  node_client_registry[("Enrolled clients")]
  node_device_context["Device context<br/>[device_ctx.cpp]"]
  node_nvm[("Persistent storage<br/>[nvm.cpp]")]
end

subgraph group_shared_security["Protocol and security"]
  node_protocol_messages["Protocol messages"]
  node_ecies["ECIES security<br/>[ecies.c]"]
end

node_user(("Gate user"))
node_gate_controller["Gate controller"]
node_mqtt_broker["MQTT broker"]

node_user -->|"controls"| node_mobile_ui
node_mobile_ui -.->|"uses services"| node_client_services
node_client_services -->|"routes frames"| node_ble_client
node_client_services -->|"routes frames"| node_ap_client
node_client_services -->|"routes frames"| node_mqtt_client
node_ble_client -->|"exchanges frames"| node_ble_device
node_ap_client -.->|"exchanges frames"| node_ap_device
node_mqtt_client -.->|"publishes frames"| node_mqtt_broker
node_mqtt_broker -.->|"delivers frames"| node_mqtt_device
node_channel_manager -->|"starts and sends"| node_ble_device
node_channel_manager -->|"starts and sends"| node_ap_device
node_channel_manager -->|"starts and sends"| node_mqtt_device
node_ble_device -->|"queues received"| node_channel_manager
node_ap_device -->|"queues received"| node_channel_manager
node_mqtt_device -->|"queues received"| node_channel_manager
node_firmware_main -->|"initializes channels"| node_channel_manager
node_firmware_main -->|"initializes and enrolls"| node_client_registry
node_firmware_main -->|"initializes context"| node_device_context
node_client_registry -->|"reads and writes"| node_nvm
node_firmware_main -.->|"handles messages"| node_protocol_messages
node_firmware_main -.->|"secures messages"| node_ecies
node_firmware_main -.->|"triggers action"| node_gate_controller

click node_mobile_ui "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/UI/MainPage.xaml.cs"
click node_client_services "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs"
click node_ble_client "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/BT/BleService.cs"
click node_ap_client "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/AP/ApService.cs"
click node_mqtt_client "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/mqtt/MqttService.cs"
click node_channel_manager "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/channel_manager.cpp"
click node_ble_device "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/ble/ble_channel.cpp"
click node_ap_device "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/ap/ap_channel.cpp"
click node_mqtt_device "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/mqtt/mqtt_channel.cpp"
click node_firmware_main "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/main.cpp"
click node_client_registry "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/ctx_client/clients_manager.cpp"
click node_device_context "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/ctx_device/device_ctx.cpp"
click node_nvm "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/common/nvm/nvm.cpp"
click node_protocol_messages "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/messages/transport_message.h"
click node_ecies "https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/components/ecies_crypto/ecies.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_mobile_ui,node_client_services,node_user toneBlue
class node_ble_client,node_ap_client,node_mqtt_client toneAmber
class node_channel_manager,node_ble_device,node_ap_device,node_mqtt_device toneMint
class node_firmware_main,node_client_registry,node_device_context,node_nvm toneRose
class node_protocol_messages,node_ecies,node_gate_controller,node_mqtt_broker toneIndigo
```

## Components

### Mobile client

- [Mobile app UI](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/UI/MainPage.xaml.cs): `tapgate_client/MobileClientMAUI/UI/MainPage.xaml.cs`
- [Service manager](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs): `tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs`

### Client transports

- [BLE client](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/BT/BleService.cs): `tapgate_client/MobileClientMAUI/Core/Services/BT/BleService.cs`
- [AP client](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/AP/ApService.cs): `tapgate_client/MobileClientMAUI/Core/Services/AP/ApService.cs`
- [MQTT client](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_client/MobileClientMAUI/Core/Services/mqtt/MqttService.cs): `tapgate_client/MobileClientMAUI/Core/Services/mqtt/MqttService.cs`

### Device transports

- [Channel manager](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/channel_manager.cpp): `tapgate_firmware/main/channels/channel_manager.cpp`
- [BLE channel](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/ble/ble_channel.cpp): `tapgate_firmware/main/channels/ble/ble_channel.cpp`
- [AP channel](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/ap/ap_channel.cpp): `tapgate_firmware/main/channels/ap/ap_channel.cpp`
- [MQTT channel](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/channels/mqtt/mqtt_channel.cpp): `tapgate_firmware/main/channels/mqtt/mqtt_channel.cpp`

### Device core

- [Message handler](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/main.cpp): `tapgate_firmware/main/main.cpp`
- [Enrolled clients](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/ctx_client/clients_manager.cpp): `tapgate_firmware/main/ctx_client/clients_manager.cpp`
- [Device context](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/ctx_device/device_ctx.cpp): `tapgate_firmware/main/ctx_device/device_ctx.cpp`
- [Persistent storage](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/common/nvm/nvm.cpp): `tapgate_firmware/main/common/nvm/nvm.cpp`

### Protocol and security

- [Protocol messages](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/main/messages/transport_message.h): `tapgate_firmware/main/messages/transport_message.h`
- [ECIES security](https://github.com/solomai/esp32-tapgate/blob/main/tapgate_firmware/components/ecies_crypto/ecies.c): `tapgate_firmware/components/ecies_crypto/ecies.c`

### Other components

- **Gate user**
- **Gate controller**
- **MQTT broker**

## Connections

- Gate user → Mobile app UI: controls (evidence: `README.md`)
- Mobile app UI → Service manager: uses services
- Service manager → BLE client: routes frames (evidence: `tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs`)
- Service manager → AP client: routes frames (evidence: `tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs`)
- Service manager → MQTT client: routes frames (evidence: `tapgate_client/MobileClientMAUI/Core/Services/ServiceManager.cs`)
- BLE client → BLE channel: exchanges frames (evidence: `README.md`)
- AP client → AP channel: exchanges frames (evidence: `README.md`)
- MQTT client → MQTT broker: publishes frames (evidence: `README.md`)
- MQTT broker → MQTT channel: delivers frames (evidence: `README.md`)
- Channel manager → BLE channel: starts and sends (evidence: `tapgate_firmware/main/channels/channel_manager.cpp`)
- Channel manager → AP channel: starts and sends (evidence: `tapgate_firmware/main/channels/channel_manager.cpp`)
- Channel manager → MQTT channel: starts and sends (evidence: `tapgate_firmware/main/channels/channel_manager.cpp`)
- BLE channel → Channel manager: queues received (evidence: `tapgate_firmware/main/channels/channel_manager.cpp`)
- AP channel → Channel manager: queues received (evidence: `tapgate_firmware/main/channels/channel_manager.cpp`)
- MQTT channel → Channel manager: queues received (evidence: `tapgate_firmware/main/channels/channel_manager.cpp`)
- Message handler → Channel manager: initializes channels (evidence: `tapgate_firmware/main/main.cpp`)
- Message handler → Enrolled clients: initializes and enrolls (evidence: `tapgate_firmware/main/main.cpp`)
- Message handler → Device context: initializes context (evidence: `tapgate_firmware/main/main.cpp`)
- Enrolled clients → Persistent storage: reads and writes (evidence: `tapgate_firmware/main/ctx_client/clients_manager.cpp`)
- Message handler → Protocol messages: handles messages (evidence: `tapgate_firmware/main/main.cpp`)
- Message handler → ECIES security: secures messages
- Message handler → Gate controller: triggers action
