# sysrqmagician/stringbar architecture

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

- Interactive diagram: https://gitdiagram.com/sysrqmagician/stringbar
- Repository: https://github.com/sysrqmagician/stringbar

## Overview

##### Main Components
- Main Executable: Represented by src/main.rs in the top-level project, this is the entry point that orchestrates the status bar updates.
- Library/Module for Functionality: There’s a “bittenhumans” directory that includes its own Cargo.toml and source files (e.g., bittenhumans/src/lib.rs and bittenhumans/src/consts.rs) – this likely provides reusable functionality or abstractions used by the main executable.
- Configuration Module: Based on the README instructions, the configuration file (located at $XDG_CONFIG_HOME/stringbar/config.ron) must be read, parsed, and its settings dynamically reloaded (hot config reloading) during runtime.
- Status Modules: The README lists several available modules (CpuUsage, MemoryUsage, DiskUsage modules, Timestamp, etc.). Each module is responsible for gathering and formatting specific system information.
- Runtime Loop / Scheduler: Implicit in the configuration (update_interval_ms) is a periodic update cycle for refreshing the status bar.
- System Call Interface: Integration with external tools like xsetroot for setting the X root window name.
- Build/Deployment Tools: Presence of a Justfile (for building via [Just]) and GitHub workflows (Rust and conventional commits) indicates that build scripts and CI/CD pipelines are part of the overall system but aren’t runtime components.

##### Relationships and Interactions
- The main executable initializes the application, loads the configuration, and sets up a scheduler to periodically update the status bar.
- The configuration module parses the RON file and wires up the desired status modules with customized decorations.
- Each status module acts as an independent component that gathers its designated system metric.
- The outputs from each module are formatted (with provided “before” and “after” decorations) and concatenated using a specified separator.
- A final “update” function triggers the call to xsetroot to update the X root window name with the aggregated output.
- The “bittenhumans” crate/library may be providing some shared logic or abstractions used by one or more status modules, so it should be visually shown as a supporting library.

##### Architectural Patterns & Design Principles
- Config-Driven Behavior: Emphasize that the application behavior is heavily influenced by a configuration file, thus including a “Configuration” component is essential.

##### Technologies & Frameworks
- Rust: The whole project is written in Rust, as indicated by multiple Cargo.toml files and the Rust GitHub workflows.
- X11 (xsetroot): Depicted as an external dependency.
- Build Tools: Just (for building) and UPX (for binary compression) should be noted in the deployment/build tool chain if relevant.

##### Elements
- Clear labels for:
- Main Application (stringbar main binary)
- Configuration Loader (reads config.ron)
- Status Modules (each module such as CpuUsage, MemoryUsage, etc.)
- Supporting Library (“bittenhumans” crate)
- Scheduler/Update Loop (handles periodic refresh)
- External Dependency (xsetroot / X server interaction)
- Data flow from the Configuration Loader to the main application and the Status Modules.
- Updates flowing from the Scheduler to the status bar updater.
- The final output flowing to the external system (xsetroot).
- Core application components (e.g., main executable, modules)
- External or system-level dependencies (e.g., X server, build tooling)
- Supporting libraries (like the “bittenhumans” crate)

- Capturing the interdependency of components: from configuration to module instantiation and from data assembly to external system update.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build/Deployment Tools
    subgraph "Build/Deployment Tools"
        BT1["Justfile"]:::build
        BT2[".github/workflows"]:::build
    end

    %% Application Core
    subgraph "Application Core"
        A1["Configuration Loader (config.ron)"]:::core
        A2["stringbar main binary"]:::core
        A3["Runtime Scheduler / Update Loop"]:::core

        subgraph "Status Modules"
            SM1["CpuUsage Module"]:::core
            SM2["MemoryUsage Module"]:::core
            SM3["DiskUsage Module"]:::core
            SM4["Timestamp Module"]:::core
        end
    end

    %% Supporting Library: bittenhumans crate
    subgraph "Supporting Library"
        BL1["bittenhumans lib.rs"]:::library
        BL2["bittenhumans consts.rs"]:::library
    end

    %% External Dependency
    ED["xsetroot (X server)"]:::external

    %% Connections within Application Core
    A1 -->|"loadConfig"| A2
    A3 -->|"triggerUpdate"| A2
    A2 -->|"collectMetrics"| SM1
    A2 -->|"collectMetrics"| SM2
    A2 -->|"collectMetrics"| SM3
    A2 -->|"collectMetrics"| SM4
    SM1 -->|"uses"| BL1
    SM1 -->|"uses"| BL2
    SM2 -->|"uses"| BL1
    SM2 -->|"uses"| BL2
    SM3 -->|"uses"| BL1
    SM3 -->|"uses"| BL2
    SM4 -->|"uses"| BL1
    SM4 -->|"uses"| BL2
    A2 -->|"update"| ED

    %% Click Events
    click A2 "https://github.com/sysrqmagician/stringbar/blob/main/src/main.rs"
    click BL1 "https://github.com/sysrqmagician/stringbar/blob/main/bittenhumans/src/lib.rs"
    click BL2 "https://github.com/sysrqmagician/stringbar/blob/main/bittenhumans/src/consts.rs"
    click A1 "https://github.com/sysrqmagician/stringbar/blob/main/$XDG_CONFIG_HOME/stringbar/config.ron"
    click BT1 "https://github.com/sysrqmagician/stringbar/tree/main/Justfile"
    click BT2 "https://github.com/sysrqmagician/stringbar/tree/main/.github/workflows"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef library fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef external fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef build fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
```
