# dishatimbadiya/loadbalancer architecture

> Architecture diagram of the GitHub repository dishatimbadiya/loadbalancer, 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/dishatimbadiya/loadbalancer
- Repository: https://github.com/dishatimbadiya/loadbalancer

## Overview

##### Main Components
- Client/Request Simulator – This is the part of the system generating requests that will be balanced.
- Load Balancer Modules – There are separate implementations for each algorithm:
- Round Robin (both one-thread and multi-thread variants)
- Weighted Round Robin
- Least Connections
- (Hash-Based Algorithm – even if not represented directly by its own folder, it is part of the conceptual framework.)
- Server Simulation – Each algorithm has a “Server.java” class that likely simulates the behavior of individual servers receiving the requests.
- Main Driver/Application Entry – Each package has a “Main.java” that likely sets up the simulation and prompts for input.
- (Optional) UI/Visualization Components – The images in “Load_balance_images” indicate there is visual documentation that might also be integrated into the simulation flow.

##### Establish Relationships and Data Flow
- The Main Driver initializes the simulation by capturing user input (such as the number of servers and requests).
- The client simulator generates the stream of requests.
- These requests are sent to the selected load balancing algorithm module (shown as separate components).
- Within each module, the load balancer component analyzes the incoming requests and distributes them to the available Server components.
- There is communication from the load balancer back to the simulation engine, which might update the UI or provide simulation feedback (especially useful for educational and interactive purposes).

##### Architectural Patterns
- Modular Design – Each algorithm is isolated into its own package/module (e.g., RoundRobin_MultiThread, RoundRobin_OneThread, WeightedRoundRobin, and LeastConnections). This reflects a strategy where each load balancing algorithm is a self-contained component.
- Simulation/Interactive Flow – The system is designed to prompt users and simulate real-time request handling.
- Possibly MVC-like – Although not explicitly a web application, the separation of simulation (control logic), algorithm modules (model/business logic), and visual aids (view layer) can be noted.

##### Relevant Technologies and Frameworks
- Java – Core language; important to indicate that the entire system is built with Java.
- Version control (Git) is used but it’s not directly part of the runtime architecture.

##### Elements
- Clear labels on each block:
- “Client/Request Generator”
- “Load Balancer – Round Robin (One Thread)”
- “Load Balancer – Round Robin (Multi-Thread)”
- “Load Balancer – Weighted Round Robin”
- “Load Balancer – Least Connections”
- “(Load Balancer – Hash-Based)” – if needed, drawn as a conceptual component.
- “Server Simulation”
- Feedback paths where the simulation might acknowledge processed requests.
- Optionally, include annotations such as “multi-threaded” where applicable (for example, inside the Round Robin component).

Happy diagramming!

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Simulation Components
    A["Main/Simulation Controller"]:::sim
    B["Client/Request Generator"]:::sim
    UI["UI/Visualization Documentation"]:::ui

    A -->|"initiates"| B
    A ---|"references"| UI

    %% Connections from Client Simulator to Load Balancer Modules
    B -->|"sendsRequest"| RRO1
    B -->|"sendsRequest"| RRM1
    B -->|"sendsRequest"| WRR1
    B -->|"sendsRequest"| LC1

    %% Round Robin (One Thread) Module
    subgraph "Round Robin (One Thread)"
        RRO1["Main Driver – Round Robin (One Thread)"]:::sim
        RRO2["Load Balancer – Round Robin (One Thread)"]:::alg
        RRO3["Server Simulation – Round Robin (One Thread)"]:::server
        RRO1 -->|"launches"| RRO2
        RRO2 -->|"distributes"| RRO3
    end

    %% Round Robin (Multi-Thread) Module
    subgraph "Round Robin (Multi-Thread)"
        RRM1["Main Driver – Round Robin (Multi-Thread)"]:::sim
        RRM2["Load Balancer – Round Robin (Multi-Thread)"]:::alg
        RRM3["Server Simulation – Round Robin (Multi-Thread)"]:::server
        RRM1 -->|"launches"| RRM2
        RRM2 -->|"distributes"| RRM3
    end

    %% Weighted Round Robin Module
    subgraph "Weighted Round Robin"
        WRR1["Main Driver – Weighted Round Robin"]:::sim
        WRR2["Load Balancer – Weighted Round Robin"]:::alg
        WRR3["Server Simulation – Weighted Round Robin"]:::server
        WRR1 -->|"launches"| WRR2
        WRR2 -->|"distributes"| WRR3
    end

    %% Least Connections Module
    subgraph "Least Connections"
        LC1["Main Driver – Least Connections"]:::sim
        LC2["Load Balancer – Least Connections"]:::alg
        LC3["Server Simulation – Least Connections"]:::server
        LC1 -->|"launches"| LC2
        LC2 -->|"distributes"| LC3
    end

    %% Click Events
    click RRO1 "https://github.com/dishatimbadiya/loadbalancer/blob/main/RoundRobin_OneThread/Main.java"
    click RRO2 "https://github.com/dishatimbadiya/loadbalancer/blob/main/RoundRobin_OneThread/LoadBalancer.java"
    click RRO3 "https://github.com/dishatimbadiya/loadbalancer/blob/main/RoundRobin_OneThread/Server.java"

    click RRM1 "https://github.com/dishatimbadiya/loadbalancer/blob/main/RoundRobin_MultiThread/Main.java"
    click RRM2 "https://github.com/dishatimbadiya/loadbalancer/blob/main/RoundRobin_MultiThread/LoadBalancer.java"
    click RRM3 "https://github.com/dishatimbadiya/loadbalancer/blob/main/RoundRobin_MultiThread/Server.java"

    click WRR1 "https://github.com/dishatimbadiya/loadbalancer/blob/main/WeightedRoundRobin/Main.java"
    click WRR2 "https://github.com/dishatimbadiya/loadbalancer/blob/main/WeightedRoundRobin/LoadBalancer.java"
    click WRR3 "https://github.com/dishatimbadiya/loadbalancer/blob/main/WeightedRoundRobin/Server.java"

    click LC1 "https://github.com/dishatimbadiya/loadbalancer/blob/main/LeastConnections/Main.java"
    click LC2 "https://github.com/dishatimbadiya/loadbalancer/blob/main/LeastConnections/LoadBalancer.java"
    click LC3 "https://github.com/dishatimbadiya/loadbalancer/blob/main/LeastConnections/Server.java"

    click UI "https://github.com/dishatimbadiya/loadbalancer/tree/main/Load_balance_images"

    %% Styles
    classDef sim fill:#CCE5FF,stroke:#333,stroke-width:2px;
    classDef alg fill:#FFFFCC,stroke:#333,stroke-width:2px;
    classDef server fill:#CCFFCC,stroke:#333,stroke-width:2px;
    classDef ui fill:#FFCCCC,stroke:#333,stroke-width:2px;
```
