# shreyas-itb/verusstatisticsapi architecture

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

- Interactive diagram: https://gitdiagram.com/shreyas-itb/verusstatisticsapi
- Repository: https://github.com/shreyas-itb/verusstatisticsapi

## Overview

##### Project Type and Purpose
This is a RESTful API service designed to provide statistical and operational data about the VerusCoin blockchain, specifically focusing on the verus-ethereum bridge and transaction handling.

##### Main Components

A. Core API Layer:
- FastAPI Application Server (app.py)
- Endpoint Handlers (endpoints/index.py)
- Function Modules (functions/)

B. External Services:
- VerusCoin Node/RPC
- Ethereum Node/RPC
- CoinGecko API
- Yahoo Finance API
- Etherscan API

C. Data Processing Components:
- Transaction Processors
- Balance Calculators
- Volume Aggregators
- Price Fetchers

**[External Clients] → [Load Balancer/Reverse Proxy]**

**[FastAPI Application Server]**
- Main Routes
- Market Routes
- Utility Routes

**[Core Functions]**
- Blockchain Interaction
- Transaction Decoders
- Block Processors
- Balance Calculators
- Market Data
- Price Fetchers
- Volume Calculators
- Reserve Handlers
- Utility Functions
- Data Formatters
- Cache Handlers

**[External Services]**
- VerusCoin Network
- Ethereum Network
- Price APIs
- Block Explorers

##### Additional Elements

a) A Cache Layer:
**[Cache]**
- Transaction Cache
- Price Cache

b) Error Handling Flows:
**[Error Handlers]**
- API Errors
- Network Errors
- Data Validation

##### Implementation Details

**[Client Applications] → [API Gateway]**
- ↓
**[FastAPI Application (app.py)]**
- ↓
**[Endpoint Handlers (endpoints/index.py)]**
- ↓
**[Function Modules]**
- Transaction Processing
- decoderawtransaction.py
- extracttransfers.py
- processtxnstaking.py
- Market Data
- getcurrencyprices.py
- markettickers.py
- getvolinfo.py
- Blockchain Interface
- latestblock.py
- getimports.py
- reserves.py
- ↓
**[External Services]**
- VerusCoin RPC
- Ethereum RPC
- CoinGecko API
- Yahoo Finance API

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client["Client Layer"]
        CL["Client Applications"]
    end

    subgraph API["API Layer"]
        API_GW["API Gateway"]
        FAPI["FastAPI Server"]:::fastapi
        EP["Endpoint Handlers"]:::endpoints
    end

    subgraph Functions["Function Layer"]
        subgraph TX["Transaction Processing"]
            DRT["Decode Raw Transaction"]:::txproc
            ET["Extract Transfers"]:::txproc
            PTS["Process TX Staking"]:::txproc
            PTC["Process TX Coinbase"]:::txproc
        end

        subgraph BAL["Balance Management"]
            CRB["Calculate Reserve Balance"]:::balance
            CTB["Calculate Total Balances"]:::balance
            GAB["Get Address Balance"]:::balance
            GEB["Get ETH Balance"]:::balance
            GTB["Get Token Balance"]:::balance
        end

        subgraph MKT["Market Data"]
            GCP["Get Currency Prices"]:::market
            MT["Market Tickers"]:::market
            GVI["Volume Info"]:::market
            TF["Ticker Functions"]:::market
        end

        subgraph BCI["Blockchain Interface"]
            LB["Latest Block"]:::blockchain
            GI["Get Imports"]:::blockchain
            RES["Reserves"]:::blockchain
            FBP["Fetch Block & Process"]:::blockchain
        end

        subgraph RSV["Reserve Management"]
            AR["Aggregate Reserves"]:::reserve
            GCR["Get Currency Reserves"]:::reserve
            GVR["Get VRSC Reserves"]:::reserve
            GBB["Get Bridge Baskets"]:::reserve
        end

        subgraph UTIL["Utilities"]
            FD["Format Difficulty"]:::util
            FH["Format Hashrate"]:::util
            SCD["Save Cache Data"]:::util
            SR["Send Request"]:::util
        end

        subgraph CFG["Configuration"]
            VARS["Variables"]:::config
            DICT["Dictionaries"]:::config
        end
    end

    subgraph External["External Services"]
        VRPC["VerusCoin RPC"]:::external
        ERPC["Ethereum RPC"]:::external
        CG["CoinGecko API"]:::external
        YF["Yahoo Finance API"]:::external
        ES["Etherscan API"]:::external
    end

    %% Connections
    CL --> API_GW
    API_GW --> FAPI
    FAPI --> EP

    EP --> TX
    EP --> BAL
    EP --> MKT
    EP --> BCI
    EP --> RSV
    EP --> UTIL

    TX --> VRPC
    BAL --> VRPC
    BAL --> ERPC
    MKT --> CG
    MKT --> YF
    BCI --> VRPC
    BCI --> ERPC
    RSV --> VRPC
    BAL --> ES

    %% Styles
    classDef fastapi fill:#1abc9c
    classDef endpoints fill:#2ecc71
    classDef txproc fill:#3498db
    classDef balance fill:#9b59b6
    classDef market fill:#f1c40f
    classDef blockchain fill:#e67e22
    classDef reserve fill:#e74c3c
    classDef util fill:#95a5a6
    classDef config fill:#7f8c8d
    classDef external fill:#34495e

    %% Click Events
    click FAPI "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/app.py"
    click EP "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/endpoints/index.py"
    click DRT "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/decoderawtransaction.py"
    click ET "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/extracttransfers.py"
    click PTS "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/processtxnstaking.py"
    click PTC "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/processtxncoinbase.py"
    click CRB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/calcreservebalance.py"
    click CTB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/calctotalbalances.py"
    click GAB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getaddressbalance.py"
    click GEB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getethbalance.py"
    click GTB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/gettokenbalance.py"
    click GCP "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getcurrencyprices.py"
    click MT "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/markettickers.py"
    click GVI "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getvolinfo.py"
    click TF "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/tickerfunc.py"
    click LB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/latestblock.py"
    click GI "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getimports.py"
    click RES "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/reserves.py"
    click FBP "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/fetchblocknprocess.py"
    click AR "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/aggregatereserves.py"
    click GCR "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getcurrencyreserves.py"
    click GVR "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getvrscreservesfrmbaskets.py"
    click GBB "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/getbridgecurrencybaskets.py"
    click FD "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/formatdifficulty.py"
    click FH "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/formathashrate.py"
    click SCD "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/savecachedata.py"
    click SR "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/functions/send_request.py"
    click VARS "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/var/vars.py"
    click DICT "https://github.com/Shreyas-ITB/VerusStatisticsAPI/blob/main/var/dict.py"
```
