# openbmc/dbus-sensors architecture

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

- Interactive diagram: https://gitdiagram.com/openbmc/dbus-sensors
- Repository: https://github.com/openbmc/dbus-sensors

## Overview

##### Project Type and Purpose
- This is a collection of sensor applications – essentially, many small “sensor daemons” – that provide DBus interfaces for sensor values and threshold information.
- Each sensor type (ADC, external, fan, hwmon-temp, intel-cpu, intrusion, IPMB, MCTP, MCU, NVMe, PSU, etc.) is implemented as its own standalone daemon. This modular design increases isolation (so that faults in one sensor have minimal impact on others) and simplifies individual updates.
- The project integrates with DBus (using sdbusplus with Asio for asynchronous event handling) to publish sensor updates and allow runtime configuration through an entity manager and other DBus consumers (like Redfish or IPMI SDR).

##### Analyzing the File Structure
- Top-Level Directories:
- “src”: Contains source code for each sensor type. Each subdirectory (e.g., src/adc, src/fan, src/intel-cpu, etc.) encapsulates the logic for a specific sensor.
- “include”: Contains common header files, including OS-specific ones (e.g., include/linux/peci-ioctl.h) that might be used by the sensor implementations.
- “service_files”: Contains service configuration files (likely for systemd) that map each sensor daemon to its corresponding DBus service (e.g., xyz.openbmc_project.adcsensor.service).
- “subprojects”: Bundles third-party dependencies (e.g., Boost, googletest, sdbusplus wraps) necessary for building and running the project.
- Build system files: “meson.build” and “meson.options” both at the root and in sensor-specific directories imply a well-structured build process to compile each sensor daemon independently.
- Testing: The “src/tests” directory shows that unit testing is part of the project architecture.

##### Key Architectural Components
a. Sensor Daemons – One for each sensor type (ADC, external, fan, hwmon-temp, etc.). Each of these is an isolated component with its own main function (for example, ADCSensorMain, FanMain, etc.).
b. Common Core Libraries and Utilities – Code in src/ such as DeviceMgmt, FileHandle, SensorPaths, and Thresholds provide shared functionality across sensor types.
c. DBus Communication Layer – The use of sdbusplus/asio bindings for asynchronous DBus interaction. Illustrate how sensor daemons publish their sensor readings and thresholds under the xyz.openbmc_project.Sensor hierarchy.
d. External Inputs and Hardware Interfaces – The sensors collect data from various platforms (hwmon sysfs, direct driver access, and D-Bus inputs), which should be drawn as data sources feeding into each sensor daemon.

##### Summary of Elements the Principal Software Engineer Should Include
- Labels for each sensor daemon component with their corresponding sensor types.
- A DBus bus component that aggregates sensor information.
- Data flow from hardware/OS interfaces (hwmon, GPIO, direct driver calls) to sensor processing.
- Configuration data flow from an external configuration (entity manager) into each sensor daemon.
- Sensor value and status updates sent from the sensor daemons to the DBus layer.
- Sensor daemons
- External data sources (hardware drivers, configuration systems)
- Consumers of DBus sensor data (e.g., Redfish, IPMI SDR)
- Annotations highlighting the usage of asynchronous event handling (via sdbusplus and asio), the modular design (isolated sensor daemons), and the reactor pattern used for sensor updates.

## Diagram (Mermaid)

```mermaid
graph TD
    Hardware["Hardware/OS Interfaces"]:::external
    Config["Entity Manager/Configuration"]:::external

    subgraph "Sensor Daemons"
        Core["Common Core Libraries and Utilities"]:::core
        ADC["ADC Sensor Daemon"]:::daemon
        Exit["Exit Air Sensor Daemon"]:::daemon
        External["External Sensor Daemon"]:::daemon
        Fan["Fan Sensor Daemon"]:::daemon
        Hwmon["Hwmon Temp Sensor Daemon"]:::daemon
        Intel["Intel CPU Sensor Daemon"]:::daemon
        Intrusion["Intrusion Sensor Daemon"]:::daemon
        IPMB["IPMB Sensor Daemon"]:::daemon
        MCTP["MCTP Reactor Component"]:::daemon
        MCU["MCU Temp Sensor Daemon"]:::daemon
        NVMe["NVMe Sensor Daemon"]:::daemon
        PSU["PSU Sensor Daemon"]:::daemon
    end

    DBus["DBus Communication Layer<br>/xyz/openbmc_project/sensors/<type>/<sensor_name>"]:::bus
    DBusConfig["DBus Service Configurations"]:::bus
    Consumer["External Consumers<br>(Redfish,IPMI SDR)"]:::consumer
    Build["Build System & Testing"]:::build

    %% Hardware and configuration feed sensor daemons
    Hardware --> ADC
    Hardware --> Exit
    Hardware --> External
    Hardware --> Fan
    Hardware --> Hwmon
    Hardware --> Intel
    Hardware --> Intrusion
    Hardware --> IPMB
    Hardware --> MCTP
    Hardware --> MCU
    Hardware --> NVMe
    Hardware --> PSU

    Config --> ADC
    Config --> Exit
    Config --> External
    Config --> Fan
    Config --> Hwmon
    Config --> Intel
    Config --> Intrusion
    Config --> IPMB
    Config --> MCTP
    Config --> MCU
    Config --> NVMe
    Config --> PSU

    %% Sensor daemons use common core libraries
    ADC --> Core
    Exit --> Core
    External --> Core
    Fan --> Core
    Hwmon --> Core
    Intel --> Core
    Intrusion --> Core
    IPMB --> Core
    MCTP --> Core
    MCU --> Core
    NVMe --> Core
    PSU --> Core

    %% Sensor daemons publish to DBus
    ADC -->|"publish"| DBus
    Exit -->|"publish"| DBus
    External -->|"publish"| DBus
    Fan -->|"publish"| DBus
    Hwmon -->|"publish"| DBus
    Intel -->|"publish"| DBus
    Intrusion -->|"publish"| DBus
    IPMB -->|"publish"| DBus
    MCTP -->|"publish"| DBus
    MCU -->|"publish"| DBus
    NVMe -->|"publish"| DBus
    PSU -->|"publish"| DBus

    %% DBus communicates to external consumers
    DBus -->|"notify"| Consumer

    %% DBus service configurations feed into DBus layer
    DBusConfig -->|"service mapping"| DBus

    %% Build system influences critical components
    Build -.-> Hardware
    Build -.-> Core
    Build -.-> DBusConfig

    %% Click Events for Sensor Daemons and Core libraries
    click ADC "https://github.com/openbmc/dbus-sensors/blob/master/src/adc/ADCSensorMain.cpp"
    click Exit "https://github.com/openbmc/dbus-sensors/blob/master/src/exit-air/ExitAirTempSensor.cpp"
    click External "https://github.com/openbmc/dbus-sensors/blob/master/src/external/ExternalSensorMain.cpp"
    click Fan "https://github.com/openbmc/dbus-sensors/blob/master/src/fan/FanMain.cpp"
    click Hwmon "https://github.com/openbmc/dbus-sensors/blob/master/src/hwmon-temp/HwmonTempMain.cpp"
    click Intel "https://github.com/openbmc/dbus-sensors/blob/master/src/intel-cpu/IntelCPUSensorMain.cpp"
    click Intrusion "https://github.com/openbmc/dbus-sensors/blob/master/src/intrusion/IntrusionSensorMain.cpp"
    click IPMB "https://github.com/openbmc/dbus-sensors/blob/master/src/ipmb/IpmbSensorMain.cpp"
    click MCTP "https://github.com/openbmc/dbus-sensors/blob/master/src/mctp/MCTPReactorMain.cpp"
    click MCU "https://github.com/openbmc/dbus-sensors/tree/master/src/mcu"
    click NVMe "https://github.com/openbmc/dbus-sensors/blob/master/src/nvme/NVMeSensorMain.cpp"
    click PSU "https://github.com/openbmc/dbus-sensors/blob/master/src/psu/PSUSensorMain.cpp"
    click Core "https://github.com/openbmc/dbus-sensors/blob/master/src/DeviceMgmt.cpp"
    click DBusConfig "https://github.com/openbmc/dbus-sensors/tree/master/service_files"

    
classDef daemon fill:#FFD700,stroke:#333,stroke-width:1px;
classDef core fill:#FFA500,stroke:#333,stroke-width:1px;
classDef bus fill:#98FB98,stroke:#333,stroke-width:1px;
classDef external fill:#87CEEB,stroke:#333,stroke-width:1px;
classDef consumer fill:#FFB6C1,stroke:#333,stroke-width:1px;
classDef build fill:#D3D3D3,stroke:#333,stroke-width:1px;
class Hardware,Config external
```
