# chyavanrao7/reverse_proxy architecture

> Architecture diagram of the GitHub repository chyavanrao7/reverse_proxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-02-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chyavanrao7/reverse_proxy
- Repository: https://github.com/chyavanrao7/reverse_proxy

## Overview

##### Project type and purpose
- This is a small, Java-based reverse proxy / load balancer demonstration project.
- It includes two main subsystems:
a. A TCP/HTTP load balancer (round-robin)
b. Multiple simple HTTP backend servers

##### File structure
- Top-level:
- LICENSE, README.md, docker-compose.yaml
- backend/ – Java HTTP backend server + Dockerfile
- loadbalancer/ – Java load balancer code
- The presence of Dockerfiles and docker-compose.yaml shows containerization and network orchestration

##### Key insights from the README
- Load balancer listens on port 8888, forwards to backends on configurable ports
- Uses java.net.ServerSocket/Socket, multithreading (2 threads per connection), round-robin
- Backends respond with simple HTML indicating their port

##### Main components
a. Client (e.g., curl or browser)
b. Load Balancer (Java process or container)
c. HTTP Backend Servers (3 instances of HttpBackendServer)
d. Docker Network (reverse_net) – optional boundary if containerized
e. Host or VM

##### Relationships & interactions
- Client → Load Balancer (TCP connection on port 8888)
- Load Balancer → Backend Servers (round-robin, TCP connections to ports 9001, 9002, 9003)
- Bidirectional data flow on each connection (two dedicated threads)
- Docker network interconnects containers by hostname

##### Architectural patterns & principles
- Reverse proxy / load balancer pattern
- Round-robin scheduling algorithm
- Thread-per-connection (uses ExecutorService)
- Containerized deployment (Docker, docker-compose)

##### Technologies & frameworks
- Java 17, java.net sockets
- Docker (Dockerfile in each service, docker-compose.yaml)
- Multithreading (Threads, ExecutorService)

##### Detail without overthinking
- Services (LB, each backend), network boundaries (host vs container), data flows, config files
- Use as many distinct components as exist in the repo (docker-compose, Dockerfiles, Java classes)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (curl/browser)"]:::external

    subgraph "reverse_net (Docker)"
        direction TB

        subgraph "Load Balancer Container"
            direction TB
            LBProc["Load Balancer\nPort 8888\n(Round-Robin,\nExecutorService)"]:::service
            LBApp["lb.java"]:::code
            LBDocker["Dockerfile"]:::file
        end

        subgraph "Backend Servers (3 instances)"
            direction TB
            BE1["HTTP Backend\nPort 9001"]:::service
            BE2["HTTP Backend\nPort 9002"]:::service
            BE3["HTTP Backend\nPort 9003"]:::service
            BECode["server.java"]:::code
            BEDocker["Dockerfile"]:::file
        end
    end

    Client -->|TCP:8888| LBProc
    LBProc -->|TCP:9001| BE1
    LBProc -->|TCP:9002| BE2
    LBProc -->|TCP:9003| BE3
    BE1 -->|Response| LBProc
    BE2 -->|Response| LBProc
    BE3 -->|Response| LBProc
    LBProc -->|Response| Client

    docCompose["docker-compose.yaml"]:::file
    docs["README.md / LICENSE"]:::file

    docCompose -.->|orchestrates| LBProc
    docCompose -.->|orchestrates| BE1
    docs -.->|documentation| Client

    click LBApp "https://github.com/chyavanrao7/reverse_proxy/blob/main/loadbalancer/lb.java"
    click LBDocker "https://github.com/chyavanrao7/reverse_proxy/tree/main/loadbalancer/dockerfile"
    click BECode "https://github.com/chyavanrao7/reverse_proxy/blob/main/backend/server.java"
    click BEDocker "https://github.com/chyavanrao7/reverse_proxy/tree/main/backend/Dockerfile"
    click docCompose "https://github.com/chyavanrao7/reverse_proxy/blob/main/docker-compose.yaml"
    click docs "https://github.com/chyavanrao7/reverse_proxy/blob/main/README.md"
    click docs "https://github.com/chyavanrao7/reverse_proxy/tree/main/LICENSE"

    classDef external fill:#bbf,stroke:#f66,stroke-width:2px
    classDef service fill:#bfb,stroke:#393,stroke-width:2px
    classDef code fill:#ff9,stroke:#c93,stroke-width:2px
    classDef file fill:#9cf,stroke:#39f,stroke-width:2px
    classDef annotation fill:#fff,stroke:#aaa,stroke-dasharray:5,5
```
