# sireax/rhosus architecture

> Architecture diagram of the GitHub repository sireax/rhosus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sireax/rhosus
- Repository: https://github.com/sireax/rhosus

## Overview

##### Main Components Identification

a) Registry Service (rhosusr)
- This is the brain of the system
- Handles decision-making for block storage
- Manages service discovery
- Handles API requests

b) Data Nodes (rhosusd)
- Responsible for raw block storage
- Multiple instances possible

c) External Dependencies
- etcd for service discovery
- BoltDB for memory-based storage backup

##### Component Relationships

a) Client Layer
- CLI tool (rhosus) at the top
- It to the Registry Service via API calls

b) Registry Layer
- Internal components:
- API Server (api/)
- Authentication System (auth/)
- Cluster Management (registry/cluster/)
- Storage Management (registry/storage/)
- Write-Ahead Log (registry/wal/)

c) Data Layer
- Data Nodes at the bottom
- Their internal components:
- Data Management (node/data/)
- Partitioning System
- gRPC Server

##### Communication Flows

- gRPC communications between components
- HTTP/REST API calls from clients
- etcd service discovery interactions
- Data flow between Registry and Data Nodes

##### Specific Implementation Details

Technical elements:
- API endpoint (port 8001)
- Cluster communication (port 8401)
- Data Node service (port 4500)
- etcd connection (port 2379)

##### Additional Elements

- Authentication flow
- File storage policy management
- Cluster management
- Data partitioning strategy

##### Architectural Patterns to Highlight

Emphasize:
- Distributed architecture pattern
- Service discovery mechanism
- Write-ahead logging
- Authentication and authorization flow

##### Side Layer: External Services

- All component types
- Communication protocols
- Port numbers
- Storage mechanisms

Keep the abstraction level high enough to show the overall architecture but detailed enough to understand the core components and their interactions. Focus on showing how the system handles distributed file storage and maintains consistency across nodes.

Remember to indicate scalability aspects, showing how multiple data nodes can be added and how the registry manages them through etcd service discovery.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        CLI["CLI Tool (rhosus)"]:::client
        click CLI "https://github.com/Sireax/rhosus/blob/master/cmd/rhosus/main.go"
    end

    subgraph "Registry Service"
        RS["Registry Service (rhosusr)"]:::core
        click RS "https://github.com/Sireax/rhosus/blob/master/cmd/rhosusr/main.go"

        subgraph "Registry Components"
            API["API Server"]:::component
            click API "https://github.com/Sireax/rhosus/blob/master/rhosus/api/api.go"
            AUTH["Authentication System"]:::component
            click AUTH "https://github.com/Sireax/rhosus/blob/master/rhosus/auth/auth.go"
            CM["Cluster Management"]:::component
            click CM "https://github.com/Sireax/rhosus/blob/master/rhosus/registry/cluster/cluster.go"
            SM["Storage Management"]:::component
            click SM "https://github.com/Sireax/rhosus/blob/master/rhosus/registry/storage/storage.go"
            WAL["Write-Ahead Log"]:::component
            click WAL "https://github.com/Sireax/rhosus/blob/master/rhosus/registry/wal/wal.go"
            FSP["File Storage Policy"]:::component
            click FSP "https://github.com/Sireax/rhosus/blob/master/rhosus/registry/policy.go"
            NM["Node Management"]:::component
            click NM "https://github.com/Sireax/rhosus/blob/master/rhosus/registry/nodes_map.go"
        end
    end

    subgraph "Data Layer"
        DN1["Data Node 1"]:::datanode
        DN2["Data Node 2"]:::datanode
        click DN1 "https://github.com/Sireax/rhosus/blob/master/cmd/rhosusd/main.go"
        click DN2 "https://github.com/Sireax/rhosus/blob/master/cmd/rhosusd/main.go"

        subgraph "Data Node Components"
            DM["Data Management"]:::component
            click DM "https://github.com/Sireax/rhosus/blob/master/rhosus/node/data/data.go"
            PS["Partitioning System"]:::component
            click PS "https://github.com/Sireax/rhosus/blob/master/rhosus/node/data/partition.go"
            GRPC["gRPC Server"]:::component
            click GRPC "https://github.com/Sireax/rhosus/blob/master/rhosus/node/grpc_server.go"
        end
    end

    subgraph "External Services"
        ETCD["etcd Service Discovery"]:::external
        click ETCD "https://github.com/Sireax/rhosus/blob/master/rhosus/etcd/client.go"
        BOLTDB["BoltDB Storage"]:::external
        PB["Protocol Buffers"]:::external
        click PB "https://github.com/Sireax/rhosus/tree/master/rhosus/pb/"
    end

    %% Connections
    CLI -->|"HTTP API (8001)"| API
    API --> AUTH
    API --> CM
    API --> SM
    SM --> WAL
    SM --> FSP
    CM --> NM
    CM -->|"Cluster Comm (8401)"| DN1
    CM -->|"Cluster Comm (8401)"| DN2
    NM --> ETCD
    DN1 --> DM
    DN2 --> DM
    DM --> PS
    DM --> GRPC
    RS -->|"Service Discovery (2379)"| ETCD
    DN1 -->|"Data Storage"| BOLTDB
    DN2 -->|"Data Storage"| BOLTDB

    %% Styles
    classDef core fill:#2374ab,stroke:#000,stroke-width:2px,color:#fff
    classDef component fill:#4a90e2,stroke:#000,stroke-width:1px,color:#fff
    classDef datanode fill:#47b39c,stroke:#000,stroke-width:2px,color:#fff
    classDef external fill:#ffa500,stroke:#000,stroke-width:1px,color:#fff
    classDef client fill:#6c757d,stroke:#000,stroke-width:1px,color:#fff

    %% Legend
    subgraph Legend
        L1["Core Service"]:::core
        L2["Component"]:::component
        L3["Data Node"]:::datanode
        L4["External Service"]:::external
        L5["Client"]:::client
    end
```
