# sufferer-of-his-sins/netwatch architecture

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

- Interactive diagram: https://gitdiagram.com/sufferer-of-his-sins/netwatch
- Repository: https://github.com/sufferer-of-his-sins/netwatch

## Overview

NetWatch is a C client-server network-device monitoring system. Agents register and send metrics and heartbeats; the server handles device communication, queries and commands, and is documented to persist data in PostgreSQL and send alerts to operators. The operator client offers device views, metric history, alert review, commands, and live alerts. Several listed capabilities are only partially implemented in the sampled code; README-backed edges describe intended product behavior, not verified runtime wiring.

Main entry points: [`server/src/Server_main.c`](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Server_main.c) (Server runtime), [`operator/src/operator_main.c`](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/operator_main.c) (Operator client), [`server/src/Alert.c`](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Alert.c) (Alert delivery), [`agent/src/Agent_main.c`](https://github.com/sufferer-of-his-sins/netwatch/blob/main/agent/src/Agent_main.c) (Device agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_endpoints["Client endpoints"]
  node_agent["Device agent<br/>[Agent_main.c]"]
  node_operator_client["Operator client<br/>[operator_main.c]"]
end

subgraph group_server["Server services"]
  node_server_runtime["Server runtime<br/>[Server_main.c]"]
  node_registration["Agent registration<br/>[Register_ack.c]"]
  node_heartbeat["Heartbeat handling<br/>[Heartbeat_ack.c]"]
  node_metrics_processing["Metrics and status"]
  node_offline_detection["Offline detection"]
  node_alert_delivery["Alert delivery<br/>[Alert.c]"]
  node_query_handling["Query handling<br/>[Query_result.c]"]
  node_command_routing["Command routing<br/>[Command.c]"]
end

subgraph group_operator["Operator workflows"]
  node_device_list["Device status list"]
  node_device_details["Device details<br/>[device_detail .c]"]
  node_metrics_history["Metrics history<br/>[metrics_history.c]"]
  node_alert_journal["Alert journal<br/>[allert_journal.c]"]
  node_command_ui["Device commands"]
end

subgraph group_shared["Protocol and storage"]
  node_protocol["Shared protocol types<br/>[library.h]"]
  node_agent_api["Agent interface<br/>[InAgent.h]"]
  node_operator_api["Operator interface<br/>[InOperator.h]"]
  node_server_api["Server interface<br/>[InServer.h]"]
  node_database_schema[("Monitoring schema<br/>[init.sql]")]
end

node_operator_actor(("Network operator"))
node_postgres[("PostgreSQL")]

node_operator_client -->|"presents menu"| node_operator_actor
node_operator_client -.->|"offers view"| node_device_list
node_operator_client -.->|"offers view"| node_device_details
node_operator_client -.->|"offers history"| node_metrics_history
node_operator_client -.->|"offers journal"| node_alert_journal
node_operator_client -.->|"offers commands"| node_command_ui
node_agent -.->|"sends telemetry"| node_server_runtime
node_server_runtime -.->|"handles registration"| node_registration
node_server_runtime -.->|"handles heartbeat"| node_heartbeat
node_server_runtime -.->|"handles metrics"| node_metrics_processing
node_server_runtime -.->|"checks timeouts"| node_offline_detection
node_offline_detection -.->|"raises alerts"| node_alert_delivery
node_server_runtime -.->|"handles queries"| node_query_handling
node_operator_client -.->|"sends queries"| node_server_runtime
node_server_runtime -.->|"broadcasts alerts"| node_alert_delivery
node_alert_delivery -.->|"sends alerts"| node_operator_client
node_operator_client -.->|"sends commands"| node_command_routing
node_command_routing -.->|"forwards commands"| node_agent
node_server_runtime -.->|"persists monitoring data"| node_postgres
node_database_schema -->|"defines tables"| node_postgres
node_operator_client -.->|"uses TCP framing"| node_server_runtime
node_agent -->|"uses shared types"| node_protocol
node_operator_client -->|"uses shared types"| node_protocol
node_server_runtime -->|"uses shared types"| node_protocol
node_server_runtime -->|"exposes handler"| node_registration
node_server_runtime -->|"exposes handler"| node_heartbeat
node_server_runtime -->|"exposes handler"| node_query_handling
node_server_runtime -->|"exposes handler"| node_command_routing
node_server_runtime -->|"exposes handler"| node_alert_delivery

click node_agent "https://github.com/sufferer-of-his-sins/netwatch/blob/main/agent/src/Agent_main.c"
click node_operator_client "https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/operator_main.c"
click node_server_runtime "https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Server_main.c"
click node_registration "https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Register_ack.c"
click node_heartbeat "https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Heartbeat_ack.c"
click node_metrics_processing "https://github.com/sufferer-of-his-sins/netwatch/tree/main/server/src"
click node_offline_detection "https://github.com/sufferer-of-his-sins/netwatch/tree/main/server/src"
click node_alert_delivery "https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Alert.c"
click node_query_handling "https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Query_result.c"
click node_command_routing "https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Command.c"
click node_device_list "https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/list_device_and_state.c"
click node_device_details "https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/device_detail%20.c"
click node_metrics_history "https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/metrics_history.c"
click node_alert_journal "https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/allert_journal.c"
click node_command_ui "https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/sending_command_device.c"
click node_protocol "https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/library.h"
click node_agent_api "https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/InAgent.h"
click node_operator_api "https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/InOperator.h"
click node_server_api "https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/InServer.h"
click node_database_schema "https://github.com/sufferer-of-his-sins/netwatch/blob/main/database/init.sql"

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_agent,node_operator_client toneBlue
class node_server_runtime,node_registration,node_heartbeat,node_metrics_processing,node_offline_detection,node_alert_delivery,node_query_handling,node_command_routing,node_postgres toneAmber
class node_device_list,node_device_details,node_metrics_history,node_alert_journal,node_command_ui toneMint
class node_protocol,node_agent_api,node_operator_api,node_server_api,node_database_schema toneRose
class node_operator_actor toneIndigo
```

## Components

### Client endpoints

- [Device agent](https://github.com/sufferer-of-his-sins/netwatch/blob/main/agent/src/Agent_main.c): `agent/src/Agent_main.c`
- [Operator client](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/operator_main.c): `operator/src/operator_main.c`

### Server services

- [Server runtime](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Server_main.c): `server/src/Server_main.c`
- [Agent registration](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Register_ack.c): `server/src/Register_ack.c`
- [Heartbeat handling](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Heartbeat_ack.c): `server/src/Heartbeat_ack.c`
- [Metrics and status](https://github.com/sufferer-of-his-sins/netwatch/tree/main/server/src): `server/src`
- [Offline detection](https://github.com/sufferer-of-his-sins/netwatch/tree/main/server/src): `server/src`
- [Alert delivery](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Alert.c): `server/src/Alert.c`
- [Query handling](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Query_result.c): `server/src/Query_result.c`
- [Command routing](https://github.com/sufferer-of-his-sins/netwatch/blob/main/server/src/Command.c): `server/src/Command.c`

### Operator workflows

- [Device status list](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/list_device_and_state.c): `operator/src/list_device_and_state.c`
- [Device details](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/device_detail%20.c): `operator/src/device_detail .c`
- [Metrics history](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/metrics_history.c): `operator/src/metrics_history.c`
- [Alert journal](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/allert_journal.c): `operator/src/allert_journal.c`
- [Device commands](https://github.com/sufferer-of-his-sins/netwatch/blob/main/operator/src/sending_command_device.c): `operator/src/sending_command_device.c`

### Protocol and storage

- [Shared protocol types](https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/library.h): `include/library.h`
- [Agent interface](https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/InAgent.h): `include/InAgent.h`
- [Operator interface](https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/InOperator.h): `include/InOperator.h`
- [Server interface](https://github.com/sufferer-of-his-sins/netwatch/blob/main/include/InServer.h): `include/InServer.h`
- [Monitoring schema](https://github.com/sufferer-of-his-sins/netwatch/blob/main/database/init.sql): `database/init.sql`

### Other components

- **Network operator**
- **PostgreSQL**

## Connections

- Operator client → Network operator: presents menu (evidence: `operator/src/operator_main.c`)
- Operator client → Device status list: offers view (evidence: `README.md`)
- Operator client → Device details: offers view (evidence: `README.md`)
- Operator client → Metrics history: offers history (evidence: `README.md`)
- Operator client → Alert journal: offers journal (evidence: `README.md`)
- Operator client → Device commands: offers commands (evidence: `README.md`)
- Device agent → Server runtime: sends telemetry (evidence: `README.md`)
- Server runtime → Agent registration: handles registration (evidence: `README.md`)
- Server runtime → Heartbeat handling: handles heartbeat (evidence: `README.md`)
- Server runtime → Metrics and status: handles metrics (evidence: `README.md`)
- Server runtime → Offline detection: checks timeouts (evidence: `README.md`)
- Offline detection → Alert delivery: raises alerts (evidence: `README.md`)
- Server runtime → Query handling: handles queries (evidence: `README.md`)
- Operator client → Server runtime: sends queries (evidence: `README.md`)
- Server runtime → Alert delivery: broadcasts alerts (evidence: `README.md`)
- Alert delivery → Operator client: sends alerts (evidence: `README.md`)
- Operator client → Command routing: sends commands (evidence: `README.md`)
- Command routing → Device agent: forwards commands (evidence: `README.md`)
- Server runtime → PostgreSQL: persists monitoring data (evidence: `README.md`)
- Monitoring schema → PostgreSQL: defines tables (evidence: `README.md`)
- Operator client → Server runtime: uses TCP framing (evidence: `README.md`)
- Device agent → Shared protocol types: uses shared types
- Operator client → Shared protocol types: uses shared types
- Server runtime → Shared protocol types: uses shared types
- Server runtime → Agent registration: exposes handler
- Server runtime → Heartbeat handling: exposes handler
- Server runtime → Query handling: exposes handler
- Server runtime → Command routing: exposes handler
- Server runtime → Alert delivery: exposes handler
