# capple217/cache-aware-llm-proxy architecture

> Architecture diagram of the GitHub repository capple217/cache-aware-llm-proxy, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/capple217/cache-aware-llm-proxy
- Repository: https://github.com/capple217/cache-aware-llm-proxy

## Overview

This repository is a cache-aware, streaming reverse proxy for LLM inference replicas, plus a simulated backend and an open-loop load generator. The main workflow is to accept and frame a client request, choose a replica using cache and load estimates, stream the upstream response, and update routing state from progress and backend KV events. The README documents the cache tiers, routing modes, and measurement goals; some implementation details are unsampled, so those links rely on documented behavior rather than inspected internals.

Main entry points: [`src/proxy.cpp`](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/proxy.cpp) (Proxy workers), [`src/fake_backend.cpp`](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp) (Fake inference server), [`src/router.cpp`](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/router.cpp) (Replica router), [`apps/loadgen.cpp`](https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/loadgen.cpp) (Open-loop loadgen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_traffic["Traffic and proxy"]
  node_proxy_app["Proxy launcher<br/>[proxy.cpp]"]
  node_proxy["Proxy workers<br/>[proxy.cpp]"]
  node_http["HTTP framing<br/>[http.cpp]"]
  node_net["Socket poller<br/>[net.cpp]"]
end

subgraph group_routing["Cache-aware routing"]
  node_router["Replica router<br/>[router.cpp]"]
  node_cache["Tiered cache index<br/>[kv_cache.cpp]"]
  node_event_follower["KV event follower<br/>[proxy.cpp]"]
end

subgraph group_backend["Inference backends"]
  node_backend_service{{"Inference replicas"}}
  node_fake_app["Fake backend launcher<br/>[fake_backend.cpp]"]
  node_fake_backend["Fake inference server<br/>[fake_backend.cpp]"]
  node_backend_cache[("Backend KV tiers<br/>[fake_backend.cpp]")]
  node_backend_events["Backend KV event stream<br/>[fake_backend.cpp]"]
end

subgraph group_measurement["Load and measurement"]
  node_loadgen["Open-loop loadgen<br/>[loadgen.cpp]"]
  node_stats["Router metrics<br/>[router.cpp]"]
end

node_client(("LLM client"))

node_client -->|"sends requests"| node_proxy
node_loadgen -->|"sends workload"| node_proxy
node_proxy_app -->|"configures and starts"| node_proxy
node_proxy -->|"polls sockets"| node_net
node_proxy -->|"frames messages"| node_http
node_proxy -->|"routes requests"| node_router
node_router -->|"matches cache blocks"| node_cache
node_proxy -->|"forwards and streams"| node_backend_service
node_backend_service -->|"streams responses"| node_proxy
node_event_follower -->|"reads KV events"| node_backend_events
node_backend_events -->|"updates shadow index"| node_router
node_proxy -->|"reports progress"| node_router
node_fake_app -->|"starts server"| node_fake_backend
node_fake_backend -->|"updates cache tiers"| node_backend_cache
node_fake_backend -->|"publishes events"| node_backend_events
node_backend_service -.->|"simulated by"| node_fake_backend
node_proxy -->|"exposes metrics"| node_stats
node_loadgen -->|"fetches proxy stats"| node_stats

click node_loadgen "https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/loadgen.cpp"
click node_proxy_app "https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/proxy.cpp"
click node_proxy "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/proxy.cpp"
click node_http "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/http.cpp"
click node_net "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/net.cpp"
click node_router "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/router.cpp"
click node_cache "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/kv_cache.cpp"
click node_event_follower "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/proxy.cpp"
click node_fake_app "https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/fake_backend.cpp"
click node_fake_backend "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp"
click node_backend_cache "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp"
click node_backend_events "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp"
click node_stats "https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/router.cpp"

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_proxy_app,node_proxy,node_http,node_net,node_client toneBlue
class node_router,node_cache,node_event_follower toneAmber
class node_backend_service,node_fake_app,node_fake_backend,node_backend_cache,node_backend_events toneMint
class node_loadgen,node_stats toneRose
```

## Components

### Traffic and proxy

- [Proxy launcher](https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/proxy.cpp): `apps/proxy.cpp`
- [Proxy workers](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/proxy.cpp): `src/proxy.cpp`
- [HTTP framing](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/http.cpp): `src/http.cpp`
- [Socket poller](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/net.cpp): `src/net.cpp`

### Cache-aware routing

- [Replica router](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/router.cpp): `src/router.cpp`
- [Tiered cache index](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/kv_cache.cpp): `src/kv_cache.cpp`
- [KV event follower](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/proxy.cpp): `src/proxy.cpp`

### Inference backends

- **Inference replicas**
- [Fake backend launcher](https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/fake_backend.cpp): `apps/fake_backend.cpp`
- [Fake inference server](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp): `src/fake_backend.cpp`
- [Backend KV tiers](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp): `src/fake_backend.cpp`
- [Backend KV event stream](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/fake_backend.cpp): `src/fake_backend.cpp`

### Load and measurement

- [Open-loop loadgen](https://github.com/capple217/cache-aware-llm-proxy/blob/main/apps/loadgen.cpp): `apps/loadgen.cpp`
- [Router metrics](https://github.com/capple217/cache-aware-llm-proxy/blob/main/src/router.cpp): `src/router.cpp`

### Other components

- **LLM client**

## Connections

- LLM client → Proxy workers: sends requests (evidence: `README.md`)
- Open-loop loadgen → Proxy workers: sends workload (evidence: `apps/loadgen.cpp`)
- Proxy launcher → Proxy workers: configures and starts (evidence: `apps/proxy.cpp`)
- Proxy workers → Socket poller: polls sockets (evidence: `README.md`)
- Proxy workers → HTTP framing: frames messages (evidence: `src/proxy.cpp`)
- Proxy workers → Replica router: routes requests (evidence: `README.md`)
- Replica router → Tiered cache index: matches cache blocks (evidence: `src/router.cpp`)
- Proxy workers → Inference replicas: forwards and streams (evidence: `README.md`)
- Inference replicas → Proxy workers: streams responses (evidence: `README.md`)
- KV event follower → Backend KV event stream: reads KV events (evidence: `README.md`)
- Backend KV event stream → Replica router: updates shadow index (evidence: `src/router.cpp`)
- Proxy workers → Replica router: reports progress (evidence: `README.md`)
- Fake backend launcher → Fake inference server: starts server (evidence: `apps/fake_backend.cpp`)
- Fake inference server → Backend KV tiers: updates cache tiers (evidence: `src/fake_backend.cpp`)
- Fake inference server → Backend KV event stream: publishes events (evidence: `src/fake_backend.cpp`)
- Inference replicas → Fake inference server: simulated by (evidence: `README.md`)
- Proxy workers → Router metrics: exposes metrics (evidence: `README.md`)
- Open-loop loadgen → Router metrics: fetches proxy stats (evidence: `apps/loadgen.cpp`)
