# harikamasam/distributed-rate-limiter-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/harikamasam/distributed-rate-limiter-gateway
- Repository: https://github.com/harikamasam/distributed-rate-limiter-gateway

## Overview

The product is a FastAPI API gateway that authenticates API keys, applies per-tier token-bucket limits, and serves protected API routes. Its principal path is client request → gateway policy → Redis-backed limiter → shared Redis state; accepted requests continue to the demo API routes. The repository also includes an in-memory algorithm implementation, dashboard/stats capability, health check, and documented benchmark. Source excerpts establish gateway and limiter calls; dashboard and benchmark relationships are based on README descriptions.

Main entry points: [`app/main.py`](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py) (Gateway middleware), [`app/redis_token_bucket.py`](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/redis_token_bucket.py) (Redis limiter), [`dashboard/index.html`](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/dashboard/index.html) (Stats dashboard), [`benchmark.py`](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/benchmark.py) (Load benchmark)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway"]
  node_gateway_app["Gateway middleware<br/>[main.py]"]
  node_api_routes["Protected API routes<br/>[main.py]"]
  node_tier_policy["Tier policy<br/>[main.py]"]
end

subgraph group_limiting["Rate Limiting"]
  node_redis_limiter["Redis limiter"]
  node_memory_limiter["In-memory limiter<br/>[token_bucket.py]"]
  node_redis[("Redis")]
end

subgraph group_operations["Operations"]
  node_stats_api["Stats and health API<br/>[main.py]"]
  node_dashboard["Stats dashboard<br/>[index.html]"]
  node_benchmark["Load benchmark<br/>[benchmark.py]"]
end

node_client(("API client"))

node_client -->|"sends request"| node_gateway_app
node_gateway_app -->|"checks API key"| node_tier_policy
node_gateway_app -->|"checks limit"| node_redis_limiter
node_redis_limiter -->|"runs atomic script"| node_redis
node_gateway_app -->|"dispatches allowed"| node_api_routes
node_client -->|"requests stats"| node_stats_api
node_dashboard -->|"reads stats"| node_stats_api
node_stats_api -->|"checks health"| node_redis
node_benchmark -->|"sends concurrent requests"| node_gateway_app

click node_gateway_app "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py"
click node_api_routes "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py"
click node_tier_policy "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py"
click node_redis_limiter "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/redis_token_bucket.py"
click node_memory_limiter "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/token_bucket.py"
click node_stats_api "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py"
click node_dashboard "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/dashboard/index.html"
click node_benchmark "https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/benchmark.py"

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_gateway_app,node_api_routes,node_tier_policy,node_client toneBlue
class node_redis_limiter,node_memory_limiter,node_redis toneAmber
class node_stats_api,node_dashboard,node_benchmark toneMint
```

## Components

### Gateway

- [Gateway middleware](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py): `app/main.py`
- [Protected API routes](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py): `app/main.py`
- [Tier policy](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py): `app/main.py`

### Rate Limiting

- [Redis limiter](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/redis_token_bucket.py): `app/redis_token_bucket.py`
- [In-memory limiter](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/token_bucket.py): `app/token_bucket.py`
- **Redis**

### Operations

- [Stats and health API](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/app/main.py): `app/main.py`
- [Stats dashboard](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/dashboard/index.html): `dashboard/index.html`
- [Load benchmark](https://github.com/harikamasam/distributed-rate-limiter-gateway/blob/main/benchmark.py): `benchmark.py`

### Other components

- **API client**

## Connections

- API client → Gateway middleware: sends request (evidence: `README.md`)
- Gateway middleware → Tier policy: checks API key (evidence: `app/main.py`)
- Gateway middleware → Redis limiter: checks limit (evidence: `app/main.py`)
- Redis limiter → Redis: runs atomic script (evidence: `app/redis_token_bucket.py`)
- Gateway middleware → Protected API routes: dispatches allowed (evidence: `app/main.py`)
- API client → Stats and health API: requests stats (evidence: `README.md`)
- Stats dashboard → Stats and health API: reads stats (evidence: `README.md`)
- Stats and health API → Redis: checks health (evidence: `app/main.py`)
- Load benchmark → Gateway middleware: sends concurrent requests (evidence: `README.md`)
