# userjoo9/netrex architecture

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

- Interactive diagram: https://gitdiagram.com/userjoo9/netrex
- Repository: https://github.com/userjoo9/netrex

## Overview

Netrex is a home-gateway product that meters traffic per person and enforces fair-use quotas across that person’s devices. The main workflow runs from household devices through kernel traffic counting to quota calculation and enforcement, with the dashboard exposing live usage and controls. The repository also documents security, sharing, VPN, remote access, and network-management capabilities. Source excerpts are partial; dashed links mark documented features whose exact runtime wiring was not shown.

Main entry points: [`api/app.py`](https://github.com/userjoo9/netrex/blob/main/api/app.py) (REST and WebSocket API), [`run.py`](https://github.com/userjoo9/netrex/blob/main/run.py) (Gateway runtime), [`quota/vpn_manager.py`](https://github.com/userjoo9/netrex/blob/main/quota/vpn_manager.py) (VPN management), [`quota/service.py`](https://github.com/userjoo9/netrex/blob/main/quota/service.py) (Quota calculations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway Runtime"]
  node_run["Gateway runtime<br/>[run.py]"]
  node_api["REST and WebSocket API<br/>[app.py]"]
  node_db[("SQLite persistence<br/>[db.py]")]
  node_engine["Traffic snapshots<br/>[engine.py]"]
end

subgraph group_quota["Quota and Policy"]
  node_service["Quota calculations<br/>[service.py]"]
  node_nftables["Kernel metering<br/>[nftables.py]"]
  node_daily["Daily plans<br/>[daily_plan.py]"]
end

subgraph group_network["Network Services"]
  node_dns["DNS blocking<br/>[dns_rules.py]"]
  node_firewall["Firewall controls<br/>[firewall.py]"]
  node_shaping["Speed shaping<br/>[shaping.py]"]
  node_network_mgr["Network management<br/>[netmgr.py]"]
end

subgraph group_integrations["Gateway Features"]
  node_disk_share["File sharing<br/>[disk_share.py]"]
  node_local_share["Local sharing<br/>[local_share.py]"]
  node_vpn_manager["VPN management<br/>[vpn_manager.py]"]
  node_vpn_parser["VPN profiles<br/>[vpn_parser.py]"]
  node_vpnshare["VPN routing<br/>[vpnshare.py]"]
  node_tailscale["Remote access<br/>[tailscale.py]"]
end

subgraph group_dashboard["Dashboard"]
  node_main["Dashboard shell<br/>[main.js]"]
  node_pages["Feature pages<br/>[overview.js]"]
  node_client_api["API client<br/>[api.js]"]
  node_ui["UI components<br/>[ui.js]"]
  node_dom["DOM rendering<br/>[dom.js]"]
  node_i18n["Localization<br/>[i18n.js]"]
end

node_household(("Household devices"))
node_browser(("Household admin"))

node_household -->|"sends traffic"| node_nftables
node_nftables -->|"publishes counters"| node_engine
node_engine -.->|"supplies usage"| node_service
node_service -->|"reads and updates"| node_db
node_service -.->|"sets enforcement"| node_nftables
node_daily -->|"supports plans"| node_service
node_run -->|"wires application"| node_api
node_run -->|"starts engine"| node_nftables
node_run -->|"configures firewall"| node_firewall
node_api -->|"uses persistence"| node_db
node_api -->|"pushes live snapshots"| node_engine
node_api -->|"serves share routes"| node_local_share
node_run -->|"wires DNS rules"| node_dns
node_browser -->|"opens dashboard"| node_main
node_main -->|"loads feature pages"| node_pages
node_pages -.->|"requests data"| node_client_api
node_client_api -->|"sends HTTP requests"| node_api
node_main -->|"renders shell"| node_ui
node_ui -->|"builds elements"| node_dom
node_ui -->|"formats labels"| node_i18n
node_disk_share -.->|"supports sharing"| node_local_share
node_vpn_manager -->|"reads VPN settings"| node_db
node_vpn_manager -->|"loads profiles"| node_vpn_parser
node_vpn_manager -->|"reconciles routing"| node_vpnshare
node_browser -.->|"configures blocking"| node_dns
node_browser -.->|"sets speed limits"| node_shaping
node_browser -.->|"manages remote access"| node_tailscale
node_browser -.->|"manages VPN"| node_vpn_manager

click node_run "https://github.com/userjoo9/netrex/blob/main/run.py"
click node_api "https://github.com/userjoo9/netrex/blob/main/api/app.py"
click node_db "https://github.com/userjoo9/netrex/blob/main/quota/db.py"
click node_engine "https://github.com/userjoo9/netrex/blob/main/quota/engine.py"
click node_service "https://github.com/userjoo9/netrex/blob/main/quota/service.py"
click node_nftables "https://github.com/userjoo9/netrex/blob/main/quota/nftables.py"
click node_daily "https://github.com/userjoo9/netrex/blob/main/quota/daily_plan.py"
click node_dns "https://github.com/userjoo9/netrex/blob/main/quota/dns_rules.py"
click node_firewall "https://github.com/userjoo9/netrex/blob/main/quota/firewall.py"
click node_shaping "https://github.com/userjoo9/netrex/blob/main/quota/shaping.py"
click node_network_mgr "https://github.com/userjoo9/netrex/blob/main/quota/netmgr.py"
click node_disk_share "https://github.com/userjoo9/netrex/blob/main/quota/disk_share.py"
click node_local_share "https://github.com/userjoo9/netrex/blob/main/quota/local_share.py"
click node_vpn_manager "https://github.com/userjoo9/netrex/blob/main/quota/vpn_manager.py"
click node_vpn_parser "https://github.com/userjoo9/netrex/blob/main/quota/vpn_parser.py"
click node_vpnshare "https://github.com/userjoo9/netrex/blob/main/quota/vpnshare.py"
click node_tailscale "https://github.com/userjoo9/netrex/blob/main/quota/tailscale.py"
click node_main "https://github.com/userjoo9/netrex/blob/main/web/js/main.js"
click node_pages "https://github.com/userjoo9/netrex/blob/main/web/js/pages/overview.js"
click node_client_api "https://github.com/userjoo9/netrex/blob/main/web/js/core/api.js"
click node_ui "https://github.com/userjoo9/netrex/blob/main/web/js/components/ui.js"
click node_dom "https://github.com/userjoo9/netrex/blob/main/web/js/core/dom.js"
click node_i18n "https://github.com/userjoo9/netrex/blob/main/web/js/core/i18n.js"

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_run,node_api,node_db,node_engine toneBlue
class node_service,node_nftables,node_daily toneAmber
class node_dns,node_firewall,node_shaping,node_network_mgr toneMint
class node_disk_share,node_local_share,node_vpn_manager,node_vpn_parser,node_vpnshare,node_tailscale toneRose
class node_main,node_pages,node_client_api,node_ui,node_dom,node_i18n,node_household,node_browser toneIndigo
```

## Components

### Gateway Runtime

- [Gateway runtime](https://github.com/userjoo9/netrex/blob/main/run.py): `run.py`
- [REST and WebSocket API](https://github.com/userjoo9/netrex/blob/main/api/app.py): `api/app.py`
- [SQLite persistence](https://github.com/userjoo9/netrex/blob/main/quota/db.py): `quota/db.py`
- [Traffic snapshots](https://github.com/userjoo9/netrex/blob/main/quota/engine.py): `quota/engine.py`

### Quota and Policy

- [Quota calculations](https://github.com/userjoo9/netrex/blob/main/quota/service.py): `quota/service.py`
- [Kernel metering](https://github.com/userjoo9/netrex/blob/main/quota/nftables.py): `quota/nftables.py`
- [Daily plans](https://github.com/userjoo9/netrex/blob/main/quota/daily_plan.py): `quota/daily_plan.py`

### Network Services

- [DNS blocking](https://github.com/userjoo9/netrex/blob/main/quota/dns_rules.py): `quota/dns_rules.py`
- [Firewall controls](https://github.com/userjoo9/netrex/blob/main/quota/firewall.py): `quota/firewall.py`
- [Speed shaping](https://github.com/userjoo9/netrex/blob/main/quota/shaping.py): `quota/shaping.py`
- [Network management](https://github.com/userjoo9/netrex/blob/main/quota/netmgr.py): `quota/netmgr.py`

### Gateway Features

- [File sharing](https://github.com/userjoo9/netrex/blob/main/quota/disk_share.py): `quota/disk_share.py`
- [Local sharing](https://github.com/userjoo9/netrex/blob/main/quota/local_share.py): `quota/local_share.py`
- [VPN management](https://github.com/userjoo9/netrex/blob/main/quota/vpn_manager.py): `quota/vpn_manager.py`
- [VPN profiles](https://github.com/userjoo9/netrex/blob/main/quota/vpn_parser.py): `quota/vpn_parser.py`
- [VPN routing](https://github.com/userjoo9/netrex/blob/main/quota/vpnshare.py): `quota/vpnshare.py`
- [Remote access](https://github.com/userjoo9/netrex/blob/main/quota/tailscale.py): `quota/tailscale.py`

### Dashboard

- [Dashboard shell](https://github.com/userjoo9/netrex/blob/main/web/js/main.js): `web/js/main.js`
- [Feature pages](https://github.com/userjoo9/netrex/blob/main/web/js/pages/overview.js): `web/js/pages/overview.js`
- [API client](https://github.com/userjoo9/netrex/blob/main/web/js/core/api.js): `web/js/core/api.js`
- [UI components](https://github.com/userjoo9/netrex/blob/main/web/js/components/ui.js): `web/js/components/ui.js`
- [DOM rendering](https://github.com/userjoo9/netrex/blob/main/web/js/core/dom.js): `web/js/core/dom.js`
- [Localization](https://github.com/userjoo9/netrex/blob/main/web/js/core/i18n.js): `web/js/core/i18n.js`

### Other components

- **Household devices**
- **Household admin**

## Connections

- Household devices → Kernel metering: sends traffic (evidence: `README.md`)
- Kernel metering → Traffic snapshots: publishes counters (evidence: `quota/engine.py`)
- Traffic snapshots → Quota calculations: supplies usage
- Quota calculations → SQLite persistence: reads and updates (evidence: `quota/service.py`)
- Quota calculations → Kernel metering: sets enforcement
- Daily plans → Quota calculations: supports plans (evidence: `quota/service.py`)
- Gateway runtime → REST and WebSocket API: wires application (evidence: `run.py`)
- Gateway runtime → Kernel metering: starts engine (evidence: `run.py`)
- Gateway runtime → Firewall controls: configures firewall (evidence: `run.py`)
- REST and WebSocket API → SQLite persistence: uses persistence (evidence: `api/app.py`)
- REST and WebSocket API → Traffic snapshots: pushes live snapshots (evidence: `api/app.py`)
- REST and WebSocket API → Local sharing: serves share routes (evidence: `api/app.py`)
- Gateway runtime → DNS blocking: wires DNS rules (evidence: `run.py`)
- Household admin → Dashboard shell: opens dashboard (evidence: `README.md`)
- Dashboard shell → Feature pages: loads feature pages (evidence: `web/js/main.js`)
- Feature pages → API client: requests data
- API client → REST and WebSocket API: sends HTTP requests (evidence: `web/js/core/api.js`)
- Dashboard shell → UI components: renders shell (evidence: `web/js/main.js`)
- UI components → DOM rendering: builds elements (evidence: `web/js/components/ui.js`)
- UI components → Localization: formats labels (evidence: `web/js/components/ui.js`)
- File sharing → Local sharing: supports sharing
- VPN management → SQLite persistence: reads VPN settings (evidence: `quota/vpn_manager.py`)
- VPN management → VPN profiles: loads profiles (evidence: `quota/vpn_manager.py`)
- VPN management → VPN routing: reconciles routing (evidence: `quota/vpn_manager.py`)
- Household admin → DNS blocking: configures blocking
- Household admin → Speed shaping: sets speed limits
- Household admin → Remote access: manages remote access
- Household admin → VPN management: manages VPN
