How harshbhargav45/routex- works
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: store.ts State store · index.ts Entry · rpc.ts Proxy router · scoring.ts Scoring
Components 18
RouteX backend
Node.js/TypeScript proxy, routing, and operational API
- Entry · Bootstraps the backend server and exposes proxy/API routes
src/index.ts - Config · Loads provider and server settings
src/config.ts - Domain types · Shared provider, request, and state types
src/types.ts - State store · Holds provider snapshots, routes, events, and metrics
src/store.ts - Monitor · Tracks provider freshness and health via gRPC streaming or RPC polling
src/monitor.ts - Scoring · Ranks providers using lag, latency, errors, failures, and bias
src/scoring.ts - Proxy router · Classifies JSON-RPC calls and forwards them with failover
src/rpc.ts - API surface · Serves health, metrics, events, routes, and dashboard endpoints
src/dashboard.ts
Dashboard frontend
React/Vite observability client
- Frontend entry · Bootstraps the React dashboard app
frontend/src/main.tsx - API client · Client wrapper for backend health, metrics, routes, and events APIs
frontend/src/lib/routex-api.ts - Dashboard page · Main observability view over RouteX routing state
frontend/src/pages/AppDashboard.tsx - Site pages · Public site and fallback pages
frontend/src/pages/Index.tsx - Panels · Provider, metrics, routing, traffic, failover, and probe panels
frontend/src/components/dashboard/ProvidersTable.tsx - Site shell · Shared navigation, theme, and page chrome
frontend/src/components/site/SiteShell.tsx - UI kit · Reusable component primitives used across the frontend
frontend/src/components/ui/button.tsx
Demo and benchmark
Local simulation and load-testing support
- Mock cluster · Local Solana cluster used for demos and testing
src/mock-cluster.ts - Demo mode · Wires the router to the mock cluster for local walkthroughs
src/demo.ts - Benchmark · Drives benchmark and stress runs against the router
scripts/benchmark.ts
Connections 26
- 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