# harik0/dns-ad-block architecture

> Architecture diagram of the GitHub repository harik0/dns-ad-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/harik0/dns-ad-block
- Repository: https://github.com/harik0/dns-ad-block

## Overview

This is an AI-assisted DNS analytics dashboard: Pi-hole remains responsible for allow/block decisions, while the backend imports or accepts DNS events, enriches them with auditable explanations and advisory false-positive risk, and stores them for review. The frontend presents query counts, decision/category charts, and a log table; the README also documents WebSocket updates. The main page excerpt shows five-second polling rather than a WebSocket client, so the live WebSocket relationship is documented but its frontend implementation is not visible in the sampled code.

Main entry points: [`backend/app/main.py`](https://github.com/harik0/dns-ad-block/blob/main/backend/app/main.py) (Sync and ingestion), [`backend/app/models.py`](https://github.com/harik0/dns-ad-block/blob/main/backend/app/models.py) (DNS log model), [`backend/app/db.py`](https://github.com/harik0/dns-ad-block/blob/main/backend/app/db.py) (SQLite database), [`backend/app/pihole_client.py`](https://github.com/harik0/dns-ad-block/blob/main/backend/app/pihole_client.py) (Pi-hole client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Event ingestion"]
  node_client["Pi-hole client<br/>[pihole_client.py]"]
end

subgraph group_analysis["Explanation and storage"]
  node_analyzer["Event explanation<br/>[ml_engine.py]"]
  node_model["DNS log model<br/>[models.py]"]
  node_database[("SQLite database<br/>[db.py]")]
end

subgraph group_api["Backend API"]
  node_sync["Sync and ingestion<br/>[main.py]"]
  node_schemas["Event schemas<br/>[schemas.py]"]
  node_api_main["HTTP and WebSocket API<br/>[main.py]"]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard["Dashboard view<br/>[page.tsx]"]
  node_metric["Metric component"]
  node_logs["Logs table component<br/>[logs-table.tsx]"]
  node_badge["Status badge<br/>[status-badge.tsx]"]
  node_chart["Threat chart<br/>[threat-chart.tsx]"]
end

node_pihole(("Pi-hole"))
node_adapter(("Event adapter"))
node_browser(("Dashboard user"))

node_client -->|"fetches queries"| node_pihole
node_sync -->|"fetches queries"| node_client
node_adapter -->|"submits events"| node_api_main
node_sync -->|"validates events"| node_schemas
node_sync -->|"builds explanations"| node_analyzer
node_sync -->|"creates log records"| node_model
node_sync -->|"commits records"| node_database
node_api_main -->|"queries logs"| node_model
node_api_main -->|"opens sessions"| node_database
node_database -->|"creates tables"| node_model
node_model -->|"uses ORM base"| node_database
node_dashboard -->|"polls logs"| node_api_main
node_api_main -->|"streams updates"| node_browser
node_browser -.->|"views analytics"| node_dashboard

click node_client "https://github.com/harik0/dns-ad-block/blob/main/backend/app/pihole_client.py"
click node_sync "https://github.com/harik0/dns-ad-block/blob/main/backend/app/main.py"
click node_schemas "https://github.com/harik0/dns-ad-block/blob/main/backend/app/schemas.py"
click node_analyzer "https://github.com/harik0/dns-ad-block/blob/main/backend/app/ml_engine.py"
click node_model "https://github.com/harik0/dns-ad-block/blob/main/backend/app/models.py"
click node_database "https://github.com/harik0/dns-ad-block/blob/main/backend/app/db.py"
click node_api_main "https://github.com/harik0/dns-ad-block/blob/main/backend/app/main.py"
click node_dashboard "https://github.com/harik0/dns-ad-block/blob/main/frontend/app/page.tsx"
click node_metric "https://github.com/harik0/dns-ad-block/blob/main/frontend/components/dashboard-metric.tsx"
click node_logs "https://github.com/harik0/dns-ad-block/blob/main/frontend/components/logs-table.tsx"
click node_badge "https://github.com/harik0/dns-ad-block/blob/main/frontend/components/status-badge.tsx"
click node_chart "https://github.com/harik0/dns-ad-block/blob/main/frontend/components/threat-chart.tsx"

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_client,node_browser toneBlue
class node_analyzer,node_model,node_database toneAmber
class node_sync,node_schemas,node_api_main toneMint
class node_dashboard,node_metric,node_logs,node_badge,node_chart toneRose
class node_pihole,node_adapter toneIndigo
```

## Components

### Event ingestion

- [Pi-hole client](https://github.com/harik0/dns-ad-block/blob/main/backend/app/pihole_client.py): `backend/app/pihole_client.py`

### Explanation and storage

- [Event explanation](https://github.com/harik0/dns-ad-block/blob/main/backend/app/ml_engine.py): `backend/app/ml_engine.py`
- [DNS log model](https://github.com/harik0/dns-ad-block/blob/main/backend/app/models.py): `backend/app/models.py`
- [SQLite database](https://github.com/harik0/dns-ad-block/blob/main/backend/app/db.py): `backend/app/db.py`

### Backend API

- [Sync and ingestion](https://github.com/harik0/dns-ad-block/blob/main/backend/app/main.py): `backend/app/main.py`
- [Event schemas](https://github.com/harik0/dns-ad-block/blob/main/backend/app/schemas.py): `backend/app/schemas.py`
- [HTTP and WebSocket API](https://github.com/harik0/dns-ad-block/blob/main/backend/app/main.py): `backend/app/main.py`

### Dashboard

- [Dashboard view](https://github.com/harik0/dns-ad-block/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Metric component](https://github.com/harik0/dns-ad-block/blob/main/frontend/components/dashboard-metric.tsx): `frontend/components/dashboard-metric.tsx`
- [Logs table component](https://github.com/harik0/dns-ad-block/blob/main/frontend/components/logs-table.tsx): `frontend/components/logs-table.tsx`
- [Status badge](https://github.com/harik0/dns-ad-block/blob/main/frontend/components/status-badge.tsx): `frontend/components/status-badge.tsx`
- [Threat chart](https://github.com/harik0/dns-ad-block/blob/main/frontend/components/threat-chart.tsx): `frontend/components/threat-chart.tsx`

### Other components

- **Pi-hole**
- **Event adapter**
- **Dashboard user**

## Connections

- Pi-hole client → Pi-hole: fetches queries (evidence: `backend/app/pihole_client.py`)
- Sync and ingestion → Pi-hole client: fetches queries (evidence: `backend/app/main.py`)
- Event adapter → HTTP and WebSocket API: submits events (evidence: `README.md`)
- Sync and ingestion → Event schemas: validates events (evidence: `backend/app/main.py`)
- Sync and ingestion → Event explanation: builds explanations (evidence: `backend/app/main.py`)
- Sync and ingestion → DNS log model: creates log records (evidence: `backend/app/main.py`)
- Sync and ingestion → SQLite database: commits records (evidence: `backend/app/main.py`)
- HTTP and WebSocket API → DNS log model: queries logs (evidence: `backend/app/main.py`)
- HTTP and WebSocket API → SQLite database: opens sessions (evidence: `backend/app/main.py`)
- SQLite database → DNS log model: creates tables (evidence: `backend/app/db.py`)
- DNS log model → SQLite database: uses ORM base (evidence: `backend/app/models.py`)
- Dashboard view → HTTP and WebSocket API: polls logs (evidence: `frontend/app/page.tsx`)
- HTTP and WebSocket API → Dashboard user: streams updates (evidence: `README.md`)
- Dashboard user → Dashboard view: views analytics
