# harshbhargav45/routex- architecture

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

- Interactive diagram: https://gitdiagram.com/harshbhargav45/routex-
- Repository: https://github.com/harshbhargav45/routex-

## Overview

1. **What this repo is**
   RouteX is a **local Solana JSON-RPC router/proxy** with a separate **observability dashboard**. The backend sits in front of multiple upstream RPC providers and decides, per request, which provider is freshest and healthiest.

2. **Backend boundary and runtime**
   The root `src/` tree is the core Node.js/TypeScript service. `src/index.ts` is the main entrypoint, with `src/config.ts` for loading provider/runtime settings and `src/types.ts` for the shared domain model. The backend listens on the local RouteX port and exposes both the proxy and API endpoints.

3. **Provider configuration**
   Providers are defined in `routex.providers.json` / example JSON and modeled as records with:
   - `rpcUrl` for standard JSON-RPC
   - optional `yellowstoneUrl` + `token` for gRPC slot streaming
   - `writeEnabled`
   - `priorityBias`
   - cluster/tags metadata  
   This config is the main external boundary for the system: it tells RouteX which Solana nodes it can route to.

4. **Freshness and health monitoring**
   `src/monitor.ts` is the subsystem that watches provider freshness and health. The README shows two acquisition modes:
   - **Yellowstone gRPC streaming** for low-latency slot updates
   - **RPC polling** for providers without gRPC  
   This monitoring layer feeds live provider state into the router and the dashboard.

5. **Scoring and selection**
   `src/scoring.ts` turns monitoring data into a ranked provider list. The README describes a weighted score based on slot lag, latency, errors, failures, and priority bias. This is the key decision engine: lower score means better routing candidate.

6. **Proxy and failover path**
   `src/rpc.ts` is the request-routing layer. Incoming JSON-RPC calls are classified into request types such as read, fresh-read, and write, then forwarded to the best provider that satisfies the request’s freshness/writability requirements. If the chosen provider fails, RouteX retries with the next-ranked provider.

7. **State and observability**
   `src/store.ts` appears to hold the live system state: provider snapshots, route decisions, events, and metrics that the rest of the backend and the UI consume. This is the shared internal boundary between monitoring, scoring, routing, and external APIs.

8. **Operational API surface**
   The backend exposes operational endpoints called out in the README:
   - `POST /rpc` for JSON-RPC proxying
   - `GET /api/health`
   - `GET /api/metrics`
   - `GET /api/events`
   - `GET /api/routes`
   - `GET /`
   - `GET /legacy` for the built-in dashboard  
   These are what the frontend and operators use to inspect route decisions and provider health.

9. **Backend demo and local simulation**
   `src/mock-cluster.ts` and `src/demo.ts` support a **local mock Solana cluster** so the router can be exercised without real RPC keys. The root `scripts/benchmark.ts` drives stress/benchmark testing against the router. This makes the repo usable both for production routing and for isolated local demos.

10. **Frontend boundary**
   `frontend/` is a separate React + Vite application. It is not the proxy itself; it is an external dashboard client that talks to the backend APIs. The README notes it runs on a different local port and can be deployed separately, with CORS controlled by `ROUTEX_ALLOWED_ORIGINS`.

11. **Frontend composition**
   The frontend has two visible layers:
   - `src/pages/Index.tsx`, `Features.tsx`, `FeatureDetail.tsx`, `NotFound.tsx` for site pages
   - `src/pages/AppDashboard.tsx` plus `src/components/dashboard/*` for the live RouteX dashboard  
   The dashboard panels map directly to backend concepts: provider tables, metrics HUD, routing explanation, traffic/events, failover banner, race view, and manual probing.

12. **Frontend data flow**
   The dashboard consumes the backend’s health/metrics/routes/events APIs and renders the current routing state. The `dashboard` components are presentation slices over the same backend state model, while `src/lib/routex-api.ts` is the client-side integration point.

13. **UI/supporting structure**
   The frontend also contains a reusable UI kit under `src/components/ui/`, a site shell/theme layer under `src/components/site/`, and shared hooks/utilities. These are implementation details of the dashboard shell, not separate architectural services.

14. **Important deployment picture**
   The architecture diagram should show:
   - Solana client/app → `POST /rpc` → RouteX backend
   - RouteX backend → upstream RPC/gRPC providers
   - RouteX backend → `/api/*` endpoints → React dashboard
   - Optional mock cluster → RouteX demo mode  
   The core value is the routing decision loop: monitor freshness, score providers, route each request, observe outcomes, and feed that back into the next decision.

Main entry points: [`src/store.ts`](https://github.com/harshbhargav45/routex-/blob/main/src/store.ts) (State store), [`src/index.ts`](https://github.com/harshbhargav45/routex-/blob/main/src/index.ts) (Entry), [`src/rpc.ts`](https://github.com/harshbhargav45/routex-/blob/main/src/rpc.ts) (Proxy router), [`src/scoring.ts`](https://github.com/harshbhargav45/routex-/blob/main/src/scoring.ts) (Scoring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["RouteX backend"]
  node_src_index["Entry<br/>[index.ts]"]
  node_src_config["Config<br/>[config.ts]"]
  node_src_types["Domain types<br/>shared model<br/>[types.ts]"]
  node_src_store[("State store<br/>live state<br/>[store.ts]")]
  node_src_monitor(("Monitor<br/>health watcher<br/>[monitor.ts]"))
  node_src_scoring{{"Scoring<br/>ranking engine<br/>[scoring.ts]"}}
  node_src_rpc["Proxy router<br/>request router<br/>[rpc.ts]"]
  node_src_dashboard["API surface<br/>ops api<br/>[dashboard.ts]"]
end

subgraph group_ui["Dashboard frontend"]
  node_frontend_main["Frontend entry<br/>ui entrypoint<br/>[main.tsx]"]
  node_frontend_api["API client<br/>frontend integration<br/>[routex-api.ts]"]
  node_frontend_dashboard["Dashboard page<br/>[AppDashboard.tsx]"]
  node_frontend_pages["Site pages<br/>marketing pages<br/>[Index.tsx]"]
  node_frontend_panelset["Panels<br/>dashboard components<br/>[ProvidersTable.tsx]"]
  node_frontend_shell["Site shell<br/>ui shell<br/>[SiteShell.tsx]"]
  node_frontend_ui["UI kit<br/>design system<br/>[button.tsx]"]
end

subgraph group_demo["Demo and benchmark"]
  node_src_mock_cluster[("Mock cluster<br/>simulation backend<br/>[mock-cluster.ts]")]
  node_src_demo["Demo mode<br/>demo runner<br/>[demo.ts]"]
  node_scripts_benchmark["Benchmark<br/>load test<br/>[benchmark.ts]"]
end

node_src_index -->|"loads"| node_src_config
node_src_index -->|"initializes"| node_src_store
node_src_index -->|"starts"| node_src_monitor
node_src_index -->|"uses"| node_src_scoring
node_src_index -->|"serves"| node_src_rpc
node_src_index -->|"serves"| node_src_dashboard
node_src_config -->|"provider inputs"| node_src_monitor
node_src_types -->|"shapes"| node_src_monitor
node_src_types -->|"shapes"| node_src_scoring
node_src_types -->|"shapes"| node_src_rpc
node_src_store -->|"updates"| node_src_monitor
node_src_store -->|"feeds"| node_src_scoring
node_src_store -->|"serves"| node_src_rpc
node_src_monitor -->|"publishes"| node_src_store
node_src_scoring -->|"publishes"| node_src_store
node_src_scoring -->|"ranks for"| node_src_rpc
node_src_rpc -->|"records"| node_src_store
node_src_dashboard -->|"reads"| node_src_store
node_frontend_main -->|"mounts"| node_frontend_dashboard
node_frontend_dashboard -->|"calls"| node_frontend_api
node_frontend_dashboard -->|"renders"| node_frontend_panelset
node_frontend_pages -->|"wraps"| node_frontend_shell
node_frontend_shell -->|"uses"| node_frontend_ui
node_frontend_api -->|"consumes"| node_src_dashboard
node_src_demo -->|"drives"| node_src_mock_cluster
node_scripts_benchmark -->|"stresses"| node_src_rpc

click node_src_index "https://github.com/harshbhargav45/routex-/blob/main/src/index.ts"
click node_src_config "https://github.com/harshbhargav45/routex-/blob/main/src/config.ts"
click node_src_types "https://github.com/harshbhargav45/routex-/blob/main/src/types.ts"
click node_src_store "https://github.com/harshbhargav45/routex-/blob/main/src/store.ts"
click node_src_monitor "https://github.com/harshbhargav45/routex-/blob/main/src/monitor.ts"
click node_src_scoring "https://github.com/harshbhargav45/routex-/blob/main/src/scoring.ts"
click node_src_rpc "https://github.com/harshbhargav45/routex-/blob/main/src/rpc.ts"
click node_src_dashboard "https://github.com/harshbhargav45/routex-/blob/main/src/dashboard.ts"
click node_src_mock_cluster "https://github.com/harshbhargav45/routex-/blob/main/src/mock-cluster.ts"
click node_src_demo "https://github.com/harshbhargav45/routex-/blob/main/src/demo.ts"
click node_scripts_benchmark "https://github.com/harshbhargav45/routex-/blob/main/scripts/benchmark.ts"
click node_frontend_main "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/main.tsx"
click node_frontend_api "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/lib/routex-api.ts"
click node_frontend_dashboard "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/pages/AppDashboard.tsx"
click node_frontend_pages "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/pages/Index.tsx"
click node_frontend_panelset "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/components/dashboard/ProvidersTable.tsx"
click node_frontend_shell "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/components/site/SiteShell.tsx"
click node_frontend_ui "https://github.com/harshbhargav45/routex-/blob/main/frontend/src/components/ui/button.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_src_index,node_src_config,node_src_types,node_src_store,node_src_monitor,node_src_scoring,node_src_rpc,node_src_dashboard toneBlue
class node_frontend_main,node_frontend_api,node_frontend_dashboard,node_frontend_pages,node_frontend_panelset,node_frontend_shell,node_frontend_ui toneAmber
class node_src_mock_cluster,node_src_demo,node_scripts_benchmark toneMint
```

## Components

### RouteX backend

Node.js/TypeScript proxy, routing, and operational API

- [Entry](https://github.com/harshbhargav45/routex-/blob/main/src/index.ts): service entrypoint · Bootstraps the backend server and exposes proxy/API routes · `src/index.ts`
- [Config](https://github.com/harshbhargav45/routex-/blob/main/src/config.ts): runtime config · Loads provider and server settings · `src/config.ts`
- [Domain types](https://github.com/harshbhargav45/routex-/blob/main/src/types.ts): shared model · Shared provider, request, and state types · `src/types.ts`
- [State store](https://github.com/harshbhargav45/routex-/blob/main/src/store.ts): live state · Holds provider snapshots, routes, events, and metrics · `src/store.ts`
- [Monitor](https://github.com/harshbhargav45/routex-/blob/main/src/monitor.ts): health watcher · Tracks provider freshness and health via gRPC streaming or RPC polling · `src/monitor.ts`
- [Scoring](https://github.com/harshbhargav45/routex-/blob/main/src/scoring.ts): ranking engine · Ranks providers using lag, latency, errors, failures, and bias · `src/scoring.ts`
- [Proxy router](https://github.com/harshbhargav45/routex-/blob/main/src/rpc.ts): request router · Classifies JSON-RPC calls and forwards them with failover · `src/rpc.ts`
- [API surface](https://github.com/harshbhargav45/routex-/blob/main/src/dashboard.ts): ops api · Serves health, metrics, events, routes, and dashboard endpoints · `src/dashboard.ts`

### Dashboard frontend

React/Vite observability client

- [Frontend entry](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/main.tsx): ui entrypoint · Bootstraps the React dashboard app · `frontend/src/main.tsx`
- [API client](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/lib/routex-api.ts): frontend integration · Client wrapper for backend health, metrics, routes, and events APIs · `frontend/src/lib/routex-api.ts`
- [Dashboard page](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/pages/AppDashboard.tsx): dashboard page · Main observability view over RouteX routing state · `frontend/src/pages/AppDashboard.tsx`
- [Site pages](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/pages/Index.tsx): marketing pages · Public site and fallback pages · `frontend/src/pages/Index.tsx`
- [Panels](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/components/dashboard/ProvidersTable.tsx): dashboard components · Provider, metrics, routing, traffic, failover, and probe panels · `frontend/src/components/dashboard/ProvidersTable.tsx`
- [Site shell](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/components/site/SiteShell.tsx): ui shell · Shared navigation, theme, and page chrome · `frontend/src/components/site/SiteShell.tsx`
- [UI kit](https://github.com/harshbhargav45/routex-/blob/main/frontend/src/components/ui/button.tsx): design system · Reusable component primitives used across the frontend · `frontend/src/components/ui/button.tsx`

### Demo and benchmark

Local simulation and load-testing support

- [Mock cluster](https://github.com/harshbhargav45/routex-/blob/main/src/mock-cluster.ts): simulation backend · Local Solana cluster used for demos and testing · `src/mock-cluster.ts`
- [Demo mode](https://github.com/harshbhargav45/routex-/blob/main/src/demo.ts): demo runner · Wires the router to the mock cluster for local walkthroughs · `src/demo.ts`
- [Benchmark](https://github.com/harshbhargav45/routex-/blob/main/scripts/benchmark.ts): load test · Drives benchmark and stress runs against the router · `scripts/benchmark.ts`

## Connections

- Entry → Config: loads · Boot reads runtime and provider settings
- Entry → State store: initializes · Creates shared live state for the backend
- Entry → Monitor: starts · Launches freshness and health monitoring
- Entry → Scoring: uses · Installs ranking logic for provider selection
- Entry → Proxy router: serves · Exposes the JSON-RPC proxy path
- Entry → API surface: serves · Exposes operational and dashboard endpoints
- Config → Monitor: provider inputs · Supplies RPC/gRPC endpoints and tags
- Domain types → Monitor: shapes · Shared monitoring state and provider records
- Domain types → Scoring: shapes · Shared ranking inputs and outputs
- Domain types → Proxy router: shapes · Shared request and routing types
- State store → Monitor: updates · Receives live provider snapshots
- State store → Scoring: feeds · Provides current health and freshness state
- State store → Proxy router: serves · Gives router the ranked state and route history
- Monitor → State store: publishes · Writes health and freshness updates
- Scoring → State store: publishes · Writes ranked provider decisions
- Scoring → Proxy router: ranks for · Provides provider ordering for each request type
- Proxy router → State store: records · Stores route decisions and failures
- API surface → State store: reads · Serves current state to operators and UI clients
- Frontend entry → Dashboard page: mounts · Loads the dashboard application
- Dashboard page → API client: calls · Fetches backend metrics and routing state
- Dashboard page → Panels: renders · Composes observability panels
- Site pages → Site shell: wraps · Uses shared page chrome and site layout
- Site shell → UI kit: uses · Builds the interface from reusable primitives
- API client → API surface: consumes · Reads the backend operational endpoints
- Demo mode → Mock cluster: drives · Connects router demo mode to the local cluster
- Benchmark → Proxy router: stresses · Benchmarks the routing and failover path
