# riffe007/system-detection architecture

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

- Interactive diagram: https://gitdiagram.com/riffe007/system-detection
- Repository: https://github.com/riffe007/system-detection

## Overview

##### Main Components
- Backend (src/backend):
– Contains the core monitoring modules such as cpu_monitor.rs, memory_monitor.rs, gpu_monitor.rs, storage_monitor.rs, and logger.rs.
– The system_monitor.rs file aggregates the outputs from these subsystem modules, assembling the final metrics snapshot.
- Inference Module (src/inference):
– Comprises C++ source and header files (inference_engine, llama_wrapper, and quantization) that hint at additional analysis or predictive diagnostics capabilities, likely serving as an advanced data evaluation layer (e.g., using language models or machine learning based on the Llama integration).
– The CMakeList.txt file at the root further supports the existence and build requirements of these native code portions.
- Storage Module (src/storage):
– Provides caching, database, and vector storage functionality. This module likely supports persistence of monitoring data or fast retrieval for historical or analytical purposes.
- User Interface (src/ui):
– Written in TypeScript and utilizing React-style components (App.tsx, ChatWindow.tsx, Settings.tsx, Sidebar.tsx) along with an HTML entry point (index.html).
– Even though the README shows a CLI output example, the existence of a UI layer suggests a more advanced interactive dashboard for viewing metrics and possibly controlling settings.
- Configuration & Build Files:
– The config.json file likely contains runtime or deployment configurations.
– Cargo.toml and Cargo.lock manage Rust dependencies while CMakeList.txt handles the build of the C++ inference components.

##### Relationships & Interactions
- The centerpiece is the asynchronous SystemMonitor which gathers data concurrently by delegating to individual subsystem monitors.
- The resulting metrics (a HashMap<String, String> in Rust) are output to the console and can be extended via logging, web APIs, or integrated into a UI.
- The storage layer (cache, database, vector storage) might persist metrics for future analysis or serve as input for the inference module.
- The inference module works as a separate layer that may process or analyze the collected metrics data. Its C++ components could be interfaced via FFI (from Rust) or run as separate service communicating with the core monitor.

##### Architectural Patterns & Design Principles
- Modular Architecture: Each subsystem (backend monitors, storage, inference, UI) is cleanly separated, promoting reusability and extendability.
- Asynchronous Processing: The use of the tokio runtime ensures efficient concurrency for real-time metric collection.
- Extensibility: With clear modular divisions and a dedicated inference module, the design is prepared to evolve into more complex workflows such as daemons, web APIs, or comprehensive logging services.
- Clean Separation of Concerns: Backend data collection, UI rendering, persistent storage, and advanced analytics are all handled in different layers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Configuration & Build Files Subgraph
    subgraph "Configuration & Build Files"
        config["config.json"]:::config
        cargo["Cargo.toml"]:::config
        cmake["CMakeList.txt"]:::config
    end

    %% Backend (Rust) Subgraph
    subgraph "Backend (Rust)"
        sysMon["SystemMonitor"]:::backend
        cpu["CPU Monitor"]:::backend
        mem["Memory Monitor"]:::backend
        gpu["GPU Monitor"]:::backend
        storMon["Storage Monitor"]:::backend
        logger["Logger"]:::backend
    end

    %% Storage Module
    storage["Storage Module"]:::storage

    %% Inference Module
    inference["Inference Module"]:::inference

    %% User Interface
    ui["User Interface"]:::ui

    %% Connections from Monitoring Modules to SystemMonitor
    cpu -->|"sends_data"| sysMon
    mem -->|"sends_data"| sysMon
    gpu -->|"sends_data"| sysMon
    storMon -->|"sends_data"| sysMon
    logger -->|"sends_logs"| sysMon

    %% Connections from SystemMonitor to other components
    sysMon -->|"async_report"| storage
    sysMon -->|"display_metrics"| ui
    sysMon -->|"analyzes"| inference

    %% Connections from Storage Module to Inference Module
    storage -->|"provides_data"| inference

    %% Connections from Inference Module to UI
    inference -->|"results_to"| ui

    %% Connections from Configuration & Build Files to main components
    cargo -->|"configures"| sysMon
    config -->|"configures"| sysMon
    cmake -->|"builds"| inference
    cargo -->|"configures"| ui
    config -->|"configures"| ui

    %% Styles
    classDef backend fill:#FFEEAD,stroke:#F79F1F,stroke-width:2px;
    classDef inference fill:#E0BBE4,stroke:#9B59B6,stroke-width:2px;
    classDef storage fill:#FFCCCC,stroke:#E74C3C,stroke-width:2px;
    classDef ui fill:#AEDFF7,stroke:#3498DB,stroke-width:2px;
    classDef config fill:#C7F464,stroke:#27AE60,stroke-width:2px;

    %% Click Events
    click sysMon "https://github.com/riffe007/system-detection/tree/main/src/backend/"
    click cpu "https://github.com/riffe007/system-detection/tree/main/src/backend/"
    click mem "https://github.com/riffe007/system-detection/tree/main/src/backend/"
    click gpu "https://github.com/riffe007/system-detection/tree/main/src/backend/"
    click storMon "https://github.com/riffe007/system-detection/tree/main/src/backend/"
    click logger "https://github.com/riffe007/system-detection/tree/main/src/backend/"
    click inference "https://github.com/riffe007/system-detection/tree/main/src/inference/"
    click storage "https://github.com/riffe007/system-detection/tree/main/src/storage/"
    click ui "https://github.com/riffe007/system-detection/tree/main/src/ui/"
    click config "https://github.com/riffe007/system-detection/blob/main/config.json"
    click cargo "https://github.com/riffe007/system-detection/blob/main/Cargo.toml"
    click cmake "https://github.com/riffe007/system-detection/blob/main/CMakeList.txt"
```
