# janoside/btc-rpc-explorer architecture

> Architecture diagram of the GitHub repository janoside/btc-rpc-explorer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/janoside/btc-rpc-explorer
- Repository: https://github.com/janoside/btc-rpc-explorer

## Overview

##### Component Details and Relationships

a) Frontend Layer (Top):
- Static Assets (/public)
- View Templates (/views)
- Client-side JavaScript
- Connection to main application server

b) Application Server (Middle):
- Connection to various API services
- Authentication middleware
- Performance monitoring components

c) Data Layer (Bottom):
- Bitcoin Core RPC connection
- Redis cache
- External API connections

##### Key Flows to Highlight

a) Primary Data Flows:
- Bitcoin data retrieval flow
- Caching mechanisms
- API request handling
- User authentication flow

b) Secondary Flows:
- Performance monitoring
- Static asset serving
- External API fallbacks

##### Component Breakdown

Core Application (app/):
**┌─────────────────────────┐**
- Web Application      │
- ┤
- API Layer            │
- Authentication       │
- Caching             │
- Performance Monitor  │
- ┘

API Services (app/api/):
**┌─────────────────────────┐**
- API Services        │
- ┤
- Core RPC API         │
- Address APIs         │
- Blockchain APIs      │
- ┘

##### Notes for Implementation

- Version compatibility notes
- Scaling points (Redis cache, API layers)

##### The separation between core and optional features

Remember to include version information and system requirements in supplementary documentation.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph External["External Services"]
        direction TB
        BTC[Bitcoin Core Node]:::external
        ELE[Electrum Servers]:::external
        EXT["External APIs<br>(Blockchair/Blockcypher)"]:::external
    end

    subgraph Frontend["Frontend Layer"]
        direction TB
        STATIC["Static Assets"]:::frontend
        VIEWS["View Templates"]:::frontend
        CLIENT["Client-side JavaScript"]:::frontend
    end
    click STATIC "https://github.com/janoside/btc-rpc-explorer/tree/master/public/"
    click VIEWS "https://github.com/janoside/btc-rpc-explorer/tree/master/views/"
    click CLIENT "https://github.com/janoside/btc-rpc-explorer/blob/master/public/js/site.js"

    subgraph Server["Application Server"]
        direction TB
        WEB["Web Server<br>(Express.js)"]:::core
        
        subgraph Routes["Route Handlers"]
            direction TB
            ADMIN["Admin Router"]:::router
            API["API Router"]:::router
            BASE["Base Router"]:::router
            INTERNAL["Internal API Router"]:::router
        end
        
        subgraph Auth["Authentication"]
            direction TB
            AUTH["Auth System"]:::security
            SSO["SSO Handler"]:::security
            CRED["Credentials"]:::security
        end
        
        subgraph Monitor["Performance Monitoring"]
            direction TB
            PERF["Action Monitor"]:::monitor
            SYS["System Monitor"]:::monitor
            STATS["App Stats"]:::monitor
            TRACK["Stat Tracker"]:::monitor
        end
    end
    click WEB "https://github.com/janoside/btc-rpc-explorer/blob/master/app.js"
    click ADMIN "https://github.com/janoside/btc-rpc-explorer/blob/master/routes/adminRouter.js"
    click API "https://github.com/janoside/btc-rpc-explorer/blob/master/routes/apiRouter.js"
    click BASE "https://github.com/janoside/btc-rpc-explorer/blob/master/routes/baseRouter.js"
    click INTERNAL "https://github.com/janoside/btc-rpc-explorer/blob/master/routes/internalApiRouter.js"
    click AUTH "https://github.com/janoside/btc-rpc-explorer/blob/master/app/auth.js"
    click SSO "https://github.com/janoside/btc-rpc-explorer/blob/master/app/sso.js"
    click CRED "https://github.com/janoside/btc-rpc-explorer/blob/master/app/credentials.js"
    click PERF "https://github.com/janoside/btc-rpc-explorer/blob/master/app/actionPerformanceMonitor.js"
    click SYS "https://github.com/janoside/btc-rpc-explorer/blob/master/app/systemMonitor.js"
    click STATS "https://github.com/janoside/btc-rpc-explorer/blob/master/app/appStats.js"
    click TRACK "https://github.com/janoside/btc-rpc-explorer/blob/master/app/statTracker.js"

    subgraph Data["Data Layer"]
        direction TB
        subgraph Cache["Caching Layer"]
            direction TB
            REDIS["Redis Cache"]:::cache
            CACHEU["Cache Utils"]:::cache
        end
        
        subgraph APIs["API Services"]
            direction TB
            RPC["RPC Interface"]:::api
            CORE["Core API"]:::api
            ADDR["Address API"]:::api
            BLOCK["Blockchain API"]:::api
            CHAIR["Blockchair API"]:::api
            CYPHER["Blockcypher API"]:::api
            ELEC["Electrum API"]:::api
        end
        
        CONFIG["Configuration"]:::config
    end
    click REDIS "https://github.com/janoside/btc-rpc-explorer/blob/master/app/redisCache.js"
    click CACHEU "https://github.com/janoside/btc-rpc-explorer/blob/master/app/cacheUtils.js"
    click RPC "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/rpcApi.js"
    click CORE "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/coreApi.js"
    click ADDR "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/addressApi.js"
    click BLOCK "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/blockchainAddressApi.js"
    click CHAIR "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/blockchairAddressApi.js"
    click CYPHER "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/blockcypherAddressApi.js"
    click ELEC "https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/electrumAddressApi.js"
    click CONFIG "https://github.com/janoside/btc-rpc-explorer/blob/master/app/config.js"

    %% Connections
    BTC --> RPC
    ELE -.-> ELEC
    EXT -.-> APIs
    
    Frontend --> WEB
    WEB --> Routes
    Routes --> Auth
    Routes --> APIs
    
    APIs --> Cache
    APIs --> BTC
    
    Monitor --> WEB
    
    %% Styles
    classDef external fill:#90EE90,stroke:#333,stroke-width:2px
    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:2px
    classDef core fill:#4169E1,stroke:#333,stroke-width:2px,color:#fff
    classDef router fill:#6495ED,stroke:#333,stroke-width:2px
    classDef security fill:#FF6B6B,stroke:#333,stroke-width:2px
    classDef monitor fill:#FFD700,stroke:#333,stroke-width:2px
    classDef cache fill:#DDA0DD,stroke:#333,stroke-width:2px
    classDef api fill:#20B2AA,stroke:#333,stroke-width:2px
    classDef config fill:#F0E68C,stroke:#333,stroke-width:2px
```
