# vkanaparthy/loadbalancer architecture

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

- Interactive diagram: https://gitdiagram.com/vkanaparthy/loadbalancer
- Repository: https://github.com/vkanaparthy/loadbalancer

## Overview

##### Project type and purpose
- This is a small L4 load-balancer project (“loadbalancer”) that implements both a control plane (configuration via an API server) and a data plane (packet forwarding in Go).
- The README says only “L4 loadbalancer,” and the files show Python for the API/client side and Go for the core balancing logic.

##### File structure
- Top‐level files:
- apiserver.py – Python service exposing REST endpoints to add/remove backends or change strategy
- client.py   – Python CLI or interactive client to call the API server
- main.go     – Go entry point: starts the L4 proxy listener and dispatch loop
- strategy.go – Go code implementing various load-balancing algorithms (e.g., round robin)
- go.mod, go.sum – Go module definitions/configuration
- No separate “frontend”/“backend” folders; instead the control plane is in Python and the data plane in Go.

##### README for additional insights
- Very terse; implies that the core is the L4 proxy and that configuration is dynamic.

##### Detail
- Strategy module to show that it implements an interface (e.g., “SelectNextBackend()”).
- Concurrency in main.go (e.g., Go routines listening per connection).
- Module boundaries: Python side can be independently tested or extended without touching Go code.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External entities
    ExtClient["External Clients"]:::external
    BackendServers["Backend Servers"]:::external

    %% Control Plane
    subgraph "Control Plane (Python)"
        direction TB
        Client["Client (client.py)"]:::python
        APIServer["API Server (apiserver.py)"]:::python
    end

    %% Data Plane
    subgraph "Data Plane (Go)"
        direction TB
        LBCore["LB Core (main.go)"]:::go
        Strategy["Strategy Module (strategy.go)"]:::go
        GoMod["go.mod"]:::go
        GoSum["go.sum"]:::go
    end

    %% Documentation
    Doc["README.md"]:::doc

    %% Connections
    ExtClient -->|"TCP/UDP traffic"| LBCore
    Client -->|"REST API"| APIServer
    APIServer -->|"Config update (HTTP/JSON)"| LBCore
    LBCore -->|"Forwarded traffic"| BackendServers
    LBCore -->|"requests next backend"| Strategy
    Strategy -->|"returns backend"| LBCore

    %% Click Events
    click Client "https://github.com/vkanaparthy/loadbalancer/blob/main/client.py"
    click APIServer "https://github.com/vkanaparthy/loadbalancer/blob/main/apiserver.py"
    click LBCore "https://github.com/vkanaparthy/loadbalancer/blob/main/main.go"
    click Strategy "https://github.com/vkanaparthy/loadbalancer/blob/main/strategy.go"
    click GoMod "https://github.com/vkanaparthy/loadbalancer/blob/main/go.mod"
    click GoSum "https://github.com/vkanaparthy/loadbalancer/blob/main/go.sum"
    click Doc "https://github.com/vkanaparthy/loadbalancer/blob/main/README.md"

    %% Styles
    classDef python fill:#D0E1FF,stroke:#0366d6,color:#0366d6
    classDef go fill:#DFF8E1,stroke:#2e8b57,color:#2e8b57
    classDef external fill:#FFEFD5,stroke:#CD853F,color:#8B4513
    classDef doc fill:#F0F0F0,stroke:#A9A9A9,color:#555555
```
