# hiro-microdatacenters-bv/rhio architecture

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

- Interactive diagram: https://gitdiagram.com/hiro-microdatacenters-bv/rhio
- Repository: https://github.com/hiro-microdatacenters-bv/rhio

## Overview

##### Main components
- rhio core process: This is the central daemon that coordinates message routing and file syncing.
- rhio-operator: Acts as the Kubernetes operator managing CRDs and reconciliations for rhio services.
- NATS Server / JetStream: Acts as the messaging backbone for receiving and broadcasting messages.
- MinIO (or any S3-compatible store): Represents the external persistent objects storage for replicated files.
- HTTP API server (rhio-http-api): Supports health endpoints and status/control operations.
- Supporting libraries/crates:
- rhio-blobs: Handles the bao file encoding/decoding and file operations.
- rhio-config and rhio-core: Manage configuration and shared core types, such as message formats.
- Auxiliary components: Other tooling like s3-server for internal testing or simulation might be shown optionally.

##### Relationships and interactions
- The rhio process listens on a configured port and interacts with both internal cluster communications (via NATS) and external p2p messaging (via p2panda).
- It receives messages published to NATS (or JetStream), processes and routes them to other nodes.
- For file transfers, the process interacts with a local S3 bucket (MinIO) after encoding file content using bao and announces file availability over the network.
- The operator components (rhio-operator) would be shown managing configuration, CRDs, and deploying updates/fixtures within the Kubernetes cluster.
- A clear separation should be represented between external cluster messaging and internal file replication.
- Optionally, indicate how environment configurations, Helm charts, and ArgoCD overlays are used for deployment management.

##### Important architectural patterns and design principles
- Modular microservice design, achieved by splitting functionality into multiple Rust crates.
- Operator pattern for Kubernetes integration.
- P2P messaging and decentralized file distribution, emphasizing separation of concerns (message routing vs. file replication).
- Usage of standard configuration management practices (YAML-based configs, environment overlays, Helm charts).

##### Relevant technologies and frameworks
- Programming language: Rust (with multiple Cargo projects).
- Message queue: NATS Server with JetStream.
- Object storage: MinIO (or any S3-compatible system).
- Bao encoding for file handling.
- Kubernetes for deployment: Helm charts, ArgoCD applications, and CRDs via the rhio-operator.
- p2panda for decentralized messaging.

## Diagram (Mermaid)

```mermaid
graph TD
    %% External Systems
    subgraph "External Systems"
        A["NATS Server (JetStream)"]:::external
        B["MinIO Object Store"]:::storage
        C["S3-Server (Auxiliary)"]:::storage
    end

    %% Core Services
    subgraph "Core Services"
        D["rhio Core Process"]:::process
        E["HTTP API Server"]:::process
        subgraph "Shared Libraries"
            F["rhio-blobs"]:::lib
            G["rhio-config"]:::lib
            H["rhio-core"]:::lib
            K["NATS Integration"]:::lib
        end
    end

    %% Management Layer
    subgraph "Management"
        I["rhio Operator"]:::operator
        J["Kubernetes Cluster"]:::operator
    end

    %% Relationships
    A -->|"messages"| D
    F -->|"supports"| D
    G -->|"config"| D
    H -->|"core_types"| D
    K -->|"messaging"| D
    D <-->|"status_control"| E
    D -->|"file-sync"| B
    C -->|"testing"| D

    I -->|"manages"| J
    J -->|"deploys"| D
    J -->|"deploys"| E
    I -->|"oversees"| D

    %% Styles
    classDef external fill:#c3f0ca,stroke:#2d7a2d,stroke-width:2px;
    classDef process fill:#a8d8ea,stroke:#0077b6,stroke-width:2px;
    classDef storage fill:#ffcc80,stroke:#fb8c00,stroke-width:2px;
    classDef operator fill:#f8bbd0,stroke:#d81b60,stroke-width:2px;
    classDef lib fill:#e0e0e0,stroke:#9e9e9e,stroke-width:2px;

    %% Click Events
    click D "https://github.com/hiro-microdatacenters-bv/rhio/blob/main/rhio/src/main.rs"
    click I "https://github.com/hiro-microdatacenters-bv/rhio/blob/main/rhio-operator/src/main.rs"
    click A "https://github.com/hiro-microdatacenters-bv/rhio/tree/main/env/dev/apps/nats"
    click B "https://github.com/hiro-microdatacenters-bv/rhio/tree/main/env/dev/apps/minio"
    click E "https://github.com/hiro-microdatacenters-bv/rhio/blob/main/rhio-http-api/src/server.rs"
    click F "https://github.com/hiro-microdatacenters-bv/rhio/tree/main/rhio-blobs/"
    click G "https://github.com/hiro-microdatacenters-bv/rhio/tree/main/rhio-config/"
    click H "https://github.com/hiro-microdatacenters-bv/rhio/tree/main/rhio-core/"
    click K "https://github.com/hiro-microdatacenters-bv/rhio/blob/main/rhio-core/src/nats.rs"
    click C "https://github.com/hiro-microdatacenters-bv/rhio/tree/main/s3-server/"
```
