# tronscan/tronscan-api architecture

> Architecture diagram of the GitHub repository tronscan/tronscan-api, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/tronscan/tronscan-api
- Repository: https://github.com/tronscan/tronscan-api

## Overview

##### Main Components

a. External Interfaces:
- TRON Blockchain Network (Full Nodes/Solidity Nodes)
- Client Applications (Frontend)
- PostgreSQL Database
- Redis Cache

b. Core System Components:
- API Layer
- GRPC Services
- Blockchain Importers
- Network Scanner
- WebSocket Engine
- Transaction Builder

**[Client Layer]**
- ↑↓
**[API Gateway Layer]**
- ↑↓
**[Service Layer]**
- ↑↓
**[Data Access Layer]**
- ↑↓
**[External Services Layer]**

##### Component Details

API Gateway Layer (app/org/tronscan/api/):
- Swagger UI integration
- WebSocket connections for real-time updates

Service Layer:
- GRPC Services (app/org/tronscan/grpc/)
- Load balancer
- Full node client
- Solidity client
- Importers (app/org/tronscan/importer/)
- Block importer
- Account importer
- Database importer
- Network Scanner (app/org/tronscan/network/)
- Transaction Builder (app/org/tronscan/service/)

Data Access Layer:
- PostgreSQL Database (using Slick)
- Redis Cache
- Repository pattern implementation

External Services:
- TRON Network Nodes
- GeoIP Service
- Slack Integration

##### Key Interactions to Highlight

- Synchronous API calls
- Asynchronous streams
- Database operations
- Cache interactions
- Blockchain network communication

##### Technical Stack Indicators

Technology badges/labels for:
- Scala
- Play Framework
- Akka Streams
- GRPC
- PostgreSQL
- Redis
- Socket.io

##### Additional Elements

- Monitoring/logging flows
- Scale-out possibilities
- Failure handling paths
- Critical paths for high availability

- The reactive nature of the system
- The separation between blockchain interaction and API serving
- The caching strategy for performance
- The modular architecture allowing for easy scaling
- The security boundaries for transaction signing

Remember to use consistent styling and maintain a clear visual hierarchy to make the complex system easily understandable.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef client fill:#E1F5FE,stroke:#01579B
    classDef api fill:#E8F5E9,stroke:#2E7D32
    classDef service fill:#FFF3E0,stroke:#E65100
    classDef data fill:#F3E5F5,stroke:#4A148C
    classDef external fill:#EFEBE9,stroke:#3E2723
    classDef websocket fill:#FCE4EC,stroke:#880E4F
    classDef importer fill:#FFFDE7,stroke:#F57F17
    classDef network fill:#E0F2F1,stroke:#004D40

    %% Client Layer
    subgraph ClientLayer
        CLIENT[Client Applications]:::client
    end

    %% API Gateway Layer
    subgraph APILayer
        BaseAPI["Base API"]:::api
        RestAPI["REST Endpoints"]:::api
        SwaggerUI["Swagger UI"]:::api
        APIModels["API Models"]:::api
        TransactionAPI["Transaction API"]:::api
    end

    %% WebSocket Layer
    subgraph WebSocketLayer
        SocketEngine["Socket Engine"]:::websocket
        SocketCodecs["Socket Codecs"]:::websocket
    end

    %% Service Layer
    subgraph ServiceLayer
        GrpcBase["GRPC Base"]:::service
        LoadBalancer["Load Balancer"]:::service
        FullNode["Full Node Client"]:::service
        SolidityNode["Solidity Client"]:::service
        TransBuilder["Transaction Builder"]:::service
    end

    %% Importer Layer
    subgraph ImporterLayer
        ImportManager["Import Manager"]:::importer
        BlockImporter["Block Importer"]:::importer
        AccountImporter["Account Importer"]:::importer
        DBImporter["Database Importer"]:::importer
    end

    %% Network Layer
    subgraph NetworkLayer
        NetScanner["Network Scanner"]:::network
        NetStreams["Network Streams"]:::network
        NetNode["Network Node"]:::network
    end

    %% Data Access Layer
    subgraph DataLayer
        Repository["Repository Base"]:::data
        DBProfile["Database Profile"]:::data
        Models["Domain Models"]:::data
        BlockchainDomain["Blockchain Domain"]:::data
        DomainEvents["Domain Events"]:::data
        DomainTypes["Domain Types"]:::data
    end

    %% External Services
    subgraph ExternalLayer
        TronNetwork["TRON Network"]:::external
        PostgreSQL["PostgreSQL"]:::external
        Redis["Redis Cache"]:::external
        GeoIP["GeoIP Service"]:::external
        Slack["Slack Integration"]:::external
    end

    %% Relationships
    CLIENT <--> BaseAPI
    CLIENT <--> SocketEngine
    BaseAPI --> RestAPI
    BaseAPI --> SwaggerUI
    BaseAPI --> APIModels
    BaseAPI --> TransactionAPI
    
    SocketEngine --> SocketCodecs
    SocketEngine --> NetStreams
    
    RestAPI --> GrpcBase
    GrpcBase --> LoadBalancer
    LoadBalancer --> FullNode
    LoadBalancer --> SolidityNode
    
    ImportManager --> BlockImporter
    ImportManager --> AccountImporter
    ImportManager --> DBImporter
    
    NetScanner --> NetStreams
    NetStreams --> NetNode
    
    Repository --> DBProfile
    Repository --> Models
    Models --> BlockchainDomain
    BlockchainDomain --> DomainEvents
    BlockchainDomain --> DomainTypes
    
    FullNode --> TronNetwork
    SolidityNode --> TronNetwork
    Repository --> PostgreSQL
    Repository --> Redis
    NetNode --> GeoIP
    ImportManager --> Slack

    %% Click Events
    click BaseAPI "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/api/BaseApi.scala"
    click RestAPI "https://github.com/tronscan/tronscan-api/tree/develop/app/org/tronscan/api/"
    click SwaggerUI "https://github.com/tronscan/tronscan-api/tree/develop/public/swagger/"
    click APIModels "https://github.com/tronscan/tronscan-api/tree/develop/app/org/tronscan/api/models/"
    click GrpcBase "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/grpc/GrpcService.scala"
    click LoadBalancer "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/grpc/GrpcBalancer.scala"
    click FullNode "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/grpc/FullNodeClient.scala"
    click SolidityNode "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/grpc/SolidityClient.scala"
    click BlockImporter "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/importer/BlockImporter.scala"
    click AccountImporter "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/importer/AccountImporter.scala"
    click DBImporter "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/importer/DatabaseImporter.scala"
    click ImportManager "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/importer/ImportManager.scala"
    click NetScanner "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/network/NetworkScanner.scala"
    click NetStreams "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/network/NetworkStreams.scala"
    click NetNode "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/network/NetworkNode.scala"
    click TransBuilder "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/service/TransactionBuilder.scala"
    click TransactionAPI "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/api/TransactionBuilderApi.scala"
    click SocketEngine "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/websockets/SocketIOEngine.scala"
    click SocketCodecs "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/websockets/SocketCodecs.scala"
    click Repository "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/db/Repository.scala"
    click DBProfile "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/db/PgProfile.scala"
    click Models "https://github.com/tronscan/tronscan-api/tree/develop/app/org/tronscan/models/"
    click BlockchainDomain "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/domain/BlockChain.scala"
    click DomainEvents "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/domain/Events.scala"
    click DomainTypes "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/domain/Types.scala"
    click GeoIP "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/service/GeoIPService.scala"
    click Slack "https://github.com/tronscan/tronscan-api/blob/develop/app/org/tronscan/slack/SlackApi.scala"
```
