# mayssa1232/home_gateway_doctor architecture

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

- Interactive diagram: https://gitdiagram.com/mayssa1232/home_gateway_doctor
- Repository: https://github.com/mayssa1232/home_gateway_doctor

## Overview

HGW Doctor is a lightweight gateway-health daemon. Its main workflow is to load the TR-181 model, periodically sample system metrics, update the model, and expose it over ubus; the README also documents procd boot and crash-recovery integration. The source excerpt shows CPU and memory sampling and the model/ubus operations, but does not show uptime collection or the contents of the ODL and init files, so those details are represented only at the documented capability level.

Main entry points: [`src/main.c`](https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c) (HGW Doctor daemon), [`files/HGW_doctor.init`](https://github.com/mayssa1232/home_gateway_doctor/blob/main/files/HGW_doctor.init) (Service init), [`odl/HGW_doctor.odl`](https://github.com/mayssa1232/home_gateway_doctor/blob/main/odl/HGW_doctor.odl) (Model definition)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Health monitoring"]
  node_daemon["HGW Doctor daemon<br/>[main.c]"]
  node_sampler["Metric sampler<br/>[main.c]"]
  node_eventloop["Event loop<br/>[main.c]"]
end

subgraph group_model["TR-181 model"]
  node_model[("TR-181 data model<br/>[main.c]")]
  node_odl["Model definition<br/>[HGW_doctor.odl]"]
end

subgraph group_integration["Gateway integration"]
  node_ubus["ubus service"]
  node_init["Service init<br/>[HGW_doctor.init]"]
end

node_gateway(("Gateway system"))
node_proc[("Linux proc metrics")]
node_procd["procd supervisor"]

node_gateway -->|"exposes metrics"| node_proc
node_daemon -->|"loads definition"| node_odl
node_daemon -->|"initializes"| node_model
node_daemon -->|"starts polling"| node_sampler
node_sampler -->|"reads CPU/RAM"| node_proc
node_sampler -->|"updates metrics"| node_model
node_daemon -->|"registers model"| node_ubus
node_daemon -->|"runs"| node_eventloop
node_eventloop -->|"handles requests"| node_ubus
node_procd -.->|"supervises service"| node_init
node_init -.->|"starts and recovers"| node_daemon

click node_daemon "https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c"
click node_sampler "https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c"
click node_eventloop "https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c"
click node_model "https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c"
click node_odl "https://github.com/mayssa1232/home_gateway_doctor/blob/main/odl/HGW_doctor.odl"
click node_init "https://github.com/mayssa1232/home_gateway_doctor/blob/main/files/HGW_doctor.init"

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_daemon,node_sampler,node_eventloop toneBlue
class node_model,node_odl,node_proc toneAmber
class node_ubus,node_init toneMint
class node_gateway,node_procd toneIndigo
```

## Components

### Health monitoring

- [HGW Doctor daemon](https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c): `src/main.c`
- [Metric sampler](https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c): `src/main.c`
- [Event loop](https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c): `src/main.c`

### TR-181 model

- [TR-181 data model](https://github.com/mayssa1232/home_gateway_doctor/blob/main/src/main.c): `src/main.c`
- [Model definition](https://github.com/mayssa1232/home_gateway_doctor/blob/main/odl/HGW_doctor.odl): `odl/HGW_doctor.odl`

### Gateway integration

- **ubus service**
- [Service init](https://github.com/mayssa1232/home_gateway_doctor/blob/main/files/HGW_doctor.init): `files/HGW_doctor.init`

### Other components

- **Gateway system**
- **Linux proc metrics**
- **procd supervisor**

## Connections

- Gateway system → Linux proc metrics: exposes metrics
- HGW Doctor daemon → Model definition: loads definition (evidence: `src/main.c`)
- HGW Doctor daemon → TR-181 data model: initializes (evidence: `src/main.c`)
- HGW Doctor daemon → Metric sampler: starts polling (evidence: `src/main.c`)
- Metric sampler → Linux proc metrics: reads CPU/RAM (evidence: `src/main.c`)
- Metric sampler → TR-181 data model: updates metrics (evidence: `src/main.c`)
- HGW Doctor daemon → ubus service: registers model (evidence: `src/main.c`)
- HGW Doctor daemon → Event loop: runs (evidence: `src/main.c`)
- Event loop → ubus service: handles requests (evidence: `src/main.c`)
- procd supervisor → Service init: supervises service (evidence: `README.md`)
- Service init → HGW Doctor daemon: starts and recovers (evidence: `README.md`)
