# openbmc/entity-manager architecture

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

- Interactive diagram: https://gitdiagram.com/openbmc/entity-manager
- Repository: https://github.com/openbmc/entity-manager

## Overview

##### Main components
a. Configuration Store
- Directory: configurations/*.json
- Schemas: schemas/*.json
b. Detection Daemons (Publishers)
- fru-device (src/fru_device)
- devicetree_vpd_parser (src/devicetree_vpd_parser)
- Other custom daemons (e.g., peci-pcie, smbios-mdr)
c. Entity Manager Core
- Modules under src/entity_manager:
- configuration (loads JSON)
- perform_scan & perform_probe (runs detection rules)
- overlay & expression (overrides & conditional logic)
- topology (builds entity graph)
- dbus_interface (publishes Exposes records)
d. D-Bus Message Bus
- sdbusplus interface, service files under service_files/dbus
e. Reactors / Consumers
- dbus-sensors (scans & creates sensor objects)
- CPU managers, hot-swap backplane daemons, drive daemons
f. Build & Test Infrastructure
- Meson build files (meson.build, subprojects/)
- Unit tests (test/*.cpp)

##### Relationships & data flow
- Config Loader reads JSON configs & validates against schemas
- Detection Daemons scan hardware → publish “Detected Entity” signals on D-Bus
- Entity Manager Core listens on D-Bus → triggers perform_scan() & perform_probe() → applies overlays/expressions → builds in‐memory topology
- Core publishes “Exposes” records on D-Bus for each detected entity feature
- Reactors subscribe to “Exposes” signals → instantiate runtime objects (sensors, controllers)
- This loop repeats on re-detection events (device plug/unplug, host power on)

##### Architectural patterns & principles
– Event‐driven pipeline: Detection → Core Processing → Publication → Consumption
– Plugin-style modules: separate .cpp/.hpp under src/entity_manager, fru_device, devicetree_vpd_parser
– Clear separation of concerns: config parsing, detection logic, topology construction, D-Bus interface, reactor actions
– Schema‐driven configuration: JSON+Valijson ensures consistency

##### Technologies & libraries
– C++17, Meson build system
– nlohmann_json for JSON parsing
– Valijson for schema validation
– sdbusplus & phosphor-dbus-interfaces for D-Bus integration
– phosphor-logging for log messages
– GoogleTest for unit tests

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Configuration"
        CS["Configuration Store"]:::config
        SS["Configuration Schemas"]:::config
    end

    subgraph "Detection Daemons"
        FD["fru-device"]:::detection
        DV["devicetree_vpd_parser"]:::detection
        OD["Other Custom Daemons"]:::detection
    end

    subgraph "Entity Manager Core"
        CFG["configuration"]:::core
        PS["perform_scan"]:::core
        PP["perform_probe"]:::core
        OVL["overlay"]:::core
        EXP["expression"]:::core
        TOP["topology"]:::core
        DBI["dbus_interface"]:::core
    end

    subgraph "D-Bus Message Bus"
        DB["D-Bus"]:::dbus
    end

    subgraph "Reactors / Consumers"
        SEN["dbus-sensors"]:::reactor
        CPU["CPU Managers"]:::reactor
        HS["Hot-swap Backplane Daemons"]:::reactor
        DD["Drive Daemons"]:::reactor
    end

    subgraph "Build & Test Infrastructure"
        MB["Meson Build Files"]:::infra
        SP["Subprojects"]:::infra
        UT["Unit Tests"]:::infra
    end

    CS -->|"load configs"| CFG
    SS -->|"validate schemas"| CFG

    FD -->|"DetectedEntity"| DB
    DV -->|"DetectedEntity"| DB
    OD -->|"DetectedEntity"| DB

    DB -->|"onDetection"| PS
    DB -->|"onDetection"| PP

    PS -->|"scan result"| OVL
    PP -->|"probe result"| OVL

    OVL -->|"apply overrides"| EXP
    EXP -->|"evaluate expressions"| TOP
    TOP -->|"build graph"| DBI
    DBI -->|"publishExposes"| DB

    DB -->|"Exposes"| SEN
    DB -->|"Exposes"| CPU
    DB -->|"Exposes"| HS
    DB -->|"Exposes"| DD

    MB -.-> CFG
    MB -.-> FD
    MB -.-> DV
    MB -.-> UT
    SP -.-> MB
    UT -.-> CFG
    UT -.-> FD

    classDef config fill:#ADD8E6,stroke:#333,stroke-width:1px;
    classDef detection fill:#98FB98,stroke:#333,stroke-width:1px;
    classDef core fill:#00008B,stroke:#fff,stroke-width:1px,color:#fff;
    classDef dbus fill:#FFA500,stroke:#333,stroke-width:1px;
    classDef reactor fill:#DA70D6,stroke:#333,stroke-width:1px;
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px;

    click CS "https://github.com/openbmc/entity-manager/tree/master/configurations/"
    click SS "https://github.com/openbmc/entity-manager/tree/master/schemas/"
    click FD "https://github.com/openbmc/entity-manager/tree/master/src/fru_device/"
    click DV "https://github.com/openbmc/entity-manager/tree/master/src/devicetree_vpd_parser/"
    click CFG "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/configuration.cpp"
    click PS "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/perform_scan.cpp"
    click PP "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/perform_probe.cpp"
    click OVL "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/overlay.cpp"
    click EXP "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/expression.cpp"
    click TOP "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/topology.cpp"
    click DBI "https://github.com/openbmc/entity-manager/blob/master/src/entity_manager/dbus_interface.cpp"
    click EntityManagerService "https://github.com/openbmc/entity-manager/blob/master/service_files/dbus/xyz.openbmc_project.EntityManager.service"
```
