# nikomalik/esp32-block architecture

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

- Interactive diagram: https://gitdiagram.com/nikomalik/esp32-block
- Repository: https://github.com/nikomalik/esp32-block

## Overview

ESP32 AdBlock is a Wi-Fi DNS sinkhole with a browser dashboard and phone-based provisioning. The main workflow is: provision Wi-Fi, receive DNS queries, check blocked domains, then sinkhole or forward them; the dashboard exposes stats and controls, including client bans and blocklist updates. The blocklist builder and firmware reader share a compact format. Some connections rely on README documentation or SOURCE INDEX references because several implementation files were not excerpted.

Main entry points: [`src/web.cpp`](https://github.com/nikomalik/esp32-block/blob/main/src/web.cpp) (HTTP dashboard API), [`src/blocklist.cpp`](https://github.com/nikomalik/esp32-block/blob/main/src/blocklist.cpp) (Blocklist lookup), [`src/main.cpp`](https://github.com/nikomalik/esp32-block/blob/main/src/main.cpp) (Firmware startup), [`src/dns.cpp`](https://github.com/nikomalik/esp32-block/blob/main/src/dns.cpp) (DNS sinkhole)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_provision["Wi-Fi Provisioning"]
  node_main["Firmware startup<br/>[main.cpp]"]
  node_wifi["Wi-Fi and portal<br/>[wifi.cpp]"]
end

subgraph group_filter["DNS Filtering"]
  node_dns["DNS sinkhole<br/>[dns.cpp]"]
  node_hash["Domain hashing<br/>[fxhash.h]"]
end

subgraph group_lists["Blocklist Lifecycle"]
  node_blocklist["Blocklist lookup<br/>[blocklist.cpp]"]
  node_format["Blocklist format<br/>[blfmt.h]"]
  node_builder["List builder"]
  node_flashlist[("Raw flash list<br/>[blocklist.cpp]")]
end

subgraph group_dashboard["Dashboard Controls"]
  node_webbackend["HTTP dashboard API<br/>[web.cpp]"]
  node_page["Dashboard UI<br/>[page.h]"]
end

subgraph group_state["Client State"]
  node_clients["Device counters and bans<br/>[clients.cpp]"]
  node_runtimefs[("Runtime state<br/>[clients.cpp]")]
end

node_phone(("Setup phone"))
node_routerclients(("Network devices"))
node_upstream(("DNS upstream"))
node_browser(("Dashboard browser"))

node_main -->|"starts"| node_wifi
node_main -->|"starts"| node_dns
node_main -->|"starts"| node_webbackend
node_main -->|"initializes"| node_blocklist
node_main -->|"loads bans"| node_clients
node_phone -->|"provisions"| node_wifi
node_wifi -->|"joins network"| node_main
node_routerclients -->|"sends queries"| node_dns
node_dns -->|"checks domains"| node_blocklist
node_dns -->|"updates counters"| node_clients
node_dns -->|"forwards allowed"| node_upstream
node_blocklist -->|"hashes domains"| node_hash
node_blocklist -->|"maps and reads"| node_flashlist
node_builder -->|"hashes domains"| node_hash
node_builder -->|"writes format"| node_format
node_format -->|"defines reader layout"| node_blocklist
node_builder -->|"produces blob"| node_flashlist
node_browser -->|"loads dashboard"| node_page
node_page -->|"calls endpoints"| node_webbackend
node_webbackend -->|"updates custom list"| node_blocklist
node_webbackend -->|"streams list updates"| node_blocklist
node_webbackend -->|"controls pause"| node_dns
node_webbackend -->|"toggles bans"| node_clients
node_clients -->|"persists bans"| node_runtimefs
node_webbackend -->|"stores update config"| node_runtimefs
node_webbackend -->|"clears credentials"| node_wifi

click node_main "https://github.com/nikomalik/esp32-block/blob/main/src/main.cpp"
click node_wifi "https://github.com/nikomalik/esp32-block/blob/main/src/wifi.cpp"
click node_dns "https://github.com/nikomalik/esp32-block/blob/main/src/dns.cpp"
click node_hash "https://github.com/nikomalik/esp32-block/blob/main/src/fxhash.h"
click node_blocklist "https://github.com/nikomalik/esp32-block/blob/main/src/blocklist.cpp"
click node_format "https://github.com/nikomalik/esp32-block/blob/main/src/blfmt.h"
click node_builder "https://github.com/nikomalik/esp32-block/blob/main/tools/build_blocklist.cpp"
click node_flashlist "https://github.com/nikomalik/esp32-block/blob/main/src/blocklist.cpp"
click node_webbackend "https://github.com/nikomalik/esp32-block/blob/main/src/web.cpp"
click node_page "https://github.com/nikomalik/esp32-block/blob/main/src/page.h"
click node_clients "https://github.com/nikomalik/esp32-block/blob/main/src/clients.cpp"
click node_runtimefs "https://github.com/nikomalik/esp32-block/blob/main/src/clients.cpp"

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_main,node_wifi,node_browser toneBlue
class node_dns,node_hash toneAmber
class node_blocklist,node_format,node_builder,node_flashlist toneMint
class node_webbackend,node_page toneRose
class node_clients,node_runtimefs,node_phone,node_routerclients,node_upstream toneIndigo
```

## Components

### Wi-Fi Provisioning

- [Firmware startup](https://github.com/nikomalik/esp32-block/blob/main/src/main.cpp): `src/main.cpp`
- [Wi-Fi and portal](https://github.com/nikomalik/esp32-block/blob/main/src/wifi.cpp): `src/wifi.cpp`

### DNS Filtering

- [DNS sinkhole](https://github.com/nikomalik/esp32-block/blob/main/src/dns.cpp): `src/dns.cpp`
- [Domain hashing](https://github.com/nikomalik/esp32-block/blob/main/src/fxhash.h): `src/fxhash.h`

### Blocklist Lifecycle

- [Blocklist lookup](https://github.com/nikomalik/esp32-block/blob/main/src/blocklist.cpp): `src/blocklist.cpp`
- [Blocklist format](https://github.com/nikomalik/esp32-block/blob/main/src/blfmt.h): `src/blfmt.h`
- [List builder](https://github.com/nikomalik/esp32-block/blob/main/tools/build_blocklist.cpp): `tools/build_blocklist.cpp`
- [Raw flash list](https://github.com/nikomalik/esp32-block/blob/main/src/blocklist.cpp): `src/blocklist.cpp`

### Dashboard Controls

- [HTTP dashboard API](https://github.com/nikomalik/esp32-block/blob/main/src/web.cpp): `src/web.cpp`
- [Dashboard UI](https://github.com/nikomalik/esp32-block/blob/main/src/page.h): `src/page.h`

### Client State

- [Device counters and bans](https://github.com/nikomalik/esp32-block/blob/main/src/clients.cpp): `src/clients.cpp`
- [Runtime state](https://github.com/nikomalik/esp32-block/blob/main/src/clients.cpp): `src/clients.cpp`

### Other components

- **Setup phone**
- **Network devices**
- **DNS upstream**
- **Dashboard browser**

## Connections

- Firmware startup → Wi-Fi and portal: starts (evidence: `src/main.cpp`)
- Firmware startup → DNS sinkhole: starts (evidence: `src/main.cpp`)
- Firmware startup → HTTP dashboard API: starts (evidence: `src/main.cpp`)
- Firmware startup → Blocklist lookup: initializes (evidence: `src/main.cpp`)
- Firmware startup → Device counters and bans: loads bans (evidence: `src/main.cpp`)
- Setup phone → Wi-Fi and portal: provisions (evidence: `README.md`)
- Wi-Fi and portal → Firmware startup: joins network (evidence: `src/main.cpp`)
- Network devices → DNS sinkhole: sends queries (evidence: `README.md`)
- DNS sinkhole → Blocklist lookup: checks domains (evidence: `src/dns.cpp`)
- DNS sinkhole → Device counters and bans: updates counters (evidence: `src/dns.cpp`)
- DNS sinkhole → DNS upstream: forwards allowed
- Blocklist lookup → Domain hashing: hashes domains
- Blocklist lookup → Raw flash list: maps and reads (evidence: `README.md`)
- List builder → Domain hashing: hashes domains (evidence: `tools/build_blocklist.cpp`)
- List builder → Blocklist format: writes format (evidence: `tools/build_blocklist.cpp`)
- Blocklist format → Blocklist lookup: defines reader layout (evidence: `src/blfmt.h`)
- List builder → Raw flash list: produces blob (evidence: `README.md`)
- Dashboard browser → Dashboard UI: loads dashboard (evidence: `README.md`)
- Dashboard UI → HTTP dashboard API: calls endpoints (evidence: `src/page.h`)
- HTTP dashboard API → Blocklist lookup: updates custom list (evidence: `src/web.cpp`)
- HTTP dashboard API → Blocklist lookup: streams list updates (evidence: `src/web.cpp`)
- HTTP dashboard API → DNS sinkhole: controls pause (evidence: `src/web.cpp`)
- HTTP dashboard API → Device counters and bans: toggles bans (evidence: `src/web.cpp`)
- Device counters and bans → Runtime state: persists bans (evidence: `src/clients.cpp`)
- HTTP dashboard API → Runtime state: stores update config (evidence: `src/web.cpp`)
- HTTP dashboard API → Wi-Fi and portal: clears credentials (evidence: `src/web.cpp`)
