# nethserver/nethsecurity architecture

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

- Interactive diagram: https://gitdiagram.com/nethserver/nethsecurity
- Repository: https://github.com/nethserver/nethsecurity

## Overview

NethSecurity is an OpenWrt-derived Linux firewall managed through configuration and system services. The tree shows a Go API server alongside Python libraries and package scripts that manage firewall, network, users, DPI, and related services. The management workflow is configuration-oriented: administrators make changes through management surfaces, and components update system configuration or invoke services. Source excerpts support several library dependencies, but the Go API’s internal routing and many unsampled integrations cannot be verified here; those links are omitted.

Main entry points: [`packages/ns-api-server/files/src/main.go`](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/main.go) (API server), [`packages/python3-nethsec/src/nethsec/utils/__init__.py`](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/utils/__init__.py) (System utilities), [`packages/python3-nethsec/src/nethsec/objects/__init__.py`](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/objects/__init__.py) (Network objects), [`packages/python3-nethsec/src/nethsec/inventory/__init__.py`](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/inventory/__init__.py) (System inventory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_management["Management API"]
  node_api["API server<br/>[main.go]"]
  node_api_auth["Authentication<br/>[auth.go]"]
  node_api_middleware["Request middleware<br/>[middleware.go]"]
  node_api_files["File methods<br/>[files.go]"]
  node_api_proxy["Proxy methods<br/>[proxy.go]"]
  node_api_ubus["Ubus methods<br/>[ubus.go]"]
  node_api_config["API configuration<br/>[configuration.go]"]
end

subgraph group_network["Network Controls"]
  node_firewall["Firewall rules<br/>[__init__.py]"]
  node_objects["Network objects<br/>[__init__.py]"]
  node_multiwan["Multi-WAN<br/>[__init__.py]"]
  node_binding["Device binding<br/>[ns-binding.py]"]
  node_conntrack["Connection tracking<br/>[__init__.py]"]
  node_mwan_sockopt["MWAN socket options<br/>[sockopt_wrap.c]"]
end

subgraph group_security["Security Services"]
  node_dpi["DPI policies<br/>[__init__.py]"]
  node_dpi_updates["DPI updates<br/>[dpi-update.py]"]
  node_threat_shield["Threat shield"]
  node_snort["Snort<br/>[__init__.py]"]
  node_ipsec["IPsec<br/>[__init__.py]"]
  node_openvpn["OpenVPN<br/>[__init__.py]"]
  node_reverse_proxy["Reverse proxy<br/>[__init__.py]"]
  node_netify_config["Netify configuration"]
end

subgraph group_foundation["Python Services"]
  node_users["Users and access<br/>[__init__.py]"]
  node_ldif["LDAP records<br/>[__init__.py]"]
  node_inventory["System inventory<br/>[__init__.py]"]
  node_utils["System utilities<br/>[__init__.py]"]
end

node_admin(("Administrator"))

node_admin -.->|"manages firewall"| node_api
node_api -.->|"authenticates"| node_api_auth
node_api -.->|"filters requests"| node_api_middleware
node_api -.->|"dispatches files"| node_api_files
node_api -.->|"dispatches proxy"| node_api_proxy
node_api -.->|"dispatches ubus"| node_api_ubus
node_api -.->|"loads configuration"| node_api_config
node_firewall -->|"uses"| node_utils
node_firewall -->|"uses"| node_objects
node_objects -->|"uses"| node_utils
node_multiwan -->|"uses"| node_utils
node_multiwan -->|"uses"| node_objects
node_binding -->|"reads configuration"| node_utils
node_dpi -->|"uses"| node_utils
node_dpi -->|"uses"| node_objects
node_threat_shield -->|"uses"| node_utils
node_users -->|"uses"| node_utils
node_users -->|"uses"| node_ldif
node_inventory -->|"uses"| node_utils
node_inventory -->|"reads rules"| node_firewall
node_inventory -->|"reads objects"| node_objects
node_inventory -->|"reads configuration"| node_multiwan

click node_api "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/main.go"
click node_api_auth "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/auth.go"
click node_api_middleware "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/middleware/middleware.go"
click node_api_files "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/files.go"
click node_api_proxy "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/proxy.go"
click node_api_ubus "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/ubus.go"
click node_api_config "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/configuration/configuration.go"
click node_firewall "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/firewall/__init__.py"
click node_objects "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/objects/__init__.py"
click node_multiwan "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/mwan/__init__.py"
click node_binding "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-binding/files/ns-binding.py"
click node_conntrack "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/conntrack/__init__.py"
click node_dpi "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/dpi/__init__.py"
click node_dpi_updates "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-dpi/files/dpi-update.py"
click node_threat_shield "https://github.com/nethserver/nethsecurity/blob/main/packages/ns-threat_shield/files/configure-adblock-devices.py"
click node_snort "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/snort/__init__.py"
click node_ipsec "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/ipsec/__init__.py"
click node_openvpn "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/ovpn/__init__.py"
click node_reverse_proxy "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/reverse_proxy/__init__.py"
click node_users "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/users/__init__.py"
click node_ldif "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/ldif/__init__.py"
click node_inventory "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/inventory/__init__.py"
click node_utils "https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/utils/__init__.py"
click node_mwan_sockopt "https://github.com/nethserver/nethsecurity/blob/main/packages/mwan3/src/sockopt_wrap.c"
click node_netify_config "https://github.com/nethserver/nethsecurity/blob/main/packages/netifyd/files/usr/sbin/ns-netifyd-configure.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_api,node_api_auth,node_api_middleware,node_api_files,node_api_proxy,node_api_ubus,node_api_config toneBlue
class node_firewall,node_objects,node_multiwan,node_binding,node_conntrack,node_mwan_sockopt toneAmber
class node_dpi,node_dpi_updates,node_threat_shield,node_snort,node_ipsec,node_openvpn,node_reverse_proxy,node_netify_config toneMint
class node_users,node_ldif,node_inventory,node_utils toneRose
class node_admin toneIndigo
```

## Components

### Management API

- [API server](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/main.go): `packages/ns-api-server/files/src/main.go`
- [Authentication](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/auth.go): `packages/ns-api-server/files/src/methods/auth.go`
- [Request middleware](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/middleware/middleware.go): `packages/ns-api-server/files/src/middleware/middleware.go`
- [File methods](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/files.go): `packages/ns-api-server/files/src/methods/files.go`
- [Proxy methods](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/proxy.go): `packages/ns-api-server/files/src/methods/proxy.go`
- [Ubus methods](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/methods/ubus.go): `packages/ns-api-server/files/src/methods/ubus.go`
- [API configuration](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-api-server/files/src/configuration/configuration.go): `packages/ns-api-server/files/src/configuration/configuration.go`

### Network Controls

- [Firewall rules](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/firewall/__init__.py): `packages/python3-nethsec/src/nethsec/firewall/__init__.py`
- [Network objects](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/objects/__init__.py): `packages/python3-nethsec/src/nethsec/objects/__init__.py`
- [Multi-WAN](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/mwan/__init__.py): `packages/python3-nethsec/src/nethsec/mwan/__init__.py`
- [Device binding](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-binding/files/ns-binding.py): `packages/ns-binding/files/ns-binding.py`
- [Connection tracking](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/conntrack/__init__.py): `packages/python3-nethsec/src/nethsec/conntrack/__init__.py`
- [MWAN socket options](https://github.com/nethserver/nethsecurity/blob/main/packages/mwan3/src/sockopt_wrap.c): `packages/mwan3/src/sockopt_wrap.c`

### Security Services

- [DPI policies](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/dpi/__init__.py): `packages/python3-nethsec/src/nethsec/dpi/__init__.py`
- [DPI updates](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-dpi/files/dpi-update.py): `packages/ns-dpi/files/dpi-update.py`
- [Threat shield](https://github.com/nethserver/nethsecurity/blob/main/packages/ns-threat_shield/files/configure-adblock-devices.py): `packages/ns-threat_shield/files/configure-adblock-devices.py`
- [Snort](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/snort/__init__.py): `packages/python3-nethsec/src/nethsec/snort/__init__.py`
- [IPsec](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/ipsec/__init__.py): `packages/python3-nethsec/src/nethsec/ipsec/__init__.py`
- [OpenVPN](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/ovpn/__init__.py): `packages/python3-nethsec/src/nethsec/ovpn/__init__.py`
- [Reverse proxy](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/reverse_proxy/__init__.py): `packages/python3-nethsec/src/nethsec/reverse_proxy/__init__.py`
- [Netify configuration](https://github.com/nethserver/nethsecurity/blob/main/packages/netifyd/files/usr/sbin/ns-netifyd-configure.py): `packages/netifyd/files/usr/sbin/ns-netifyd-configure.py`

### Python Services

- [Users and access](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/users/__init__.py): `packages/python3-nethsec/src/nethsec/users/__init__.py`
- [LDAP records](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/ldif/__init__.py): `packages/python3-nethsec/src/nethsec/ldif/__init__.py`
- [System inventory](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/inventory/__init__.py): `packages/python3-nethsec/src/nethsec/inventory/__init__.py`
- [System utilities](https://github.com/nethserver/nethsecurity/blob/main/packages/python3-nethsec/src/nethsec/utils/__init__.py): `packages/python3-nethsec/src/nethsec/utils/__init__.py`

### Other components

- **Administrator**

## Connections

- Administrator → API server: manages firewall
- API server → Authentication: authenticates
- API server → Request middleware: filters requests
- API server → File methods: dispatches files
- API server → Proxy methods: dispatches proxy
- API server → Ubus methods: dispatches ubus
- API server → API configuration: loads configuration
- Firewall rules → System utilities: uses (evidence: `packages/python3-nethsec/src/nethsec/firewall/__init__.py`)
- Firewall rules → Network objects: uses (evidence: `packages/python3-nethsec/src/nethsec/firewall/__init__.py`)
- Network objects → System utilities: uses (evidence: `packages/python3-nethsec/src/nethsec/objects/__init__.py`)
- Multi-WAN → System utilities: uses (evidence: `packages/python3-nethsec/src/nethsec/mwan/__init__.py`)
- Multi-WAN → Network objects: uses (evidence: `packages/python3-nethsec/src/nethsec/mwan/__init__.py`)
- Device binding → System utilities: reads configuration (evidence: `packages/ns-binding/files/ns-binding.py`)
- DPI policies → System utilities: uses (evidence: `packages/python3-nethsec/src/nethsec/dpi/__init__.py`)
- DPI policies → Network objects: uses (evidence: `packages/python3-nethsec/src/nethsec/dpi/__init__.py`)
- Threat shield → System utilities: uses (evidence: `packages/ns-threat_shield/files/configure-adblock-devices.py`)
- Users and access → System utilities: uses (evidence: `packages/python3-nethsec/src/nethsec/users/__init__.py`)
- Users and access → LDAP records: uses (evidence: `packages/python3-nethsec/src/nethsec/users/__init__.py`)
- System inventory → System utilities: uses (evidence: `packages/python3-nethsec/src/nethsec/inventory/__init__.py`)
- System inventory → Firewall rules: reads rules (evidence: `packages/python3-nethsec/src/nethsec/inventory/__init__.py`)
- System inventory → Network objects: reads objects (evidence: `packages/python3-nethsec/src/nethsec/inventory/__init__.py`)
- System inventory → Multi-WAN: reads configuration (evidence: `packages/python3-nethsec/src/nethsec/inventory/__init__.py`)
