# abdulrahman-tayara/go-lb architecture

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

- Interactive diagram: https://gitdiagram.com/abdulrahman-tayara/go-lb
- Repository: https://github.com/abdulrahman-tayara/go-lb

## Overview

Go-LB is an HTTP reverse proxy/load balancer. Its main workflow loads JSON/YAML settings, builds a routing strategy and load balancer, optionally wraps it in rate limiting, then accepts requests and proxies them to a selected backend. A background health checker probes configured backend health URLs and updates the load balancer when server status changes. The README also documents content-based routing, TLS, and several balancing algorithms. Edges reflect the shown startup and runtime calls; algorithm wiring beyond the factory call is not expanded where source relationships were not shown.

Main entry points: [`lb/load_balancer.go`](https://github.com/abdulrahman-tayara/go-lb/blob/main/lb/load_balancer.go) (Load balancer), [`main.go`](https://github.com/abdulrahman-tayara/go-lb/blob/main/main.go) (Process startup), [`strategy/factory.go`](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/factory.go) (Strategy factory), [`healthcheck/checker.go`](https://github.com/abdulrahman-tayara/go-lb/blob/main/healthcheck/checker.go) (Health checker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and config"]
  node_config["Config loader<br/>[configs.go]"]
  node_entry["Process startup<br/>[main.go]"]
  node_httpserver["HTTP server<br/>[main.go]"]
end

subgraph group_traffic["Request handling"]
  node_limiter["Rate-limit middleware<br/>[middleware.go]"]
  node_bucket["Token bucket<br/>[limiter.go]"]
  node_bucketstate["Bucket state<br/>[bucket.go]"]
  node_lb["Load balancer<br/>[load_balancer.go]"]
end

subgraph group_algorithms["Balancing algorithms"]
  node_strategyfactory["Strategy factory<br/>[factory.go]"]
  node_strategyinterface["Strategy interface<br/>[strategy.go]"]
  node_roundrobin["Round robin<br/>[round_robin.go]"]
  node_weighted["Weighted round robin"]
  node_least["Least connections"]
  node_random["Random strategy<br/>[random.go]"]
  node_sticky["Sticky sessions<br/>[sticky_session.go]"]
end

subgraph group_health["Health monitoring"]
  node_healthchecker["Health checker<br/>[checker.go]"]
  node_observer["Observer contract<br/>[observer.go]"]
end

subgraph group_domain["Backend and routing models"]
  node_servermodel["Server model<br/>[server.go]"]
  node_routing["Content routing<br/>[routing.go]"]
end

node_client(("HTTP client"))
node_upstream(("Backend servers"))

node_client -->|"sends request"| node_httpserver
node_entry -->|"loads settings"| node_config
node_entry -->|"selects strategy"| node_strategyfactory
node_entry -->|"constructs"| node_lb
node_entry -->|"starts checks"| node_healthchecker
node_entry -->|"optionally wraps"| node_limiter
node_entry -->|"serves handler"| node_httpserver
node_httpserver -->|"dispatches to"| node_limiter
node_limiter -->|"limits by key"| node_bucket
node_limiter -->|"forwards allowed"| node_lb
node_lb -->|"proxies request"| node_upstream
node_lb -->|"selects server"| node_strategyinterface
node_lb -->|"matches rules"| node_routing
node_lb -->|"uses server data"| node_servermodel
node_strategyfactory -.-> node_roundrobin
node_strategyfactory -.-> node_weighted
node_strategyfactory -.-> node_least
node_strategyfactory -.-> node_random
node_strategyfactory -.-> node_sticky
node_healthchecker -.->|"probes health URL"| node_upstream
node_healthchecker -->|"notifies changes"| node_observer
node_healthchecker -->|"updates availability"| node_lb
node_config -->|"decodes servers"| node_servermodel
node_config -->|"decodes routes"| node_routing

click node_config "https://github.com/abdulrahman-tayara/go-lb/blob/main/configs/configs.go"
click node_entry "https://github.com/abdulrahman-tayara/go-lb/blob/main/main.go"
click node_httpserver "https://github.com/abdulrahman-tayara/go-lb/blob/main/main.go"
click node_limiter "https://github.com/abdulrahman-tayara/go-lb/blob/main/ratelimiter/buckettokens/middleware.go"
click node_bucket "https://github.com/abdulrahman-tayara/go-lb/blob/main/ratelimiter/buckettokens/limiter.go"
click node_bucketstate "https://github.com/abdulrahman-tayara/go-lb/blob/main/ratelimiter/buckettokens/bucket.go"
click node_lb "https://github.com/abdulrahman-tayara/go-lb/blob/main/lb/load_balancer.go"
click node_strategyfactory "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/factory.go"
click node_strategyinterface "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/strategy.go"
click node_roundrobin "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/round_robin.go"
click node_weighted "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/weighted_round_robin.go"
click node_least "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/least_connections.go"
click node_random "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/random.go"
click node_sticky "https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/sticky_session.go"
click node_healthchecker "https://github.com/abdulrahman-tayara/go-lb/blob/main/healthcheck/checker.go"
click node_observer "https://github.com/abdulrahman-tayara/go-lb/blob/main/healthcheck/observer.go"
click node_servermodel "https://github.com/abdulrahman-tayara/go-lb/blob/main/models/server.go"
click node_routing "https://github.com/abdulrahman-tayara/go-lb/blob/main/models/routing.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_config,node_entry,node_httpserver,node_client toneBlue
class node_limiter,node_bucket,node_bucketstate,node_lb toneAmber
class node_strategyfactory,node_strategyinterface,node_roundrobin,node_weighted,node_least,node_random,node_sticky,node_upstream toneMint
class node_healthchecker,node_observer toneRose
class node_servermodel,node_routing toneIndigo
```

## Components

### Startup and config

- [Config loader](https://github.com/abdulrahman-tayara/go-lb/blob/main/configs/configs.go): `configs/configs.go`
- [Process startup](https://github.com/abdulrahman-tayara/go-lb/blob/main/main.go): `main.go`
- [HTTP server](https://github.com/abdulrahman-tayara/go-lb/blob/main/main.go): `main.go`

### Request handling

- [Rate-limit middleware](https://github.com/abdulrahman-tayara/go-lb/blob/main/ratelimiter/buckettokens/middleware.go): `ratelimiter/buckettokens/middleware.go`
- [Token bucket](https://github.com/abdulrahman-tayara/go-lb/blob/main/ratelimiter/buckettokens/limiter.go): `ratelimiter/buckettokens/limiter.go`
- [Bucket state](https://github.com/abdulrahman-tayara/go-lb/blob/main/ratelimiter/buckettokens/bucket.go): `ratelimiter/buckettokens/bucket.go`
- [Load balancer](https://github.com/abdulrahman-tayara/go-lb/blob/main/lb/load_balancer.go): `lb/load_balancer.go`

### Balancing algorithms

- [Strategy factory](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/factory.go): `strategy/factory.go`
- [Strategy interface](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/strategy.go): `strategy/strategy.go`
- [Round robin](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/round_robin.go): `strategy/round_robin.go`
- [Weighted round robin](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/weighted_round_robin.go): `strategy/weighted_round_robin.go`
- [Least connections](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/least_connections.go): `strategy/least_connections.go`
- [Random strategy](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/random.go): `strategy/random.go`
- [Sticky sessions](https://github.com/abdulrahman-tayara/go-lb/blob/main/strategy/sticky_session.go): `strategy/sticky_session.go`

### Health monitoring

- [Health checker](https://github.com/abdulrahman-tayara/go-lb/blob/main/healthcheck/checker.go): `healthcheck/checker.go`
- [Observer contract](https://github.com/abdulrahman-tayara/go-lb/blob/main/healthcheck/observer.go): `healthcheck/observer.go`

### Backend and routing models

- [Server model](https://github.com/abdulrahman-tayara/go-lb/blob/main/models/server.go): `models/server.go`
- [Content routing](https://github.com/abdulrahman-tayara/go-lb/blob/main/models/routing.go): `models/routing.go`

### Other components

- **HTTP client**
- **Backend servers**

## Connections

- HTTP client → HTTP server: sends request (evidence: `main.go`)
- Process startup → Config loader: loads settings (evidence: `main.go`)
- Process startup → Strategy factory: selects strategy (evidence: `main.go`)
- Process startup → Load balancer: constructs (evidence: `main.go`)
- Process startup → Health checker: starts checks (evidence: `main.go`)
- Process startup → Rate-limit middleware: optionally wraps (evidence: `main.go`)
- Process startup → HTTP server: serves handler (evidence: `main.go`)
- HTTP server → Rate-limit middleware: dispatches to (evidence: `main.go`)
- Rate-limit middleware → Token bucket: limits by key (evidence: `ratelimiter/buckettokens/middleware.go`)
- Rate-limit middleware → Load balancer: forwards allowed (evidence: `ratelimiter/buckettokens/middleware.go`)
- Load balancer → Backend servers: proxies request (evidence: `lb/load_balancer.go`)
- Load balancer → Strategy interface: selects server (evidence: `lb/load_balancer.go`)
- Load balancer → Content routing: matches rules (evidence: `lb/load_balancer.go`)
- Load balancer → Server model: uses server data (evidence: `lb/load_balancer.go`)
- Strategy factory → Round robin
- Strategy factory → Weighted round robin
- Strategy factory → Least connections
- Strategy factory → Random strategy
- Strategy factory → Sticky sessions
- Health checker → Backend servers: probes health URL (evidence: `README.md`)
- Health checker → Observer contract: notifies changes (evidence: `healthcheck/checker.go`)
- Health checker → Load balancer: updates availability
- Config loader → Server model: decodes servers (evidence: `configs/configs.go`)
- Config loader → Content routing: decodes routes (evidence: `configs/configs.go`)
