# jmcph4/blocktop architecture

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

- Interactive diagram: https://gitdiagram.com/jmcph4/blocktop
- Repository: https://github.com/jmcph4/blocktop

## Overview

Key Components to Include:

##### External Systems
- Ethereum Network (via WebSocket/Unix socket RPC)
- Etherscan (for external block/transaction viewing)

##### Core Application Components
- Client Module (src/client.rs)
- Database Module (src/db.rs)
- UI Module (src/ui/)
- Services Module (src/services/)
- CLI Interface (src/cli.rs)

##### Component Representation

a. External Services Layer:

b. Application Core Layer:
- Client Module (handles RPC communication)
- Services Module (contains blockchain service)
- UI Module (with nested components for app and stateful list)
- CLI Module (handles command-line interface)

c. Storage Layer:

##### Connection and Data Flow
- Real-time block data flow (WebSocket)
- User interface interactions
- Database operations
- External system calls

##### Technical Details
- SQLite as the database technology
- TUI components and their relationships

##### Additional Elements
- Version/alpha status indicator

##### The optional persistent storage capability

Remember to:
- Clear labels for all components
- Both data and control flow
- Asynchronous operations
- Primary user interaction points

This design should capture both the architectural complexity and the straightforward user experience of the application, while making it clear how the different components interact to provide real-time blockchain exploration functionality.

## Diagram (Mermaid)

```mermaid
graph TB
    %% External Services Layer
    subgraph External
        EN[Ethereum Node]
        ES[Etherscan]
    end

    %% Application Core Layer
    subgraph Blocktop["Blocktop Application"]
        direction TB
        
        %% Main Entry
        ME["Main Entry"]:::core
        
        %% Core Components
        CLI["CLI Interface"]:::core
        
        %% Client and Services
        subgraph CoreServices["Core Services"]
            direction TB
            CM["Client Module"]:::core
            SM["Services Module"]:::core
            BS["Blockchain Service"]:::core
        end
        
        %% UI Components
        subgraph UserInterface["UI Layer"]
            direction TB
            UI["UI Module"]:::ui
            UA["UI App"]:::ui
            USL["UI Stateful List"]:::ui
        end
        
        %% Utils
        UT["Utility Functions"]:::util
    end
    
    %% Storage Layer
    subgraph Storage
        DB["Database Module"]:::storage
        SQ[(SQLite)]:::storage
    end
    
    %% Connections
    EN -.->|WebSocket/Unix Socket| CM
    ES -.->|External Data| BS
    CM -->|Block Data| BS
    BS -->|Processed Data| UA
    CLI -->|Commands| ME
    ME -->|Initialize| CM
    ME -->|Setup| UI
    UI -->|Render| UA
    UA -->|Display| USL
    BS -->|Store| DB
    DB -->|Persist| SQ
    
    %% Styles
    classDef core fill:#90EE90,stroke:#333,stroke-width:2px
    classDef ui fill:#FFE4B5,stroke:#333,stroke-width:2px
    classDef storage fill:#A9A9A9,stroke:#333,stroke-width:2px
    classDef util fill:#B0C4DE,stroke:#333,stroke-width:2px
    
    %% Click Events
    click CM "https://github.com/jmcph4/blocktop/blob/master/src/client.rs"
    click DB "https://github.com/jmcph4/blocktop/blob/master/src/db.rs"
    click UI "https://github.com/jmcph4/blocktop/tree/master/src/ui/"
    click UA "https://github.com/jmcph4/blocktop/blob/master/src/ui/app.rs"
    click USL "https://github.com/jmcph4/blocktop/blob/master/src/ui/components/stateful_list.rs"
    click SM "https://github.com/jmcph4/blocktop/tree/master/src/services/"
    click BS "https://github.com/jmcph4/blocktop/blob/master/src/services/blockchain.rs"
    click CLI "https://github.com/jmcph4/blocktop/blob/master/src/cli.rs"
    click ME "https://github.com/jmcph4/blocktop/blob/master/src/main.rs"
    click UT "https://github.com/jmcph4/blocktop/blob/master/src/utils.rs"
    
    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[UI Components]:::ui
        L3[Storage Components]:::storage
        L4[Utility Components]:::util
    end
```
