# neonight-d/moonlan architecture

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

- Interactive diagram: https://gitdiagram.com/neonight-d/moonlan
- Repository: https://github.com/neonight-d/moonlan

## Overview

MoonLan is a self-hosted LAN discovery and monitoring service. Switches are polled over SNMP; collected device data feeds topology inference, which produces the map state served by the API and web interface. The product also includes monitoring and stateful alarms, operational controls, diagnostics, and role-protected access. The README documents the major flow and capabilities; sampled source and the SOURCE INDEX support some internal links, while unsampled implementation details are not expanded into speculative call chains.

Main entry points: [`moonlan/snmp_collector.py`](https://github.com/neonight-d/moonlan/blob/main/moonlan/snmp_collector.py) (SNMP collector), [`moonlan/routes/topology.py`](https://github.com/neonight-d/moonlan/blob/main/moonlan/routes/topology.py) (HTTP API routes), [`moonlan/poller.py`](https://github.com/neonight-d/moonlan/blob/main/moonlan/poller.py) (Polling and counters), [`moonlan/server.py`](https://github.com/neonight-d/moonlan/blob/main/moonlan/server.py) (Service and routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_discovery["Discovery and mapping"]
  node_collector["SNMP collector<br/>[snmp_collector.py]"]
  node_snmp_features["SNMP enrichments"]
  node_topology["Topology inference<br/>[topology.py]"]
  node_map_builder["Map construction<br/>[build.py]"]
  node_router_identity["Router identity<br/>[routers.py]"]
  node_demo["Virtual network demo<br/>[demo.py]"]
end

subgraph group_monitoring["Monitoring and alarms"]
  node_monitoring_engine["Polling and counters<br/>[poller.py]"]
  node_counter_rates["Counter rates<br/>[counters.py]"]
  node_alarm_engine["Stateful alarms<br/>[alarms.py]"]
  node_alarm_texts["Alarm text catalogue<br/>[alarm_texts.py]"]
  node_notifications["Notifications<br/>[notify.py]"]
end

subgraph group_service["Service and storage"]
  node_database[("SQLite persistence<br/>[db.py]")]
  node_runtime["Runtime state<br/>[runtime.py]"]
  node_server["Service and routing<br/>[server.py]"]
end

subgraph group_access["Access and operations"]
  node_authentication["Sign-in and sessions<br/>[signin.py]"]
  node_rights["Route permissions<br/>[access.py]"]
  node_settings["Live settings<br/>[settings.py]"]
  node_diagnostics["Network diagnostics<br/>[diag.py]"]
end

subgraph group_interface["API and interface"]
  node_api["HTTP API routes<br/>[topology.py]"]
  node_web["Web interface<br/>[app.js]"]
end

node_switches(("SNMP switches"))
node_operator(("Network operator"))
node_notification_services["Email, Telegram, Syslog"]

node_switches -->|"provide SNMP data"| node_collector
node_collector -->|"supplies readings"| node_topology
node_collector -->|"collects protocols"| node_snmp_features
node_collector -->|"uses router data"| node_router_identity
node_topology -->|"builds map"| node_map_builder
node_demo -->|"provides virtual readings"| node_collector
node_monitoring_engine -.->|"polls devices"| node_collector
node_monitoring_engine -.->|"tracks counters"| node_counter_rates
node_monitoring_engine -.->|"updates alarms"| node_alarm_engine
node_alarm_engine -.->|"formats messages"| node_alarm_texts
node_alarm_engine -.->|"sends alarm events"| node_notifications
node_notifications -->|"delivers notices"| node_notification_services
node_topology -->|"persists state"| node_database
node_server -->|"initializes service state"| node_runtime
node_server -->|"configures persistence"| node_database
node_server -->|"registers routes"| node_api
node_api -->|"reads service state"| node_runtime
node_api -->|"uses request guard"| node_authentication
node_authentication -->|"checks route roles"| node_rights
node_authentication -->|"looks up accounts"| node_database
node_api -->|"serves settings controls"| node_settings
node_operator -->|"uses map interface"| node_web
node_web -->|"requests map data"| node_api
node_operator -->|"runs diagnostics"| node_diagnostics

click node_collector "https://github.com/neonight-d/moonlan/blob/main/moonlan/snmp_collector.py"
click node_snmp_features "https://github.com/neonight-d/moonlan/tree/main/moonlan"
click node_topology "https://github.com/neonight-d/moonlan/blob/main/moonlan/topology.py"
click node_map_builder "https://github.com/neonight-d/moonlan/blob/main/moonlan/mapping/build.py"
click node_router_identity "https://github.com/neonight-d/moonlan/blob/main/moonlan/routers.py"
click node_demo "https://github.com/neonight-d/moonlan/blob/main/moonlan/demo.py"
click node_monitoring_engine "https://github.com/neonight-d/moonlan/blob/main/moonlan/poller.py"
click node_counter_rates "https://github.com/neonight-d/moonlan/blob/main/moonlan/counters.py"
click node_alarm_engine "https://github.com/neonight-d/moonlan/blob/main/moonlan/alarms.py"
click node_alarm_texts "https://github.com/neonight-d/moonlan/blob/main/moonlan/alarm_texts.py"
click node_notifications "https://github.com/neonight-d/moonlan/blob/main/moonlan/notify.py"
click node_database "https://github.com/neonight-d/moonlan/blob/main/moonlan/db.py"
click node_runtime "https://github.com/neonight-d/moonlan/blob/main/moonlan/runtime.py"
click node_server "https://github.com/neonight-d/moonlan/blob/main/moonlan/server.py"
click node_authentication "https://github.com/neonight-d/moonlan/blob/main/moonlan/signin.py"
click node_rights "https://github.com/neonight-d/moonlan/blob/main/moonlan/access.py"
click node_settings "https://github.com/neonight-d/moonlan/blob/main/moonlan/settings.py"
click node_diagnostics "https://github.com/neonight-d/moonlan/blob/main/moonlan/diag.py"
click node_api "https://github.com/neonight-d/moonlan/blob/main/moonlan/routes/topology.py"
click node_web "https://github.com/neonight-d/moonlan/blob/main/web/app.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_collector,node_snmp_features,node_topology,node_map_builder,node_router_identity,node_demo toneBlue
class node_monitoring_engine,node_counter_rates,node_alarm_engine,node_alarm_texts,node_notifications toneAmber
class node_database,node_runtime,node_server toneMint
class node_authentication,node_rights,node_settings,node_diagnostics toneRose
class node_api,node_web,node_switches,node_operator,node_notification_services toneIndigo
```

## Components

### Discovery and mapping

- [SNMP collector](https://github.com/neonight-d/moonlan/blob/main/moonlan/snmp_collector.py): `moonlan/snmp_collector.py`
- [SNMP enrichments](https://github.com/neonight-d/moonlan/tree/main/moonlan): `moonlan`
- [Topology inference](https://github.com/neonight-d/moonlan/blob/main/moonlan/topology.py): `moonlan/topology.py`
- [Map construction](https://github.com/neonight-d/moonlan/blob/main/moonlan/mapping/build.py): `moonlan/mapping/build.py`
- [Router identity](https://github.com/neonight-d/moonlan/blob/main/moonlan/routers.py): `moonlan/routers.py`
- [Virtual network demo](https://github.com/neonight-d/moonlan/blob/main/moonlan/demo.py): `moonlan/demo.py`

### Monitoring and alarms

- [Polling and counters](https://github.com/neonight-d/moonlan/blob/main/moonlan/poller.py): `moonlan/poller.py`
- [Counter rates](https://github.com/neonight-d/moonlan/blob/main/moonlan/counters.py): `moonlan/counters.py`
- [Stateful alarms](https://github.com/neonight-d/moonlan/blob/main/moonlan/alarms.py): `moonlan/alarms.py`
- [Alarm text catalogue](https://github.com/neonight-d/moonlan/blob/main/moonlan/alarm_texts.py): `moonlan/alarm_texts.py`
- [Notifications](https://github.com/neonight-d/moonlan/blob/main/moonlan/notify.py): `moonlan/notify.py`

### Service and storage

- [SQLite persistence](https://github.com/neonight-d/moonlan/blob/main/moonlan/db.py): `moonlan/db.py`
- [Runtime state](https://github.com/neonight-d/moonlan/blob/main/moonlan/runtime.py): `moonlan/runtime.py`
- [Service and routing](https://github.com/neonight-d/moonlan/blob/main/moonlan/server.py): `moonlan/server.py`

### Access and operations

- [Sign-in and sessions](https://github.com/neonight-d/moonlan/blob/main/moonlan/signin.py): `moonlan/signin.py`
- [Route permissions](https://github.com/neonight-d/moonlan/blob/main/moonlan/access.py): `moonlan/access.py`
- [Live settings](https://github.com/neonight-d/moonlan/blob/main/moonlan/settings.py): `moonlan/settings.py`
- [Network diagnostics](https://github.com/neonight-d/moonlan/blob/main/moonlan/diag.py): `moonlan/diag.py`

### API and interface

- [HTTP API routes](https://github.com/neonight-d/moonlan/blob/main/moonlan/routes/topology.py): `moonlan/routes/topology.py`
- [Web interface](https://github.com/neonight-d/moonlan/blob/main/web/app.js): `web/app.js`

### Other components

- **SNMP switches**
- **Network operator**
- **Email, Telegram, Syslog**

## Connections

- SNMP switches → SNMP collector: provide SNMP data
- SNMP collector → Topology inference: supplies readings (evidence: `moonlan/topology.py`)
- SNMP collector → SNMP enrichments: collects protocols (evidence: `moonlan/snmp_collector.py`)
- SNMP collector → Router identity: uses router data (evidence: `moonlan/snmp_collector.py`)
- Topology inference → Map construction: builds map (evidence: `moonlan/mapping/build.py`)
- Virtual network demo → SNMP collector: provides virtual readings (evidence: `moonlan/demo.py`)
- Polling and counters → SNMP collector: polls devices
- Polling and counters → Counter rates: tracks counters
- Polling and counters → Stateful alarms: updates alarms
- Stateful alarms → Alarm text catalogue: formats messages
- Stateful alarms → Notifications: sends alarm events
- Notifications → Email, Telegram, Syslog: delivers notices
- Topology inference → SQLite persistence: persists state
- Service and routing → Runtime state: initializes service state (evidence: `moonlan/runtime.py`)
- Service and routing → SQLite persistence: configures persistence (evidence: `moonlan/server.py`)
- Service and routing → HTTP API routes: registers routes (evidence: `moonlan/server.py`)
- HTTP API routes → Runtime state: reads service state (evidence: `moonlan/routes/topology.py`)
- HTTP API routes → Sign-in and sessions: uses request guard (evidence: `moonlan/routes/topology.py`)
- Sign-in and sessions → Route permissions: checks route roles (evidence: `moonlan/signin.py`)
- Sign-in and sessions → SQLite persistence: looks up accounts (evidence: `moonlan/signin.py`)
- HTTP API routes → Live settings: serves settings controls
- Network operator → Web interface: uses map interface
- Web interface → HTTP API routes: requests map data
- Network operator → Network diagnostics: runs diagnostics
