# adityass2004/load-balancer architecture

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

- Interactive diagram: https://gitdiagram.com/adityass2004/load-balancer
- Repository: https://github.com/adityass2004/load-balancer

## Overview

TrackIt is a project-aware reverse proxy and dynamic load balancer, with administrative tools for configuring projects and servers and viewing operational data. The main runtime flow accepts a client request, applies middleware and rate limits, resolves project and backend state, selects and forwards to an upstream, then records request data. Separate branches cover project administration, health monitoring, and analytics/logging. Some UI, health, and persistence connections are documented only broadly or were not sampled; those links are omitted or marked unverified rather than inferred as calls.

Main entry points: [`app/api/[...path]/route.ts`](https://github.com/adityass2004/load-balancer/blob/main/app/api/%5B...path%5D/route.ts) (Proxy Handler), [`services/cache/CacheService.ts`](https://github.com/adityass2004/load-balancer/blob/main/services/cache/CacheService.ts) (Runtime Cache), [`services/load-balancer/RetryService.ts`](https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/RetryService.ts) (Retry Orchestrator), [`services/project.service.ts`](https://github.com/adityass2004/load-balancer/blob/main/services/project.service.ts) (Project Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_proxy["Proxy Runtime"]
  node_middleware["Request Middleware<br/>[middleware.ts]"]
  node_proxy_route["Proxy Handler<br/>[route.ts]"]
  node_rate_limit["Rate Limiter<br/>[index.ts]"]
  node_cache["Runtime Cache<br/>[CacheService.ts]"]
  node_selector["Backend Selector<br/>[ServerSelector.ts]"]
  node_retry["Retry Orchestrator<br/>[RetryService.ts]"]
  node_forwarder["Request Forwarder"]
end

subgraph group_admin["Administration"]
  node_admin_ui["Admin Dashboard<br/>[page.tsx]"]
  node_server_actions["Server Actions<br/>[server.actions.ts]"]
  node_server_service["Server Service<br/>[server.service.ts]"]
  node_project_api["Project API<br/>[route.ts]"]
  node_project_service["Project Service<br/>[project.service.ts]"]
end

subgraph group_ops["Operations"]
  node_health["Health Monitoring<br/>[HealthScheduler.ts]"]
  node_analytics["Analytics Service"]
  node_logging["Request Logging<br/>[LogQueue.ts]"]
end

subgraph group_data["Persistence"]
  node_project_repo["Project Repository"]
  node_server_repo["Server Repository"]
  node_settings_repo["Settings Repository"]
end

node_client(("External Client"))
node_upstream(("Backend Servers"))
node_database[("PostgreSQL")]

node_client -->|"sends request"| node_middleware
node_middleware -->|"passes request"| node_proxy_route
node_proxy_route -->|"checks limits"| node_rate_limit
node_proxy_route -->|"resolves project"| node_cache
node_proxy_route -->|"dispatches request"| node_retry
node_retry -->|"selects backend"| node_selector
node_retry -->|"forwards attempt"| node_forwarder
node_forwarder -->|"sends request"| node_upstream
node_retry -->|"enqueues log"| node_logging
node_admin_ui -.->|"manages servers"| node_server_actions
node_server_actions -->|"invokes service"| node_server_service
node_server_service -->|"reads and writes"| node_server_repo
node_project_api -->|"invokes service"| node_project_service
node_project_service -->|"reads and writes"| node_project_repo
node_project_service -->|"creates settings"| node_settings_repo
node_cache -->|"loads projects"| node_project_repo
node_cache -->|"loads servers"| node_server_repo
node_cache -->|"loads settings"| node_settings_repo
node_health -.->|"persists health"| node_database
node_analytics -.->|"queries metrics"| node_database
node_logging -.->|"persists logs"| node_database

click node_middleware "https://github.com/adityass2004/load-balancer/blob/main/middleware.ts"
click node_proxy_route "https://github.com/adityass2004/load-balancer/blob/main/app/api/%5B...path%5D/route.ts"
click node_rate_limit "https://github.com/adityass2004/load-balancer/blob/main/lib/rate-limit/index.ts"
click node_cache "https://github.com/adityass2004/load-balancer/blob/main/services/cache/CacheService.ts"
click node_selector "https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/ServerSelector.ts"
click node_retry "https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/RetryService.ts"
click node_forwarder "https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/RequestForwarder.ts"
click node_admin_ui "https://github.com/adityass2004/load-balancer/blob/main/app/(dashboard)/dashboard/page.tsx"
click node_server_actions "https://github.com/adityass2004/load-balancer/blob/main/actions/server.actions.ts"
click node_server_service "https://github.com/adityass2004/load-balancer/blob/main/services/server.service.ts"
click node_project_api "https://github.com/adityass2004/load-balancer/blob/main/app/api/admin/projects/route.ts"
click node_project_service "https://github.com/adityass2004/load-balancer/blob/main/services/project.service.ts"
click node_health "https://github.com/adityass2004/load-balancer/blob/main/services/health/HealthScheduler.ts"
click node_analytics "https://github.com/adityass2004/load-balancer/blob/main/services/analytics/AnalyticsService.ts"
click node_logging "https://github.com/adityass2004/load-balancer/blob/main/services/logging/LogQueue.ts"
click node_project_repo "https://github.com/adityass2004/load-balancer/blob/main/repositories/project.repository.ts"
click node_server_repo "https://github.com/adityass2004/load-balancer/blob/main/repositories/server.repository.ts"
click node_settings_repo "https://github.com/adityass2004/load-balancer/blob/main/repositories/settings.repository.ts"

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_middleware,node_proxy_route,node_rate_limit,node_cache,node_selector,node_retry,node_forwarder,node_client toneBlue
class node_admin_ui,node_server_actions,node_server_service,node_project_api,node_project_service,node_database toneAmber
class node_health,node_analytics,node_logging,node_upstream toneMint
class node_project_repo,node_server_repo,node_settings_repo toneRose
```

## Components

### Proxy Runtime

- [Request Middleware](https://github.com/adityass2004/load-balancer/blob/main/middleware.ts): `middleware.ts`
- [Proxy Handler](https://github.com/adityass2004/load-balancer/blob/main/app/api/%5B...path%5D/route.ts): `app/api/[...path]/route.ts`
- [Rate Limiter](https://github.com/adityass2004/load-balancer/blob/main/lib/rate-limit/index.ts): `lib/rate-limit/index.ts`
- [Runtime Cache](https://github.com/adityass2004/load-balancer/blob/main/services/cache/CacheService.ts): `services/cache/CacheService.ts`
- [Backend Selector](https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/ServerSelector.ts): `services/load-balancer/ServerSelector.ts`
- [Retry Orchestrator](https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/RetryService.ts): `services/load-balancer/RetryService.ts`
- [Request Forwarder](https://github.com/adityass2004/load-balancer/blob/main/services/load-balancer/RequestForwarder.ts): `services/load-balancer/RequestForwarder.ts`

### Administration

- [Admin Dashboard](https://github.com/adityass2004/load-balancer/blob/main/app/(dashboard)/dashboard/page.tsx): `app/(dashboard)/dashboard/page.tsx`
- [Server Actions](https://github.com/adityass2004/load-balancer/blob/main/actions/server.actions.ts): `actions/server.actions.ts`
- [Server Service](https://github.com/adityass2004/load-balancer/blob/main/services/server.service.ts): `services/server.service.ts`
- [Project API](https://github.com/adityass2004/load-balancer/blob/main/app/api/admin/projects/route.ts): `app/api/admin/projects/route.ts`
- [Project Service](https://github.com/adityass2004/load-balancer/blob/main/services/project.service.ts): `services/project.service.ts`

### Operations

- [Health Monitoring](https://github.com/adityass2004/load-balancer/blob/main/services/health/HealthScheduler.ts): `services/health/HealthScheduler.ts`
- [Analytics Service](https://github.com/adityass2004/load-balancer/blob/main/services/analytics/AnalyticsService.ts): `services/analytics/AnalyticsService.ts`
- [Request Logging](https://github.com/adityass2004/load-balancer/blob/main/services/logging/LogQueue.ts): `services/logging/LogQueue.ts`

### Persistence

- [Project Repository](https://github.com/adityass2004/load-balancer/blob/main/repositories/project.repository.ts): `repositories/project.repository.ts`
- [Server Repository](https://github.com/adityass2004/load-balancer/blob/main/repositories/server.repository.ts): `repositories/server.repository.ts`
- [Settings Repository](https://github.com/adityass2004/load-balancer/blob/main/repositories/settings.repository.ts): `repositories/settings.repository.ts`

### Other components

- **External Client**
- **Backend Servers**
- **PostgreSQL**

## Connections

- External Client → Request Middleware: sends request
- Request Middleware → Proxy Handler: passes request
- Proxy Handler → Rate Limiter: checks limits (evidence: `app/api/[...path]/route.ts`)
- Proxy Handler → Runtime Cache: resolves project (evidence: `app/api/[...path]/route.ts`)
- Proxy Handler → Retry Orchestrator: dispatches request (evidence: `app/api/[...path]/route.ts`)
- Retry Orchestrator → Backend Selector: selects backend (evidence: `services/load-balancer/RetryService.ts`)
- Retry Orchestrator → Request Forwarder: forwards attempt (evidence: `services/load-balancer/RetryService.ts`)
- Request Forwarder → Backend Servers: sends request
- Retry Orchestrator → Request Logging: enqueues log (evidence: `services/load-balancer/RetryService.ts`)
- Admin Dashboard → Server Actions: manages servers
- Server Actions → Server Service: invokes service (evidence: `actions/server.actions.ts`)
- Server Service → Server Repository: reads and writes (evidence: `services/server.service.ts`)
- Project API → Project Service: invokes service (evidence: `app/api/admin/projects/route.ts`)
- Project Service → Project Repository: reads and writes (evidence: `services/project.service.ts`)
- Project Service → Settings Repository: creates settings (evidence: `services/project.service.ts`)
- Runtime Cache → Project Repository: loads projects (evidence: `services/cache/CacheService.ts`)
- Runtime Cache → Server Repository: loads servers (evidence: `services/cache/CacheService.ts`)
- Runtime Cache → Settings Repository: loads settings (evidence: `services/cache/CacheService.ts`)
- Health Monitoring → PostgreSQL: persists health
- Analytics Service → PostgreSQL: queries metrics
- Request Logging → PostgreSQL: persists logs
