# ugzv/ublockdnsclient architecture

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

- Interactive diagram: https://gitdiagram.com/ugzv/ublockdnsclient
- Repository: https://github.com/ugzv/ublockdnsclient

## Overview

uBlockDNS Client installs and manages a local system service that redirects device DNS through a filtering proxy, while dashboard policy remains remote. The main workflow is CLI command → service setup → local proxy and system DNS activation; at runtime the proxy uses encrypted upstream DNS, with endpoint recovery and optional rule-update handling. Status and readiness checks verify service and DNS health. Relationships are based on the README and shown excerpts or SOURCE INDEX references; unsampled implementation details are not expanded.

Main entry points: [`cli.go`](https://github.com/ugzv/ublockdnsclient/blob/main/cli.go) (CLI commands), [`internal/runtime/runtime_run.go`](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/runtime_run.go) (Runtime startup), [`internal/service/install.go`](https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/install.go) (Install service), [`internal/runtime/rules_watcher.go`](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/rules_watcher.go) (Rule update stream)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli_service["CLI and service lifecycle"]
  node_cli["CLI commands<br/>[cli.go]"]
  node_install["Install service<br/>[install.go]"]
  node_service_control["Service control<br/>[control.go]"]
  node_status["Status and readiness<br/>[status.go]"]
end

subgraph group_runtime["DNS runtime"]
  node_runtime_run["Runtime startup<br/>[runtime_run.go]"]
  node_proxy["Local DNS proxy<br/>[proxy_runner.go]"]
  node_bootstrap["DoH bootstrap<br/>[dns_bootstrap.go]"]
  node_endpoint_recovery["Endpoint fallback"]
  node_network_watch["Network monitoring<br/>[network_watch.go]"]
  node_resolver_retry["Resolver retries<br/>[resolver_retry.go]"]
  node_rules_updates["Rule update stream<br/>[rules_watcher.go]"]
end

subgraph group_platform_dns["Platform DNS"]
  node_dns_platform["System DNS settings<br/>[dns_activate.go]"]
  node_dns_probe["DNS probes<br/>[dns_probe.go]"]
  node_cache_flush["OS cache flush<br/>[dns_cache_flush.go]"]
end

subgraph group_state_updates["State and updates"]
  node_install_state[("Install state")]
  node_token_store[("Token storage<br/>[token_store.go]")]
  node_auto_update["Automatic updates<br/>[auto_update.go]"]
end

node_user(("Operator"))
node_doh_service{{"uBlockDNS DoH service"}}
node_dashboard(("Dashboard"))
node_release_updates{{"Signed releases"}}

node_user -->|"runs commands"| node_cli
node_cli -->|"installs service"| node_install
node_cli -->|"manages service"| node_service_control
node_cli -->|"checks readiness"| node_status
node_install -->|"activates DNS"| node_dns_platform
node_install -->|"persists config"| node_install_state
node_service_control -->|"restores DNS"| node_dns_platform
node_status -->|"probes local DNS"| node_dns_probe
node_status -->|"loads config"| node_install_state
node_runtime_run -->|"resolves upstream"| node_bootstrap
node_runtime_run -->|"starts proxy"| node_proxy
node_runtime_run -->|"configures endpoints"| node_endpoint_recovery
node_runtime_run -->|"starts watcher"| node_rules_updates
node_proxy -->|"forwards encrypted DNS"| node_doh_service
node_endpoint_recovery -->|"tests DoH endpoints"| node_doh_service
node_endpoint_recovery -->|"discovers fallback DNS"| node_dns_platform
node_rules_updates -->|"receives rule changes"| node_dashboard
node_rules_updates -->|"flushes OS caches"| node_cache_flush
node_rules_updates -->|"purges DNS cache"| node_proxy
node_auto_update -->|"checks signed releases"| node_release_updates
node_cli -->|"runs daemon"| node_runtime_run
node_install -.->|"stores credentials"| node_token_store
node_network_watch -.->|"triggers recovery"| node_endpoint_recovery
node_resolver_retry -.->|"retries resolution"| node_proxy

click node_cli "https://github.com/ugzv/ublockdnsclient/blob/main/cli.go"
click node_install "https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/install.go"
click node_service_control "https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/control.go"
click node_status "https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/status.go"
click node_runtime_run "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/runtime_run.go"
click node_proxy "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/proxy_runner.go"
click node_bootstrap "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/dns_bootstrap.go"
click node_endpoint_recovery "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/endpoint_fallback.go"
click node_network_watch "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/network_watch.go"
click node_resolver_retry "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/resolver_retry.go"
click node_rules_updates "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/rules_watcher.go"
click node_dns_platform "https://github.com/ugzv/ublockdnsclient/blob/main/internal/core/dns_activate.go"
click node_dns_probe "https://github.com/ugzv/ublockdnsclient/blob/main/internal/core/dns_probe.go"
click node_cache_flush "https://github.com/ugzv/ublockdnsclient/blob/main/internal/core/dns_cache_flush.go"
click node_install_state "https://github.com/ugzv/ublockdnsclient/blob/main/internal/state/install_state_store.go"
click node_token_store "https://github.com/ugzv/ublockdnsclient/blob/main/internal/state/token_store.go"
click node_auto_update "https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/auto_update.go"

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_cli,node_install,node_service_control,node_status toneBlue
class node_runtime_run,node_proxy,node_bootstrap,node_endpoint_recovery,node_network_watch,node_resolver_retry,node_rules_updates toneAmber
class node_dns_platform,node_dns_probe,node_cache_flush toneMint
class node_install_state,node_token_store,node_auto_update toneRose
class node_user,node_doh_service,node_dashboard,node_release_updates toneIndigo
```

## Components

### CLI and service lifecycle

- [CLI commands](https://github.com/ugzv/ublockdnsclient/blob/main/cli.go): `cli.go`
- [Install service](https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/install.go): `internal/service/install.go`
- [Service control](https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/control.go): `internal/service/control.go`
- [Status and readiness](https://github.com/ugzv/ublockdnsclient/blob/main/internal/service/status.go): `internal/service/status.go`

### DNS runtime

- [Runtime startup](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/runtime_run.go): `internal/runtime/runtime_run.go`
- [Local DNS proxy](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/proxy_runner.go): `internal/runtime/proxy_runner.go`
- [DoH bootstrap](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/dns_bootstrap.go): `internal/runtime/dns_bootstrap.go`
- [Endpoint fallback](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/endpoint_fallback.go): `internal/runtime/endpoint_fallback.go`
- [Network monitoring](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/network_watch.go): `internal/runtime/network_watch.go`
- [Resolver retries](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/resolver_retry.go): `internal/runtime/resolver_retry.go`
- [Rule update stream](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/rules_watcher.go): `internal/runtime/rules_watcher.go`

### Platform DNS

- [System DNS settings](https://github.com/ugzv/ublockdnsclient/blob/main/internal/core/dns_activate.go): `internal/core/dns_activate.go`
- [DNS probes](https://github.com/ugzv/ublockdnsclient/blob/main/internal/core/dns_probe.go): `internal/core/dns_probe.go`
- [OS cache flush](https://github.com/ugzv/ublockdnsclient/blob/main/internal/core/dns_cache_flush.go): `internal/core/dns_cache_flush.go`

### State and updates

- [Install state](https://github.com/ugzv/ublockdnsclient/blob/main/internal/state/install_state_store.go): `internal/state/install_state_store.go`
- [Token storage](https://github.com/ugzv/ublockdnsclient/blob/main/internal/state/token_store.go): `internal/state/token_store.go`
- [Automatic updates](https://github.com/ugzv/ublockdnsclient/blob/main/internal/runtime/auto_update.go): `internal/runtime/auto_update.go`

### Other components

- **Operator**
- **uBlockDNS DoH service**
- **Dashboard**
- **Signed releases**

## Connections

- Operator → CLI commands: runs commands
- CLI commands → Install service: installs service
- CLI commands → Service control: manages service (evidence: `cli.go`)
- CLI commands → Status and readiness: checks readiness (evidence: `cli.go`)
- Install service → System DNS settings: activates DNS (evidence: `internal/service/install.go`)
- Install service → Install state: persists config (evidence: `internal/service/install.go`)
- Service control → System DNS settings: restores DNS (evidence: `internal/service/control.go`)
- Status and readiness → DNS probes: probes local DNS (evidence: `internal/service/status.go`)
- Status and readiness → Install state: loads config (evidence: `internal/service/status.go`)
- Runtime startup → DoH bootstrap: resolves upstream (evidence: `internal/runtime/runtime_run.go`)
- Runtime startup → Local DNS proxy: starts proxy (evidence: `internal/runtime/runtime_run.go`)
- Runtime startup → Endpoint fallback: configures endpoints (evidence: `internal/runtime/runtime_run.go`)
- Runtime startup → Rule update stream: starts watcher (evidence: `internal/runtime/runtime_run.go`)
- Local DNS proxy → uBlockDNS DoH service: forwards encrypted DNS
- Endpoint fallback → uBlockDNS DoH service: tests DoH endpoints (evidence: `internal/runtime/endpoint_fallback.go`)
- Endpoint fallback → System DNS settings: discovers fallback DNS (evidence: `internal/runtime/endpoint_fallback.go`)
- Rule update stream → Dashboard: receives rule changes
- Rule update stream → OS cache flush: flushes OS caches (evidence: `internal/runtime/rules_watcher.go`)
- Rule update stream → Local DNS proxy: purges DNS cache
- Automatic updates → Signed releases: checks signed releases
- CLI commands → Runtime startup: runs daemon
- Install service → Token storage: stores credentials
- Network monitoring → Endpoint fallback: triggers recovery
- Resolver retries → Local DNS proxy: retries resolution
