# roborun-xyz/sol-rpc-router architecture

> Architecture diagram of the GitHub repository roborun-xyz/sol-rpc-router, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roborun-xyz/sol-rpc-router
- Repository: https://github.com/roborun-xyz/sol-rpc-router

## Overview

sol-rpc-router is a Solana JSON-RPC and WebSocket gateway that authenticates clients, enforces per-key limits, and routes traffic across configured providers. The principal HTTP path is client → assembled router/middleware → authenticated proxy handler → backend selection and upstream attempt, with retries or transaction fan-out where configured. Separate capabilities include WebSocket proxying, health probes and detailed health reporting, Prometheus metrics, and API-key administration. Edges below are limited to relationships shown in the excerpts or explicitly documented in the README; unsampled wiring is omitted.

Main entry points: [`src/handlers.rs`](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/handlers.rs) (Proxy and WS Handlers), [`src/state.rs`](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/state.rs) (Application State), [`src/router.rs`](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/router.rs) (HTTP and WS Routers), [`src/keystore.rs`](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/keystore.rs) (Key Stores)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Gateway Entry"]
  node_router["HTTP and WS Routers<br/>[router.rs]"]
  node_handlers["Proxy and WS Handlers<br/>[handlers.rs]"]
  node_rpc["RPC Parsing<br/>[rpc.rs]"]
  node_appstate["Application State<br/>[state.rs]"]
end

subgraph group_routing["Routing and Upstreams"]
  node_selection["Backend Selection<br/>[state.rs]"]
  node_upstream["Upstream Requests<br/>[upstream.rs]"]
end

subgraph group_access["Identity and Config"]
  node_config["Runtime Configuration<br/>[config.rs]"]
  node_keystore[("Key Stores<br/>[keystore.rs]")]
  node_admin["Key Administration<br/>[rpc-admin.rs]"]
end

subgraph group_operations["Health and Observability"]
  node_healthloop["Health Probes<br/>[health.rs]"]
  node_healthstate[("Backend Health State<br/>[health.rs]")]
  node_metrics["Metrics and Health Routes<br/>[router.rs]"]
  node_monitoring["Grafana Dashboard"]
end

node_client(("RPC Client"))
node_provider["Solana Providers"]
node_redis[("Redis")]
node_prometheus(("Prometheus Scraper"))

node_client -->|"sends RPC"| node_router
node_router -->|"routes requests"| node_handlers
node_handlers -->|"validates key"| node_keystore
node_handlers -->|"probes method"| node_rpc
node_handlers -->|"reads runtime state"| node_appstate
node_appstate -.->|"holds routing state"| node_selection
node_handlers -->|"selects backend"| node_selection
node_handlers -->|"builds attempts"| node_upstream
node_upstream -->|"forwards RPC"| node_provider
node_provider -.->|"returns response"| node_handlers
node_config -.->|"configures runtime"| node_appstate
node_config -->|"chooses store"| node_keystore
node_keystore -->|"reads keys"| node_redis
node_admin -.->|"manages keys"| node_redis
node_healthloop -->|"probes backend"| node_provider
node_healthloop -->|"updates status"| node_healthstate
node_appstate -.->|"retains health"| node_healthstate
node_router -->|"exposes routes"| node_metrics
node_prometheus -.->|"scrapes metrics"| node_metrics
node_monitoring -.->|"visualizes metrics"| node_prometheus

click node_router "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/router.rs"
click node_handlers "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/handlers.rs"
click node_rpc "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/rpc.rs"
click node_appstate "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/state.rs"
click node_selection "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/state.rs"
click node_upstream "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/upstream.rs"
click node_config "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/config.rs"
click node_keystore "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/keystore.rs"
click node_admin "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/bin/rpc-admin.rs"
click node_healthloop "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/health.rs"
click node_healthstate "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/health.rs"
click node_metrics "https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/router.rs"
click node_monitoring "https://github.com/roborun-xyz/sol-rpc-router/blob/main/grafana/dashboards/sol-rpc-router.json"

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_router,node_handlers,node_rpc,node_appstate,node_client toneBlue
class node_selection,node_upstream,node_redis toneAmber
class node_config,node_keystore,node_admin toneMint
class node_healthloop,node_healthstate,node_metrics,node_monitoring toneRose
class node_provider,node_prometheus toneIndigo
```

## Components

### Gateway Entry

- [HTTP and WS Routers](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/router.rs): `src/router.rs`
- [Proxy and WS Handlers](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/handlers.rs): `src/handlers.rs`
- [RPC Parsing](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/rpc.rs): `src/rpc.rs`
- [Application State](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/state.rs): `src/state.rs`

### Routing and Upstreams

- [Backend Selection](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/state.rs): `src/state.rs`
- [Upstream Requests](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/upstream.rs): `src/upstream.rs`

### Identity and Config

- [Runtime Configuration](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/config.rs): `src/config.rs`
- [Key Stores](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/keystore.rs): `src/keystore.rs`
- [Key Administration](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/bin/rpc-admin.rs): `src/bin/rpc-admin.rs`

### Health and Observability

- [Health Probes](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/health.rs): `src/health.rs`
- [Backend Health State](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/health.rs): `src/health.rs`
- [Metrics and Health Routes](https://github.com/roborun-xyz/sol-rpc-router/blob/main/src/router.rs): `src/router.rs`
- [Grafana Dashboard](https://github.com/roborun-xyz/sol-rpc-router/blob/main/grafana/dashboards/sol-rpc-router.json): `grafana/dashboards/sol-rpc-router.json`

### Other components

- **RPC Client**
- **Solana Providers**
- **Redis**
- **Prometheus Scraper**

## Connections

- RPC Client → HTTP and WS Routers: sends RPC (evidence: `README.md`)
- HTTP and WS Routers → Proxy and WS Handlers: routes requests (evidence: `src/router.rs`)
- Proxy and WS Handlers → Key Stores: validates key (evidence: `README.md`)
- Proxy and WS Handlers → RPC Parsing: probes method (evidence: `README.md`)
- Proxy and WS Handlers → Application State: reads runtime state (evidence: `src/handlers.rs`)
- Application State → Backend Selection: holds routing state (evidence: `src/state.rs`)
- Proxy and WS Handlers → Backend Selection: selects backend (evidence: `README.md`)
- Proxy and WS Handlers → Upstream Requests: builds attempts (evidence: `src/handlers.rs`)
- Upstream Requests → Solana Providers: forwards RPC (evidence: `README.md`)
- Solana Providers → Proxy and WS Handlers: returns response
- Runtime Configuration → Application State: configures runtime
- Runtime Configuration → Key Stores: chooses store (evidence: `src/config.rs`)
- Key Stores → Redis: reads keys (evidence: `src/keystore.rs`)
- Key Administration → Redis: manages keys
- Health Probes → Solana Providers: probes backend (evidence: `src/health.rs`)
- Health Probes → Backend Health State: updates status (evidence: `src/health.rs`)
- Application State → Backend Health State: retains health
- HTTP and WS Routers → Metrics and Health Routes: exposes routes (evidence: `src/router.rs`)
- Prometheus Scraper → Metrics and Health Routes: scrapes metrics
- Grafana Dashboard → Prometheus Scraper: visualizes metrics
