# 0xradioac7iv/solrpc architecture

> Architecture diagram of the GitHub repository 0xradioac7iv/solrpc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-06-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/0xradioac7iv/solrpc
- Repository: https://github.com/0xradioac7iv/solrpc

## Overview

##### Project type and purpose
- This is a full-stack system composed of:
- A backend “aggregator” service (Node.js + TypeScript) that load-balances, caches, and failovers Solana RPC calls.
- A frontend dashboard (Next.js + React) for real-time analytics and configuration.

##### File structure
- Top level:
- README.md, vercel.json (deployment)
- /aggregator – the backend service with Dockerfile, tsconfig, package.json
- /frontend – the Next.js dashboard, with components, hooks, lib, types
- Backend (/aggregator/src):
- core/ – balancing.ts, caching.ts, stats.ts, server.ts, config.ts, logger.ts
- api/routes – HTTP route definitions (dashboardRouteGroup.ts)
- transport/ – http.ts for outbound RPC requests
- utils/ – cachePolicy, requestHandler, retry, validation
- index.ts – startup entrypoint
- Frontend (/frontend/src):
- app/ – Next.js pages under /dash (analytics, endpoints, networks, settings)
- components/ui – design primitives (button, card, chart, etc.)
- components – higher-level UI (Navbar, SearchBar, metrics, etc.)
- hooks, lib/store, types – state management and type definitions

##### README
- Describes features: latency optimization, failover, multiple load-balancing algorithms, caching (in-memory, Redis, Memcached), analytics dashboard.
- Local setup instructions for both services.

##### Detail
- Four balancing algorithms as options branching off the Load Balancer.
- Where caching policies apply (e.g., route through cachePolicy.ts).
- Docker container boundary and note environment configs.
- Loop: stats → dashboard → updated balancing strategy.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Clients
    Client["Clients / dApps"]:::frontend

    %% Aggregator Service Container
    subgraph "Aggregator Service (Docker)" 
        direction TB
        index["Entry Point (index.ts)"]:::backend
        DockerfileNode["Dockerfile & tsconfig"]:::backend

        subgraph "HTTP API Layer"
            APILayer["API Routes"]:::backend
        end

        subgraph "Core Modules"
            LB["Load Balancer"]:::backend
            Cache["Caching Layer"]:::backend
            Failover["Failover Logic"]:::backend
            Stats["Stats Collector"]:::backend
            Config["Config Management"]:::backend
            Logger["Logging Utility"]:::backend
        end

        subgraph "Transport Module"
            Transport["Transport (RPC Forwarding)"]:::backend
        end

        subgraph "Utilities"
            ReqHandler["Request Handler"]:::backend
            CachePolicy["Cache Policy"]:::backend
            Validation["Input Validation"]:::backend
        end
    end

    %% External Services
    subgraph "Solana RPC Endpoints"
        RPC1["Public RPC"]:::external
        RPC2["Private RPC"]:::external
    end

    subgraph "Caching Backends"
        Redis["Redis"]:::external
        Memcached["Memcached"]:::external
    end

    %% Frontend Dashboard
    subgraph "Frontend Dashboard"
        direction TB
        FEPage["Next.js App"]:::frontend
        Layout["Layout & Routing"]:::frontend
        Overview["Dashboard Overview"]:::frontend
        Analytics["Analytics Page"]:::frontend
        Endpoints["Endpoints Config Page"]:::frontend
        Networks["Networks Config Page"]:::frontend
        Settings["Settings Page"]:::frontend
        UIPrimitives["UI Primitives"]:::frontend
        UIComponents["Higher-level UI Components"]:::frontend
        Hooks["React Hooks"]:::frontend
        Store["State Management Store"]:::frontend
        TypesFE["Frontend Type Definitions"]:::frontend
        NextConfig["Next.js & Vercel Config"]:::frontend
    end

    %% Data Flows
    Client -->|"JSON-RPC over HTTP"| index
    index --> APILayer
    APILayer --> ReqHandler
    ReqHandler --> CachePolicy
    CachePolicy --> Cache
    Cache -->|hit| APILayer
    Cache -->|miss| LB
    LB --> Failover
    Failover --> Transport
    Transport --> RPC1
    Transport --> RPC2
    RPC1 --> Transport
    RPC2 --> Transport
    Transport --> Cache
    Transport --> Stats
    Stats --> APILayer
    APILayer --> index
    FEPage -->|"HTTP REST API"| APILayer
    Analytics --> FEPage
    Endpoints --> FEPage
    Networks --> FEPage
    Settings --> FEPage
    Overview --> FEPage

    %% Click Events
    click index "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/index.ts"
    click APILayer "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/api/routes/dashboardRouteGroup.ts"
    click LB "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/core/balancing.ts"
    click Cache "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/core/caching.ts"
    click Failover "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/utils/requestRetry.ts"
    click Stats "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/core/stats.ts"
    click Transport "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/transport/http.ts"
    click Config "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/core/config.ts"
    click Logger "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/core/logger.ts"
    click ReqHandler "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/utils/requestHandler.ts"
    click CachePolicy "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/utils/cachePolicy.ts"
    click Validation "https://github.com/0xradioac7iv/solrpc/blob/main/aggregator/src/utils/validate.ts"
    click DockerfileNode "https://github.com/0xradioac7iv/solrpc/tree/main/aggregator/Dockerfile"
    click FEPage "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/page.tsx"
    click Layout "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/layout.tsx"
    click Analytics "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/dash/analytics/page.tsx"
    click Endpoints "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/dash/endpoints/page.tsx"
    click Networks "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/dash/networks/page.tsx"
    click Settings "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/dash/settings/page.tsx"
    click Overview "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/app/dash/dashboard/page.tsx"
    click UIPrimitives "https://github.com/0xradioac7iv/solrpc/tree/main/frontend/src/components/ui"
    click UIComponents "https://github.com/0xradioac7iv/solrpc/tree/main/frontend/src/components"
    click Hooks "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/hooks/use-mobile.ts"
    click Store "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/lib/store.ts"
    click TypesFE "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/src/types/dashboard.ts"
    click NextConfig "https://github.com/0xradioac7iv/solrpc/blob/main/frontend/next.config.ts"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000
    classDef backend fill:#90EE90,stroke:#000
    classDef external fill:#FFA500,stroke:#000
```
