# toptubby/csharpe-relaycontrol architecture

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

- Interactive diagram: https://gitdiagram.com/toptubby/csharpe-relaycontrol
- Repository: https://github.com/toptubby/csharpe-relaycontrol

## Overview

This repository pairs a Windows Forms controller with ESP firmware for an eight-channel relay setup. The primary workflow is: an operator selects a COM port and toggles GUI channels; the application exchanges checksum-framed state commands with firmware over USB serial; firmware applies the bitmask to relay GPIOs and reports the commanded state back to the GUI. README documents ESP32-C3 and ESP8266 firmware variants and flash restoration. Form and firmware excerpts are partial, so only documented variant behavior and supported interactions are shown.

Main entry points: [`firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino`](https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino) (ESP32-C3 firmware), [`firmware/ESP8266_RelayControl/ESP8266_RelayControl.ino`](https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP8266_RelayControl/ESP8266_RelayControl.ino) (ESP8266 firmware), [`RelayControl/RelayControl/Form1.cs`](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.cs) (Control form), [`RelayControl/RelayControl/Program.cs`](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Program.cs) (App entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Windows controller"]
  node_entry["App entry<br/>[Program.cs]"]
  node_form["Control form<br/>[Form1.cs]"]
  node_controls["Channel controls<br/>[Form1.Designer.cs]"]
  node_protocol["Frame handling<br/>[Form1.cs]"]
  node_status["Status display<br/>[Form1.Designer.cs]"]
end

subgraph group_device["ESP firmware"]
  node_c3["ESP32-C3 firmware"]
  node_esp8266["ESP8266 firmware"]
  node_state[("Saved relay state")]
  node_gpio["Relay GPIO outputs"]
end

subgraph group_hardware["Relay hardware"]
  node_relays["Eight relay channels"]
end

node_operator(("Operator"))
node_serial["USB serial"]

node_operator -->|"launches"| node_entry
node_entry -->|"opens"| node_form
node_operator -->|"selects channels"| node_controls
node_controls -->|"raises events"| node_form
node_form -->|"requests frames"| node_protocol
node_form -->|"opens port"| node_serial
node_protocol -->|"writes frames"| node_serial
node_serial -->|"delivers frames"| node_c3
node_serial -.->|"delivers frames"| node_esp8266
node_c3 -->|"sets outputs"| node_gpio
node_esp8266 -.->|"sets outputs"| node_gpio
node_gpio -->|"drives channels"| node_relays
node_c3 -->|"restores and saves"| node_state
node_esp8266 -.->|"restores and saves"| node_state
node_c3 -->|"returns state"| node_serial
node_esp8266 -.->|"returns state"| node_serial
node_serial -->|"delivers response"| node_protocol
node_protocol -->|"updates display"| node_status

click node_entry "https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Program.cs"
click node_form "https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.cs"
click node_controls "https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.Designer.cs"
click node_protocol "https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.cs"
click node_status "https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.Designer.cs"
click node_c3 "https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino"
click node_esp8266 "https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP8266_RelayControl/ESP8266_RelayControl.ino"
click node_state "https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino"
click node_gpio "https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino"

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_entry,node_form,node_controls,node_protocol,node_status toneBlue
class node_c3,node_esp8266,node_state,node_gpio toneAmber
class node_relays toneMint
class node_operator,node_serial toneIndigo
```

## Components

### Windows controller

- [App entry](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Program.cs): `RelayControl/RelayControl/Program.cs`
- [Control form](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.cs): `RelayControl/RelayControl/Form1.cs`
- [Channel controls](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.Designer.cs): `RelayControl/RelayControl/Form1.Designer.cs`
- [Frame handling](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.cs): `RelayControl/RelayControl/Form1.cs`
- [Status display](https://github.com/toptubby/csharpe-relaycontrol/blob/main/RelayControl/RelayControl/Form1.Designer.cs): `RelayControl/RelayControl/Form1.Designer.cs`

### ESP firmware

- [ESP32-C3 firmware](https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino): `firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino`
- [ESP8266 firmware](https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP8266_RelayControl/ESP8266_RelayControl.ino): `firmware/ESP8266_RelayControl/ESP8266_RelayControl.ino`
- [Saved relay state](https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino): `firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino`
- [Relay GPIO outputs](https://github.com/toptubby/csharpe-relaycontrol/blob/main/firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino): `firmware/ESP32C3_RelayControl/ESP32C3_RelayControl.ino`

### Relay hardware

- **Eight relay channels**

### Other components

- **Operator**
- **USB serial**

## Connections

- Operator → App entry: launches
- App entry → Control form: opens
- Operator → Channel controls: selects channels
- Channel controls → Control form: raises events
- Control form → Frame handling: requests frames
- Control form → USB serial: opens port
- Frame handling → USB serial: writes frames
- USB serial → ESP32-C3 firmware: delivers frames
- USB serial → ESP8266 firmware: delivers frames
- ESP32-C3 firmware → Relay GPIO outputs: sets outputs
- ESP8266 firmware → Relay GPIO outputs: sets outputs
- Relay GPIO outputs → Eight relay channels: drives channels
- ESP32-C3 firmware → Saved relay state: restores and saves
- ESP8266 firmware → Saved relay state: restores and saves
- ESP32-C3 firmware → USB serial: returns state
- ESP8266 firmware → USB serial: returns state
- USB serial → Frame handling: delivers response
- Frame handling → Status display: updates display
