# richard297779/uestc-mooncheck architecture

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

- Interactive diagram: https://gitdiagram.com/richard297779/uestc-mooncheck
- Repository: https://github.com/richard297779/uestc-mooncheck

## Overview

MoonCheck is an ESP32-based nightly check-in appliance. A phone provisions Wi-Fi, credentials, browser fingerprint, location, and schedule over BLE; the firmware connects, synchronizes time, logs into CAS, warms the portal session, enters the check-in app, submits and verifies a check-in, and persists the result. The graph also preserves multi-account operation, diagnostics, notifications, and the documented PC verification path. Unsampled implementations are included where the tree and README establish capabilities; edges are limited to explicit documentation or shown wiring.

Main entry points: [`firmware/src/main.cpp`](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/main.cpp) (Firmware startup and loop), [`firmware/src/command_router.cpp`](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/command_router.cpp) (Command routing), [`firmware/src/checkin_service.cpp`](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/checkin_service.cpp) (Session, probe, and check-in), [`firmware/src/http_client.cpp`](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/http_client.cpp) (HTTP and TLS client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_provision["Provisioning and state"]
  node_ble["BLE provisioning<br/>[ble_service.cpp]"]
  node_commands["Command routing<br/>[command_router.cpp]"]
  node_config[("Persistent configuration<br/>[app_config.cpp]")]
  node_accounts[("Account profiles<br/>[account_store.cpp]")]
end

subgraph group_connectivity["Connectivity and platform access"]
  node_wifi["Wi-Fi management<br/>[wifi_manager.cpp]"]
  node_time["Time service<br/>[time_service.cpp]"]
  node_cas["CAS authentication<br/>[cas_auth.cpp]"]
  node_http["HTTP and TLS client<br/>[http_client.cpp]"]
  node_cookies[("Cookie session jar<br/>[cookie_jar.cpp]")]
  node_crypto["Credential encryption<br/>[crypto_util.cpp]"]
end

subgraph group_checkin["Check-in workflow"]
  node_checkinapi["Portal and check-in API<br/>[checkin_api.cpp]"]
  node_service["Session, probe, and check-in"]
  node_multi["Multi-account runs<br/>[multi_checkin.cpp]"]
end

subgraph group_operations["Scheduling and operations"]
  node_scheduler["Nightly scheduler<br/>[task_scheduler.cpp]"]
  node_main["Firmware startup and loop<br/>[main.cpp]"]
  node_notify["Phone notifications<br/>[notify_service.cpp]"]
  node_led["Status LED<br/>[status_led.cpp]"]
  node_logger["Logs and diagnostics<br/>[logger.cpp]"]
end

subgraph group_pc["PC verification"]
  node_pcverify["PC chain verification<br/>[verify.py]"]
  node_pc_cas["PC CAS client<br/>[wsc_cas.py]"]
  node_pc_checkin["PC check-in client<br/>[wsc_checkin.py]"]
  node_pc_http["PC HTTP and cookies<br/>[wsc_http.py]"]
end

node_operator(("Phone or PC operator"))
node_school["School CAS and check-in platform"]
node_internet["NTP and notification endpoints"]

node_operator -->|"provisions over BLE"| node_ble
node_ble -->|"delivers commands"| node_commands
node_commands -.->|"updates settings"| node_config
node_commands -.->|"requests connection"| node_wifi
node_commands -.->|"runs diagnostics"| node_service
node_main -->|"starts"| node_ble
node_main -->|"initializes"| node_wifi
node_main -->|"initializes"| node_cas
node_main -->|"initializes"| node_checkinapi
node_main -->|"initializes"| node_service
node_main -->|"loads accounts"| node_accounts
node_main -->|"initializes"| node_multi
node_main -->|"initializes"| node_notify
node_main -->|"registers triggers"| node_scheduler
node_main -->|"initializes"| node_commands
node_main -.->|"initializes"| node_time
node_main -.->|"initializes"| node_http
node_main -->|"attaches"| node_cookies
node_wifi -.->|"connects for NTP"| node_internet
node_time -.->|"synchronizes time"| node_internet
node_scheduler -->|"emits triggers"| node_main
node_main -->|"queues scheduled work"| node_commands
node_service -->|"ensures session"| node_cas
node_cas -->|"sends login requests"| node_http
node_http -->|"reads and updates"| node_cookies
node_cas -.->|"encrypts credentials"| node_crypto
node_service -->|"probes and submits"| node_checkinapi
node_checkinapi -->|"calls platform APIs"| node_http
node_checkinapi -->|"uses portal and check-in APIs"| node_school
node_multi -->|"runs per account"| node_service
node_multi -->|"loads profiles"| node_accounts
node_service -->|"persists result"| node_config
node_commands -.->|"requests notification"| node_notify
node_notify -->|"sends HTTP requests"| node_http
node_notify -->|"pushes notifications"| node_internet
node_operator -->|"runs verification"| node_pcverify
node_pcverify -->|"uses"| node_pc_cas
node_pcverify -->|"uses"| node_pc_checkin
node_pcverify -->|"uses"| node_pc_http
node_pc_cas -.->|"sends requests"| node_pc_http
node_pc_checkin -.->|"sends requests"| node_pc_http

click node_ble "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/ble_service.cpp"
click node_commands "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/command_router.cpp"
click node_config "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/app_config.cpp"
click node_accounts "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/account_store.cpp"
click node_wifi "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/wifi_manager.cpp"
click node_time "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/time_service.cpp"
click node_cas "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/cas_auth.cpp"
click node_http "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/http_client.cpp"
click node_cookies "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/cookie_jar.cpp"
click node_crypto "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/crypto_util.cpp"
click node_checkinapi "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/checkin_api.cpp"
click node_service "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/checkin_service.cpp"
click node_multi "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/multi_checkin.cpp"
click node_scheduler "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/task_scheduler.cpp"
click node_main "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/main.cpp"
click node_notify "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/notify_service.cpp"
click node_led "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/status_led.cpp"
click node_logger "https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/logger.cpp"
click node_pcverify "https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/verify.py"
click node_pc_cas "https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/wsc_cas.py"
click node_pc_checkin "https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/wsc_checkin.py"
click node_pc_http "https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/wsc_http.py"

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_ble,node_commands,node_config,node_accounts toneBlue
class node_wifi,node_time,node_cas,node_http,node_cookies,node_crypto toneAmber
class node_checkinapi,node_service,node_multi toneMint
class node_scheduler,node_main,node_notify,node_led,node_logger toneRose
class node_pcverify,node_pc_cas,node_pc_checkin,node_pc_http,node_operator,node_school,node_internet toneIndigo
```

## Components

### Provisioning and state

- [BLE provisioning](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/ble_service.cpp): `firmware/src/ble_service.cpp`
- [Command routing](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/command_router.cpp): `firmware/src/command_router.cpp`
- [Persistent configuration](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/app_config.cpp): `firmware/src/app_config.cpp`
- [Account profiles](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/account_store.cpp): `firmware/src/account_store.cpp`

### Connectivity and platform access

- [Wi-Fi management](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/wifi_manager.cpp): `firmware/src/wifi_manager.cpp`
- [Time service](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/time_service.cpp): `firmware/src/time_service.cpp`
- [CAS authentication](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/cas_auth.cpp): `firmware/src/cas_auth.cpp`
- [HTTP and TLS client](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/http_client.cpp): `firmware/src/http_client.cpp`
- [Cookie session jar](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/cookie_jar.cpp): `firmware/src/cookie_jar.cpp`
- [Credential encryption](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/crypto_util.cpp): `firmware/src/crypto_util.cpp`

### Check-in workflow

- [Portal and check-in API](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/checkin_api.cpp): `firmware/src/checkin_api.cpp`
- [Session, probe, and check-in](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/checkin_service.cpp): `firmware/src/checkin_service.cpp`
- [Multi-account runs](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/multi_checkin.cpp): `firmware/src/multi_checkin.cpp`

### Scheduling and operations

- [Nightly scheduler](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/task_scheduler.cpp): `firmware/src/task_scheduler.cpp`
- [Firmware startup and loop](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/main.cpp): `firmware/src/main.cpp`
- [Phone notifications](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/notify_service.cpp): `firmware/src/notify_service.cpp`
- [Status LED](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/status_led.cpp): `firmware/src/status_led.cpp`
- [Logs and diagnostics](https://github.com/richard297779/uestc-mooncheck/blob/main/firmware/src/logger.cpp): `firmware/src/logger.cpp`

### PC verification

- [PC chain verification](https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/verify.py): `tools/pc_reference/verify.py`
- [PC CAS client](https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/wsc_cas.py): `tools/pc_reference/wsc_cas.py`
- [PC check-in client](https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/wsc_checkin.py): `tools/pc_reference/wsc_checkin.py`
- [PC HTTP and cookies](https://github.com/richard297779/uestc-mooncheck/blob/main/tools/pc_reference/wsc_http.py): `tools/pc_reference/wsc_http.py`

### Other components

- **Phone or PC operator**
- **School CAS and check-in platform**
- **NTP and notification endpoints**

## Connections

- Phone or PC operator → BLE provisioning: provisions over BLE
- BLE provisioning → Command routing: delivers commands
- Command routing → Persistent configuration: updates settings
- Command routing → Wi-Fi management: requests connection
- Command routing → Session, probe, and check-in: runs diagnostics
- Firmware startup and loop → BLE provisioning: starts (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Wi-Fi management: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → CAS authentication: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Portal and check-in API: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Session, probe, and check-in: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Account profiles: loads accounts (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Multi-account runs: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Phone notifications: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Nightly scheduler: registers triggers (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Command routing: initializes (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Time service: initializes
- Firmware startup and loop → HTTP and TLS client: initializes
- Firmware startup and loop → Cookie session jar: attaches (evidence: `firmware/src/main.cpp`)
- Wi-Fi management → NTP and notification endpoints: connects for NTP
- Time service → NTP and notification endpoints: synchronizes time
- Nightly scheduler → Firmware startup and loop: emits triggers (evidence: `firmware/src/main.cpp`)
- Firmware startup and loop → Command routing: queues scheduled work (evidence: `firmware/src/main.cpp`)
- Session, probe, and check-in → CAS authentication: ensures session
- CAS authentication → HTTP and TLS client: sends login requests
- HTTP and TLS client → Cookie session jar: reads and updates
- CAS authentication → Credential encryption: encrypts credentials
- Session, probe, and check-in → Portal and check-in API: probes and submits
- Portal and check-in API → HTTP and TLS client: calls platform APIs
- Portal and check-in API → School CAS and check-in platform: uses portal and check-in APIs
- Multi-account runs → Session, probe, and check-in: runs per account
- Multi-account runs → Account profiles: loads profiles
- Session, probe, and check-in → Persistent configuration: persists result
- Command routing → Phone notifications: requests notification
- Phone notifications → HTTP and TLS client: sends HTTP requests (evidence: `firmware/src/notify_service.cpp`)
- Phone notifications → NTP and notification endpoints: pushes notifications
- Phone or PC operator → PC chain verification: runs verification
- PC chain verification → PC CAS client: uses (evidence: `tools/pc_reference/verify.py`)
- PC chain verification → PC check-in client: uses (evidence: `tools/pc_reference/verify.py`)
- PC chain verification → PC HTTP and cookies: uses (evidence: `tools/pc_reference/verify.py`)
- PC CAS client → PC HTTP and cookies: sends requests
- PC check-in client → PC HTTP and cookies: sends requests
