# arps18/key-value_rpc architecture

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

- Interactive diagram: https://gitdiagram.com/arps18/key-value_rpc
- Repository: https://github.com/arps18/key-value_rpc

## Overview

##### Main Components
- Server:
- Represents the multi-threaded key-value store.
- Handles client connections and RPC calls.
- Manages concurrency using mutual exclusion (threads, locks, etc.).
- Clients:
- Client (Client.java) and Client_B (Client_B.java) – both act as separate instances that initiate remote calls.
- Remote Interface:
- Defined in RemoteInterface.java – specifies the RPC methods implemented by the server and invoked by clients.
- Key-Value Store Component:
- Although not explicitly shown as a separate module, it is an internal component within the server responsible for storing and managing key-value pairs.

##### Relationships and Interactions
- The Server acts as a central node that listens on a particular host address and port.
- Both Client and Client_B connect to the Server using RPC semantics defined by the Remote Interface.
- Clients send operations (PUT, GET, DELETE) to the Server, and responses are sent back as a result of these calls.
- The Server handles concurrent requests from multiple clients, ensuring thread safety during operations on the key-value store.

##### Architectural Patterns/Design Principles
- Multi-threading: The Server component should illustrate that it is capable of handling multiple threads concurrently (e.g., a thread pool or individual thread handlers).
- Concurrency Control: Use symbols to indicate where mutual exclusion (mutex/locks) is applied within the server for safe access to the key-value store.
- Modularity: Even though the project is small, clearly separate the components (Server, Clients, Remote Interface) to show logical layers.

##### Relevant Technologies and Libraries
- Java (JDK 8 or later)
- Built-in Java libraries for networking and threading (e.g., java.net, java.util.concurrent)
- RPC mechanism as implemented via custom RemoteInterface (and any underlying socket programming)

##### Elements
- UI/client components (Client and Client_B)
- Core business/server processing (Server and its thread management)
- Interface/communication layer (Remote Interface)
- Internal state storage (key-value store)

- The role of the Server as both an RPC endpoint and a multi-threaded processor.
- The connection between Clients (Client and Client_B) and the Server via the Remote Interface.
- The internal handling of the key-value store within the server with proper thread safety.

This detailed layout will assist in understanding how each part of the system interacts, ensuring that all architectural elements derived from the file tree and README are accurately represented.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        C1["Client"]:::client
        C2["Client_B"]:::client
    end

    %% Interface Layer
    subgraph "Interface Layer"
        RI["Remote Interface"]:::interface
    end

    %% Server Side
    subgraph "Server Side"
        S["Server"]:::server
        TM["Thread Manager"]:::serverInternal
        KV["((Key-Value Store))"]:::kvStore
    end

    %% Connections: Request Flow
    C1 -->|"RPC_Call"| RI
    C2 -->|"RPC_Call"| RI
    RI -->|"RPC_Invocation"| S

    %% Connections: Server Internal Process
    S -->|"Manages_Threads"| TM
    S -->|"Handles_Operations"| KV
    TM -->|"Controls_Access"| KV

    %% Connections: Response Flow
    S -->|"Response"| RI
    RI -->|"Response_Delivery"| C1
    RI -->|"Response_Delivery"| C2

    %% Click Events
    click S "https://github.com/arps18/key-value_rpc/blob/main/src/Server.java"
    click C1 "https://github.com/arps18/key-value_rpc/blob/main/src/Client.java"
    click C2 "https://github.com/arps18/key-value_rpc/blob/main/src/Client_B.java"
    click RI "https://github.com/arps18/key-value_rpc/blob/main/src/RemoteInterface.java"

    %% Styles
    classDef client fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef interface fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef server fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef serverInternal fill:#ffe6cc,stroke:#333,stroke-width:2px;
    classDef kvStore fill:#f8d7da,stroke:#333,stroke-width:2px;
```
