# tkthdev/myrabia architecture

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

- Interactive diagram: https://gitdiagram.com/tkthdev/myrabia
- Repository: https://github.com/tkthdev/myrabia

## Overview

##### Main Components
- Client Components – There are several client-related files and scripts (e.g., Client.sh, GClient directory, and the client directory). These represent the entry points where external requests originate.
- Proxy – The “proxy” directory (including its go.mod, proxy.go, and proxy executable) signifies a component acting as an intermediary between clients and replicas.
- Replica – The “replica” directory is central to the implementation. It contains multiple specific files (PriorityQueue.go, RoundOne.go, RoundTwo.go, command.go, data.go, exchangeStage.go, etc.) that imply different phases of the replication process. The presence of logs and setup scripts further indicates that replicas are responsible for state coordination, log management, and the protocol’s multi-stage processing.
- Supporting Scripts – Shell scripts (e.g., Proxy.sh, Replica.sh, Client.sh) provide additional orchestration support.

##### Understand Relationships and Interactions
- Clients issue requests that enter the system through dedicated client scripts/applications.
- The proxy component (if used in the deployment) intermediates these requests and may route them to the appropriate replica nodes.
- Replicas collaborate to execute the Rabia protocol: they go through different “rounds” (as indicated by RoundOne.go and RoundTwo.go) and a phase of data exchange (exchangeStage.go) to reach consensus or update the state.
- Logging and diagnostics (logs folder under the replica directory) play a key role in monitoring state transitions and protocol events.
- The plotting tools possibly provide a feedback mechanism for performance evaluation or debugging of the protocol’s behavior.

##### Architectural Patterns and Design Principles
- Distributed Coordination – The protocol involves multiple rounds of message passing and decision making across replicas.
- Modularity – The clear physical separation (via directories like client, proxy, replica, and plot) is a good indicator of modular design. Each module/component encapsulates specific responsibilities.
- Multi-phase Processing – The different “round” files under replica demonstrate staged processing, where each phase (e.g., Round One then Round Two) performs a part of the consensus or state replication process.
- Logging and Monitoring – The dedicated logs directory underscores the importance of operational transparency and debugging in distributed systems.

- Use clear labels for each component (“Client”, “Proxy”, “Replica [Round One]”, “Replica [Round Two]”, “Data Exchange”, “Logger/Monitor”, etc.) to ensure clarity.
- Interactions with brief text describing the purpose (e.g., “client request”, “protocol message: round initiation”, “consensus response”, “state update”, etc.).
- Where applicable, note the underlying technologies (e.g., Go in the client/proxy/replica components, Python for plotting) to give context.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        ClientShell["Client.sh"]:::clientStyle
        subgraph "GClient"
            GClientGo["GClient.go"]:::clientStyle
            GClientHeader["header.go"]:::clientStyle
            GClientScript["script.sh"]:::clientStyle
        end
        subgraph "Client App"
            ClientGo["client.go"]:::clientStyle
            ClientBinary["client"]:::clientStyle
            ClientMod["go.mod"]:::clientStyle
            ClientAppHeader["header.go"]:::clientStyle
        end
    end

    %% Proxy Layer
    subgraph "Proxy Layer"
        ProxyMain["Proxy"]:::proxyStyle
        subgraph "Proxy Files"
            ProxyGo["proxy.go"]:::proxyStyle
            ProxyBinary["proxy"]:::proxyStyle
            ProxyMod["go.mod"]:::proxyStyle
        end
        ProxyScript["Proxy.sh"]:::proxyStyle
    end

    %% Replica Layer
    subgraph "Replica Layer"
        subgraph "Replica Core"
            ReplicaSetup["Setup"]:::replicaStyle
            RoundOne["Round One"]:::replicaStyle
            RoundTwo["Round Two"]:::replicaStyle
            DataExchange["Data Exchange"]:::replicaStyle
            Command["Command"]:::replicaStyle
            DataComp["Data"]:::replicaStyle
            PriorityQueue["Priority Queue"]:::replicaStyle
            ReplicaCore["Replica Core"]:::replicaStyle
        end
        subgraph "Replica Logs"
            LogsDir["Logs Directory"]:::replicaStyle
            Log1["log.txt"]:::replicaStyle
            Log2["log1.txt"]:::replicaStyle
            Log3["log2.txt"]:::replicaStyle
            Log4["log3.txt"]:::replicaStyle
        end
        ReplicaScript["Replica.sh"]:::replicaStyle
    end

    %% Visualization Layer
    subgraph "Visualization"
        PPPlot["PPPlot.py"]:::plotStyle
        PlotPy["plot.py"]:::plotStyle
    end

    %% Connections between Layers
    ClientShell -->|"clientRequest"| ProxyMain
    ProxyMain -->|"forwardsRequest"| ReplicaSetup
    ReplicaSetup -->|"initiateRound"| RoundOne
    RoundOne -->|"processRound"| RoundTwo
    RoundTwo -->|"exchangeData"| DataExchange
    DataExchange -->|"logOutcome"| LogsDir
    LogsDir -->|"visualize"| PPPlot

    %% Additional orchestration links
    ReplicaScript ---|"orchestrates"| ReplicaSetup

    %% Class styles
    classDef clientStyle fill:#FAD4D8,stroke:#D14,stroke-width:2px;
    classDef proxyStyle fill:#D4E4FA,stroke:#147,stroke-width:2px;
    classDef replicaStyle fill:#D4FAD4,stroke:#4A7,stroke-width:2px;
    classDef plotStyle fill:#FAEDC4,stroke:#AA6,stroke-width:2px;

click ClientShell "https://github.com/tkthdev/myrabia/blob/main/Client.sh"
click GClientGo "https://github.com/tkthdev/myrabia/blob/main/GClient/GClient.go"
click GClientHeader "https://github.com/tkthdev/myrabia/blob/main/GClient/header.go"
click GClientScript "https://github.com/tkthdev/myrabia/blob/main/GClient/script.sh"
click ClientGo "https://github.com/tkthdev/myrabia/blob/main/client/client.go"
click ClientBinary "https://github.com/tkthdev/myrabia/tree/main/client/client"
click ClientMod "https://github.com/tkthdev/myrabia/blob/main/client/go.mod"
click ClientAppHeader "https://github.com/tkthdev/myrabia/blob/main/client/header.go"

click ProxyGo "https://github.com/tkthdev/myrabia/blob/main/proxy/proxy.go"
click ProxyBinary "https://github.com/tkthdev/myrabia/tree/main/proxy/proxy"
click ProxyMod "https://github.com/tkthdev/myrabia/blob/main/proxy/go.mod"
click ProxyScript "https://github.com/tkthdev/myrabia/blob/main/Proxy.sh"

click ReplicaSetup "https://github.com/tkthdev/myrabia/blob/main/replica/setup.go"
click RoundOne "https://github.com/tkthdev/myrabia/blob/main/replica/RoundOne.go"
click RoundTwo "https://github.com/tkthdev/myrabia/blob/main/replica/RoundTwo.go"
click DataExchange "https://github.com/tkthdev/myrabia/blob/main/replica/exchangeStage.go"
click Command "https://github.com/tkthdev/myrabia/blob/main/replica/command.go"
click DataComp "https://github.com/tkthdev/myrabia/blob/main/replica/data.go"
click PriorityQueue "https://github.com/tkthdev/myrabia/blob/main/replica/PriorityQueue.go"
click ReplicaCore "https://github.com/tkthdev/myrabia/blob/main/replica/replica.go"
click LogsDir "https://github.com/tkthdev/myrabia/tree/main/replica/logs"
click Log1 "https://github.com/tkthdev/myrabia/blob/main/replica/logs/log.txt"
click Log2 "https://github.com/tkthdev/myrabia/blob/main/replica/logs/log1.txt"
click Log3 "https://github.com/tkthdev/myrabia/blob/main/replica/logs/log2.txt"
click Log4 "https://github.com/tkthdev/myrabia/blob/main/replica/logs/log3.txt"
click ReplicaScript "https://github.com/tkthdev/myrabia/blob/main/Replica.sh"

click PPPlot "https://github.com/tkthdev/myrabia/blob/main/plot/PPPlot.py"
click PlotPy "https://github.com/tkthdev/myrabia/blob/main/plot/plot.py"
```
