# intel/ledmon architecture

> Architecture diagram of the GitHub repository intel/ledmon, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/intel/ledmon
- Repository: https://github.com/intel/ledmon

## Overview

##### Project type and purpose
- This is a system-level utility suite (“Enclosure LED Utilities”) written in C, comprising:
- A command-line tool (ledctl) for manual LED control
- A background daemon (ledmon) for automated LED monitoring/manipulation
- A shared library (libled) providing a unified API for various hardware interfaces
- Unit tests, documentation, and a systemd service unit

##### File structure
- Top-level directories
- src/ledctl — CLI implementation
- src/ledmon — daemon implementation
- src/common — shared config-file parsing code
- src/lib — shared library modules (IPMI, AHCI, SCSI, sysfs, udev, PCI, etc.)
- systemd — .service.in template for systemd integration
- tests — Python & C tests for CLI, lib, and daemon
- Build infrastructure
- autogen.sh, configure.ac, Makefile.am — GNU Autotools for configure/build
- m4/ — custom Autoconf macros
- Documentation & packaging
- doc/ — POD documentation for tools and configuration
- .github/ — CI workflows, linting, test automation

##### Extract architectural insights from the README
- The utilities interact directly with hardware via multiple subsystems (libsgutils, libudev, pciutils).
- Optional components are enabled via configure flags: systemd service, shared library, unit tests.

- ledctl CLI
- ledmon daemon
- libled (core library)
- Common config parser
- Underlying OS subsystems:
– sysfs (kernel LED sysfs interface)
– udev (device event monitoring)
– IPMI/AHCI/SCSI driver interfaces
– PCI access subsystem
- systemd (service manager)
- Configuration file (ledmon.conf)
- ledctl → libled: command-dispatch calls
- ledmon → libled: polling / event callbacks
- libled → sysfs / udev / IPMI / PCI: hardware I/O calls
- systemd → ledmon: service start/stop
- ledmon ← ledmon.conf: configuration read by common parser
c. Architectural patterns & principles
- Modular layering: CLI/daemon code calls a shared library rather than duplicating hardware logic
- Abstraction of hardware access behind libled’s drivers (IPMI, AHCI, sysfs, etc.)
- Separation of concerns: config parsing isolated in src/common
d. Key technologies & libraries
- GNU Autotools (autoconf, automake) for build
- systemd for service management
- libudev, libsgutils, pciutils for hardware access
- Check & pytest for unit tests

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User-facing Tools
    ledctl["ledctl CLI"]:::code
    ledmon["ledmon Daemon"]:::code

    %% Configuration
    configParser["Common Config Parser"]:::code
    confFile["ledmon.conf"]:::config

    %% Service Manager
    systemd["systemd Service"]:::config

    %% Core Library
    libled["libled Shared Library"]:::code

    %% Hardware Drivers Group
    subgraph "Hardware Drivers"
        style Hardware Drivers stroke-dasharray: 5 5
        ipmi["IPMI Driver"]:::subsys
        sysfs["Sysfs Driver"]:::subsys
        ahci["AHCI Driver"]:::subsys
        scsi["SCSI Driver"]:::subsys
        pci["PCI Access Module"]:::subsys
    end

    %% Tests & CI
    tests["Unit Tests & CI"]:::test

    %% Connections
    ledctl -->|"set_led_state()"| libled
    ledmon -->|"monitor()/callback"| libled
    ledmon -->|"parse_config()"| configParser
    configParser --> confFile
    systemd -->|"start/stop"| ledmon
    libled --> ipmi
    libled --> sysfs
    libled --> ahci
    libled --> scsi
    libled --> pci
    tests -.-> ledctl
    tests -.-> libled
    tests -.-> ledmon

    %% Click Events
    click ledctl "https://github.com/intel/ledmon/blob/main/src/ledctl/ledctl.c"
    click ledmon "https://github.com/intel/ledmon/blob/main/src/ledmon/ledmon.c"
    click libled "https://github.com/intel/ledmon/blob/main/src/lib/libled.c"
    click configParser "https://github.com/intel/ledmon/blob/main/src/common/config_file.c"
    click confFile "https://github.com/intel/ledmon/blob/main/doc/ledmon.conf.pod"
    click systemd "https://github.com/intel/ledmon/blob/main/systemd/ledmon.service.in"
    click ipmi "https://github.com/intel/ledmon/blob/main/src/lib/ipmi.c"
    click sysfs "https://github.com/intel/ledmon/blob/main/src/lib/sysfs.c"
    click ahci "https://github.com/intel/ledmon/blob/main/src/lib/ahci.c"
    click scsi "https://github.com/intel/ledmon/blob/main/src/lib/scsi.c"
    click pci "https://github.com/intel/ledmon/blob/main/src/lib/pci_slot.c"
    click tests "https://github.com/intel/ledmon/tree/main/tests/ledctl/"
    click tests "https://github.com/intel/ledmon/tree/main/.github/workflows/"

    %% Styles
    classDef code fill:#ADD8E6,stroke:#000,stroke-width:1px,color:#000
    classDef subsys fill:#90EE90,stroke:#000,stroke-width:1px,color:#000
    classDef config fill:#FFA500,stroke:#000,stroke-width:1px,color:#000
    classDef test fill:#D3D3D3,stroke:#000,stroke-width:1px,color:#000
```
