# prajyotdev530/rate-limiter architecture

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

- Interactive diagram: https://gitdiagram.com/prajyotdev530/rate-limiter
- Repository: https://github.com/prajyotdev530/rate-limiter

## Overview

RLaaS accepts API-keyed rate checks, loads each key's policy, evaluates it against Redis state, returns a decision, and records it for analytics. Its dashboard manages keys and presents live statistics and request logs, with a request tester for exercising limits. The graph includes the documented analytics and management branches; unsampled handler details and frontend pages are represented using documented routes, with those links cited to the README.

Main entry points: [`backend/internal/api/handlers.go`](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/api/handlers.go) (API Handlers), [`frontend/app/page.tsx`](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/page.tsx) (Dashboard), [`frontend/lib/api.ts`](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/lib/api.ts) (Typed API Client), [`backend/internal/db/postgres.go`](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/postgres.go) (PostgreSQL)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Rate Limit API"]
  node_server["HTTP Server<br/>[main.go]"]
  node_handlers["API Handlers<br/>[handlers.go]"]
  node_middleware["Gin Middleware<br/>[middleware.go]"]
  node_models["API Models<br/>[types.go]"]
end

subgraph group_algorithms["Limit Algorithms"]
  node_algorithm_factory["Algorithm Factory<br/>[redis.go]"]
  node_limiter_interface["Limiter Interface<br/>[interface.go]"]
  node_token_bucket["Token Bucket<br/>[token_bucket.go]"]
  node_sliding_window["Sliding Window<br/>[sliding_window.go]"]
end

subgraph group_persistence["State And Analytics"]
  node_postgres[("PostgreSQL<br/>[postgres.go]")]
  node_redis[("Redis<br/>[redis.go]")]
end

subgraph group_dashboard["Dashboard"]
  node_dashboard_home["Dashboard<br/>[page.tsx]"]
  node_keys_page["Key Management<br/>[page.tsx]"]
  node_logs_page["Request Logs<br/>[page.tsx]"]
  node_api_client["Typed API Client<br/>[api.ts]"]
  node_request_tester["Request Tester<br/>[RequestTester.tsx]"]
  node_stats_chart["Live Stats Chart<br/>[StatsChart.tsx]"]
  node_key_table["Key Table<br/>[KeyTable.tsx]"]
  node_log_table["Log Table<br/>[LogTable.tsx]"]
end

node_client(("Client Backend"))
node_dashboard_user(("Dashboard User"))

node_server -->|"routes to"| node_handlers
node_server -->|"initializes"| node_postgres
node_server -->|"initializes"| node_redis
node_handlers -->|"reads and writes"| node_postgres
node_handlers -->|"selects limiter"| node_algorithm_factory
node_algorithm_factory -->|"creates"| node_token_bucket
node_algorithm_factory -->|"creates"| node_sliding_window
node_token_bucket -->|"implements"| node_limiter_interface
node_sliding_window -->|"implements"| node_limiter_interface
node_token_bucket -->|"updates state"| node_redis
node_sliding_window -->|"updates state"| node_redis
node_handlers -->|"logs asynchronously"| node_postgres
node_handlers -->|"queries analytics"| node_postgres
node_client -->|"checks limit"| node_handlers
node_handlers -->|"returns decision"| node_client
node_middleware -->|"uses handler"| node_handlers
node_dashboard_user -->|"views"| node_dashboard_home
node_dashboard_home -->|"loads keys"| node_api_client
node_dashboard_home -->|"renders"| node_stats_chart
node_dashboard_home -->|"renders"| node_request_tester
node_dashboard_home -->|"renders"| node_key_table
node_keys_page -->|"manages keys"| node_api_client
node_keys_page -->|"renders"| node_key_table
node_keys_page -->|"renders"| node_stats_chart
node_logs_page -->|"loads logs"| node_api_client
node_logs_page -->|"renders"| node_log_table
node_request_tester -->|"sends checks"| node_handlers
node_api_client -->|"calls API"| node_handlers
node_stats_chart -->|"loads stats"| node_api_client

click node_server "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/cmd/server/main.go"
click node_handlers "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/api/handlers.go"
click node_middleware "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/api/middleware.go"
click node_models "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/models/types.go"
click node_algorithm_factory "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/redis.go"
click node_limiter_interface "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/algorithms/interface.go"
click node_token_bucket "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/algorithms/token_bucket.go"
click node_sliding_window "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/algorithms/sliding_window.go"
click node_postgres "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/postgres.go"
click node_redis "https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/redis.go"
click node_dashboard_home "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/page.tsx"
click node_keys_page "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/keys/page.tsx"
click node_logs_page "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/logs/page.tsx"
click node_api_client "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/lib/api.ts"
click node_request_tester "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/RequestTester.tsx"
click node_stats_chart "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/StatsChart.tsx"
click node_key_table "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/KeyTable.tsx"
click node_log_table "https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/LogTable.tsx"

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_server,node_handlers,node_middleware,node_models,node_client,node_dashboard_user toneBlue
class node_algorithm_factory,node_limiter_interface,node_token_bucket,node_sliding_window toneAmber
class node_postgres,node_redis toneMint
class node_dashboard_home,node_keys_page,node_logs_page,node_api_client,node_request_tester,node_stats_chart,node_key_table,node_log_table toneRose
```

## Components

### Rate Limit API

- [HTTP Server](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/cmd/server/main.go): `backend/cmd/server/main.go`
- [API Handlers](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/api/handlers.go): `backend/internal/api/handlers.go`
- [Gin Middleware](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/api/middleware.go): `backend/internal/api/middleware.go`
- [API Models](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/models/types.go): `backend/internal/models/types.go`

### Limit Algorithms

- [Algorithm Factory](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/redis.go): `backend/internal/db/redis.go`
- [Limiter Interface](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/algorithms/interface.go): `backend/internal/algorithms/interface.go`
- [Token Bucket](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/algorithms/token_bucket.go): `backend/internal/algorithms/token_bucket.go`
- [Sliding Window](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/algorithms/sliding_window.go): `backend/internal/algorithms/sliding_window.go`

### State And Analytics

- [PostgreSQL](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/postgres.go): `backend/internal/db/postgres.go`
- [Redis](https://github.com/prajyotdev530/rate-limiter/blob/main/backend/internal/db/redis.go): `backend/internal/db/redis.go`

### Dashboard

- [Dashboard](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Key Management](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/keys/page.tsx): `frontend/app/keys/page.tsx`
- [Request Logs](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/app/logs/page.tsx): `frontend/app/logs/page.tsx`
- [Typed API Client](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`
- [Request Tester](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/RequestTester.tsx): `frontend/components/RequestTester.tsx`
- [Live Stats Chart](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/StatsChart.tsx): `frontend/components/StatsChart.tsx`
- [Key Table](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/KeyTable.tsx): `frontend/components/KeyTable.tsx`
- [Log Table](https://github.com/prajyotdev530/rate-limiter/blob/main/frontend/components/LogTable.tsx): `frontend/components/LogTable.tsx`

### Other components

- **Client Backend**
- **Dashboard User**

## Connections

- HTTP Server → API Handlers: routes to (evidence: `backend/cmd/server/main.go`)
- HTTP Server → PostgreSQL: initializes (evidence: `backend/cmd/server/main.go`)
- HTTP Server → Redis: initializes (evidence: `backend/cmd/server/main.go`)
- API Handlers → PostgreSQL: reads and writes (evidence: `backend/internal/api/handlers.go`)
- API Handlers → Algorithm Factory: selects limiter (evidence: `backend/internal/api/handlers.go`)
- Algorithm Factory → Token Bucket: creates (evidence: `README.md`)
- Algorithm Factory → Sliding Window: creates (evidence: `README.md`)
- Token Bucket → Limiter Interface: implements (evidence: `backend/internal/algorithms/token_bucket.go`)
- Sliding Window → Limiter Interface: implements (evidence: `backend/internal/algorithms/sliding_window.go`)
- Token Bucket → Redis: updates state (evidence: `backend/internal/algorithms/token_bucket.go`)
- Sliding Window → Redis: updates state (evidence: `README.md`)
- API Handlers → PostgreSQL: logs asynchronously (evidence: `backend/internal/api/handlers.go`)
- API Handlers → PostgreSQL: queries analytics (evidence: `README.md`)
- Client Backend → API Handlers: checks limit (evidence: `README.md`)
- API Handlers → Client Backend: returns decision (evidence: `README.md`)
- Gin Middleware → API Handlers: uses handler (evidence: `README.md`)
- Dashboard User → Dashboard: views (evidence: `frontend/app/page.tsx`)
- Dashboard → Typed API Client: loads keys (evidence: `frontend/app/page.tsx`)
- Dashboard → Live Stats Chart: renders (evidence: `frontend/app/page.tsx`)
- Dashboard → Request Tester: renders (evidence: `frontend/app/page.tsx`)
- Dashboard → Key Table: renders (evidence: `frontend/app/page.tsx`)
- Key Management → Typed API Client: manages keys (evidence: `frontend/app/keys/page.tsx`)
- Key Management → Key Table: renders (evidence: `README.md`)
- Key Management → Live Stats Chart: renders (evidence: `frontend/app/keys/page.tsx`)
- Request Logs → Typed API Client: loads logs (evidence: `frontend/app/logs/page.tsx`)
- Request Logs → Log Table: renders (evidence: `frontend/app/logs/page.tsx`)
- Request Tester → API Handlers: sends checks (evidence: `frontend/components/RequestTester.tsx`)
- Typed API Client → API Handlers: calls API (evidence: `README.md`)
- Live Stats Chart → Typed API Client: loads stats (evidence: `README.md`)
