# clockley/watchdogd architecture

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

- Interactive diagram: https://gitdiagram.com/clockley/watchdogd
- Repository: https://github.com/clockley/watchdogd

## Overview

##### Main Components

a) Core Watchdog Components:
- Watchdog Timer Interface (watchdog.cpp/hpp)
- Configuration Manager (configfile.cpp/hpp)
- System Monitor Components
- Repair Script Manager
- Thread Pool (threadpool.cpp/hpp)
- D-Bus API Interface (dbusapi.cpp/hpp)

b) Monitoring Subsystems:
- Network Monitor (network_tester.cpp/hpp)
- Load Average Monitor
- Memory Monitor
- PID File Monitor
- Directory Monitor (testdir.cpp/hpp)

c) External Interfaces:
- System Watchdog Device
- D-Bus System
- Filesystem (for repair scripts)
- System Services (via PID files)

**┌─────────────────────────────────────────┐**
- External Layer             │
- (Hardware WDT, System Services, etc.)  │
- ┤
- Interface Layer              │
- (D-Bus, Device Drivers, Files)     │
- ┤
- Core Components              │
- (Timer, Config, Monitors, Thread Pool) │
- ┤
- Monitoring Systems            │
- (Network, Load, Memory, PID, Directory)  │
- ┘

##### Component Relationships

- Blue: Core components
- Green: Monitoring systems
- Orange: External interfaces
- Gray: System resources being monitored

##### Specific Implementation Details

a) Core Process Flow:
- Main daemon loop
- Configuration file input
- Thread pool management
- Repair script execution paths

b) Monitoring Flow:
- Parallel monitoring processes
- Threshold checking
- Error handling paths
- Repair action triggers

##### Additional Elements

- Timing indicators for key intervals
- Configuration parameters influence
- Error handling paths
- System state transitions

**┌─────────────────────────────────────────────────┐**
- Configuration                    │
- (watchdogd.conf, command-line options)       │
- ┤
- Core Daemon                      │
- ┌─────────────┐  ┌─────────────┐            │
- WDT Timer  │  │Thread Pool  │            │
- ┘  └─────────────┘            │
- ┤
- Monitoring Systems                 │
- ┌─────────┐ ┌────────┐ ┌────────────┐       │
- Network │ │ Load   │ │  Memory    │       │
- ┘ └────────┘ └────────────┘       │
- ┤
- Repair Actions                   │
- (Scripts, System Commands, Reboot)           │
- ┘

Remember to:
- Use consistent notation
- Version information
- Document all assumptions
- Error handling paths
- Configuration dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and classes
    classDef external fill:#FFA07A,stroke:#FF6347
    classDef interface fill:#87CEEB,stroke:#4682B4
    classDef core fill:#98FB98,stroke:#228B22
    classDef monitoring fill:#DDA0DD,stroke:#9370DB
    classDef config fill:#F0E68C,stroke:#DAA520
    classDef repair fill:#FFB6C1,stroke:#FF69B4

    %% External Layer
    subgraph External
        HW_WDT["Hardware Watchdog Timer"]:::external
        SYS_SERVICES["System Services"]:::external
        FILESYSTEM["Filesystem"]:::external
    end

    %% Interface Layer
    subgraph Interface
        WDT_IF["Watchdog Timer Interface"]:::interface
        DBUS_IF["D-Bus API Interface"]:::interface
        SYS_IF["System Interface"]:::interface
    end

    %% Core Components
    subgraph Core
        MAIN["Main Application"]:::core
        DAEMON["Daemon Core"]:::core
        CONFIG["Configuration Manager"]:::core
        THREAD_POOL["Thread Pool"]:::core
        BOOT_STATUS["Boot Status"]:::core
        ERROR_HANDLE["Error Handler"]:::core
    end

    %% Monitoring Systems
    subgraph Monitors
        NET_MON["Network Monitor"]:::monitoring
        LOAD_MON["Load Monitor"]:::monitoring
        MEM_MON["Memory Monitor"]:::monitoring
        PID_MON["PID File Monitor"]:::monitoring
        DIR_MON["Directory Monitor"]:::monitoring
    end

    %% Repair Components
    subgraph Repair
        REPAIR_MGR["Repair Script Manager"]:::repair
        REPAIR_SCRIPTS["Repair Scripts"]:::repair
    end

    %% Configuration Files
    subgraph Config_Files
        WATCHDOG_CONF["watchdogd.conf"]:::config
        DBUS_CONF["D-Bus Config"]:::config
        SYSTEMD_CONF["Systemd Service"]:::config
    end

    %% Relationships
    MAIN --> DAEMON
    DAEMON --> WDT_IF
    DAEMON --> THREAD_POOL
    DAEMON --> CONFIG
    CONFIG --> WATCHDOG_CONF
    DBUS_IF --> DBUS_CONF
    WDT_IF --> HW_WDT
    THREAD_POOL --> NET_MON
    THREAD_POOL --> LOAD_MON
    THREAD_POOL --> MEM_MON
    THREAD_POOL --> PID_MON
    THREAD_POOL --> DIR_MON
    NET_MON --> REPAIR_MGR
    LOAD_MON --> REPAIR_MGR
    MEM_MON --> REPAIR_MGR
    PID_MON --> REPAIR_MGR
    DIR_MON --> REPAIR_MGR
    REPAIR_MGR --> REPAIR_SCRIPTS
    REPAIR_SCRIPTS --> SYS_SERVICES
    PID_MON --> SYS_SERVICES
    BOOT_STATUS --> SYS_IF
    ERROR_HANDLE --> DAEMON

    %% Click events for component mapping
    click WDT_IF "https://github.com/clockley/watchdogd/blob/master/src/watchdog.cpp"
    click CONFIG "https://github.com/clockley/watchdogd/blob/master/src/configfile.cpp"
    click THREAD_POOL "https://github.com/clockley/watchdogd/blob/master/src/threadpool.cpp"
    click DBUS_IF "https://github.com/clockley/watchdogd/blob/master/src/dbusapi.cpp"
    click NET_MON "https://github.com/clockley/watchdogd/blob/master/src/network_tester.cpp"
    click DIR_MON "https://github.com/clockley/watchdogd/blob/master/src/testdir.cpp"
    click PID_MON "https://github.com/clockley/watchdogd/blob/master/src/pidfile.cpp"
    click REPAIR_MGR "https://github.com/clockley/watchdogd/blob/master/src/repair.cpp"
    click BOOT_STATUS "https://github.com/clockley/watchdogd/blob/master/src/bootstatus.cpp"
    click DAEMON "https://github.com/clockley/watchdogd/blob/master/src/daemon.cpp"
    click WATCHDOG_CONF "https://github.com/clockley/watchdogd/blob/master/conf/watchdogd.conf"
    click SYSTEMD_CONF "https://github.com/clockley/watchdogd/blob/master/contrib/systemd/watchdogd.service.in"
    click DBUS_CONF "https://github.com/clockley/watchdogd/blob/master/contrib/dbus/watchdogd.conf"
    click ERROR_HANDLE "https://github.com/clockley/watchdogd/blob/master/src/errorlist.hpp"
    click MAIN "https://github.com/clockley/watchdogd/blob/master/src/main.cpp"

    %% Legend
    subgraph Legend
        L1["External Components"]:::external
        L2["Interface Layer"]:::interface
        L3["Core Components"]:::core
        L4["Monitoring Systems"]:::monitoring
        L5["Configuration"]:::config
        L6["Repair Systems"]:::repair
    end
```
