# pranavparuchur1/inference-gateway architecture

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

- Interactive diagram: https://gitdiagram.com/pranavparuchur1/inference-gateway
- Repository: https://github.com/pranavparuchur1/inference-gateway

## Overview

Inference Gateway is an OpenAI-compatible front door for three model workers, with an optional Claude fallback. A client request is authenticated, rate-limited, validated, routed, admitted to a worker tier, and returned as a normal or streamed response; usage and request logs are recorded. The repository also includes measured studies of batching, KV caching, quantization, and load. Runtime wiring is supported by the README and sampled gateway/router excerpts; experiment-script relationships are documented at a capability level rather than inferred from unsampled implementations.

Main entry points: [`src/inference_gateway/app.py`](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/app.py) (HTTP gateway), [`src/inference_gateway/auth.py`](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/auth.py) (API keys), [`scripts/bench_batching.py`](https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/bench_batching.py) (Batching benchmark), [`src/inference_gateway/db.py`](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/db.py) (SQLite records)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_gateway["Gateway request path"]
  node_api["HTTP gateway<br/>[app.py]"]
  node_settings["Settings<br/>[config.py]"]
  node_tokens["Token counting<br/>[tokens.py]"]
  node_cli["Admin CLI<br/>[cli.py]"]
end

subgraph group_controls["Routing and controls"]
  node_keys["API keys<br/>[auth.py]"]
  node_limits["Rate limits<br/>[ratelimit.py]"]
  node_routing["Tier router<br/>[router.py]"]
  node_admission["Admission pool<br/>[pool.py]"]
end

subgraph group_state["Identity and records"]
  node_records[("SQLite records<br/>[db.py]")]
  node_logs["JSON request logs<br/>[logs.py]"]
end

subgraph group_providers["Inference providers"]
  node_workers["vLLM workers"]
  node_claude["Claude fallback<br/>[claude.py]"]
end

subgraph group_studies["Inference studies"]
  node_mini_engine["Minigen engine<br/>[minigen.py]"]
  node_batch_study["Batching benchmark<br/>[bench_batching.py]"]
  node_kv_study["KV cache lab<br/>[kv_cache_lab.py]"]
  node_quant_study["Quantization lab<br/>[quant_lab.py]"]
  node_load_study["Load generator<br/>[loadgen.py]"]
  node_grading["Eval grading<br/>[grading.py]"]
end

node_client(("API client"))

node_client -->|"sends requests"| node_api
node_api -->|"authenticates"| node_keys
node_api -->|"rate limits"| node_limits
node_api -->|"chooses tier"| node_routing
node_api -->|"checks capacity"| node_admission
node_api -->|"counts tokens"| node_tokens
node_api -->|"forwards requests"| node_workers
node_api -.->|"uses fallback"| node_claude
node_api -->|"records usage"| node_records
node_api -->|"writes request logs"| node_logs
node_settings -->|"configures"| node_api
node_keys -->|"reads and writes keys"| node_records
node_cli -->|"manages keys"| node_keys
node_batch_study -->|"benchmarks batching"| node_mini_engine
node_batch_study -->|"uses grading"| node_grading
node_kv_study -->|"measures caching"| node_workers
node_quant_study -->|"measures quantization"| node_workers
node_load_study -->|"sends load"| node_api

click node_api "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/app.py"
click node_settings "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/config.py"
click node_keys "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/auth.py"
click node_limits "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/ratelimit.py"
click node_routing "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/router.py"
click node_admission "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/pool.py"
click node_tokens "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/tokens.py"
click node_records "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/db.py"
click node_logs "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/logs.py"
click node_claude "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/claude.py"
click node_cli "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/cli.py"
click node_mini_engine "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/minigen.py"
click node_batch_study "https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/bench_batching.py"
click node_kv_study "https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/kv_cache_lab.py"
click node_quant_study "https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/quant_lab.py"
click node_load_study "https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/loadgen.py"
click node_grading "https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/grading.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_api,node_settings,node_tokens,node_cli,node_client toneBlue
class node_keys,node_limits,node_routing,node_admission toneAmber
class node_records,node_logs toneMint
class node_workers,node_claude toneRose
class node_mini_engine,node_batch_study,node_kv_study,node_quant_study,node_load_study,node_grading toneIndigo
```

## Components

### Gateway request path

- [HTTP gateway](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/app.py): `src/inference_gateway/app.py`
- [Settings](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/config.py): `src/inference_gateway/config.py`
- [Token counting](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/tokens.py): `src/inference_gateway/tokens.py`
- [Admin CLI](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/cli.py): `src/inference_gateway/cli.py`

### Routing and controls

- [API keys](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/auth.py): `src/inference_gateway/auth.py`
- [Rate limits](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/ratelimit.py): `src/inference_gateway/ratelimit.py`
- [Tier router](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/router.py): `src/inference_gateway/router.py`
- [Admission pool](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/pool.py): `src/inference_gateway/pool.py`

### Identity and records

- [SQLite records](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/db.py): `src/inference_gateway/db.py`
- [JSON request logs](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/logs.py): `src/inference_gateway/logs.py`

### Inference providers

- **vLLM workers**
- [Claude fallback](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/claude.py): `src/inference_gateway/claude.py`

### Inference studies

- [Minigen engine](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/minigen.py): `src/inference_gateway/minigen.py`
- [Batching benchmark](https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/bench_batching.py): `scripts/bench_batching.py`
- [KV cache lab](https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/kv_cache_lab.py): `scripts/kv_cache_lab.py`
- [Quantization lab](https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/quant_lab.py): `scripts/quant_lab.py`
- [Load generator](https://github.com/pranavparuchur1/inference-gateway/blob/main/scripts/loadgen.py): `scripts/loadgen.py`
- [Eval grading](https://github.com/pranavparuchur1/inference-gateway/blob/main/src/inference_gateway/grading.py): `src/inference_gateway/grading.py`

### Other components

- **API client**

## Connections

- API client → HTTP gateway: sends requests (evidence: `README.md`)
- HTTP gateway → API keys: authenticates (evidence: `src/inference_gateway/app.py`)
- HTTP gateway → Rate limits: rate limits (evidence: `README.md`)
- HTTP gateway → Tier router: chooses tier (evidence: `src/inference_gateway/app.py`)
- HTTP gateway → Admission pool: checks capacity (evidence: `README.md`)
- HTTP gateway → Token counting: counts tokens (evidence: `README.md`)
- HTTP gateway → vLLM workers: forwards requests (evidence: `README.md`)
- HTTP gateway → Claude fallback: uses fallback (evidence: `README.md`)
- HTTP gateway → SQLite records: records usage (evidence: `README.md`)
- HTTP gateway → JSON request logs: writes request logs (evidence: `README.md`)
- Settings → HTTP gateway: configures (evidence: `README.md`)
- API keys → SQLite records: reads and writes keys (evidence: `src/inference_gateway/auth.py`)
- Admin CLI → API keys: manages keys (evidence: `README.md`)
- Batching benchmark → Minigen engine: benchmarks batching (evidence: `scripts/bench_batching.py`)
- Batching benchmark → Eval grading: uses grading (evidence: `scripts/bench_batching.py`)
- KV cache lab → vLLM workers: measures caching (evidence: `README.md`)
- Quantization lab → vLLM workers: measures quantization (evidence: `README.md`)
- Load generator → HTTP gateway: sends load (evidence: `README.md`)
