# ndavd/bop architecture

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

- Interactive diagram: https://gitdiagram.com/ndavd/bop
- Repository: https://github.com/ndavd/bop

## Overview

##### Project Type and Purpose
- This is a command-line (REPL) multichain portfolio tracker supporting several blockchains (EVM, Solana, Ton, etc.).
- It fetches portfolio data locally and uses RPC calls to interact with blockchains and API calls (via Dexscreener) for token pricing.
- The data is stored locally (in an encrypted configuration file) and accessed in memory during REPL sessions.

##### Analyzing the File Structure
- The top-level directories include .github for workflows (CI/CD) and src, which contains the application’s source code.
- Under src, key directories include:
- chain – Implements chain-specific functionalities such as properties, handling different blockchain types (evm, sol, ton, etc.).
- dexscreener – Handles the interactions with the external DEX Screener API to retrieve token price information.
- repl – Contains the interactive REPL logic (command parsing, session management, data encryption/decryption, and input/output handling).
- utils – Provides supporting functions for tasks like text formatting, retry logic, and displaying spinners to indicate loading.
- The presence of Cargo.toml, Cargo.lock, etc., confirms it is a Rust project with dependency management.

a. Main Entry Point:
- ‘src/main.rs’ as the central starting module which initializes the application.

b. REPL Interface:
- REPL module (src/repl) as the primary user interface. It handles user commands, reads the local encrypted data file (.bop-data), and orchestrates interactions among various components.

c. Chain Module:
- ‘chain’ directory with submodules (chain_properties, chain_type, evm_chain, sol_chain, ton_chain, token, etc.). This module acts as an abstraction layer for querying different blockchains using RPC.
- That it is designed to allow swapping of default RPCs with custom ones.

d. Dexscreener Module:
- Dexscreener module, which interfaces with the Dexscreener API to fetch token prices.

e. Utility Functions:
- ‘utils’ components (like float, table, text, spinner, etc.) as supporting services used by both the chain and REPL modules to manage formatting and synchronous operations.

f. Data Storage:
- Local configuration storage (".bop-data" file) as a persistent data store that holds encrypted portfolio data.

g. External Interactions:
- Similarly, from the dexscreener module to the Dexscreener external API, indicating these as external service interactions.

##### Architectural Patterns and Design Principles
- Modular design: The project cleanly separates concerns by dividing blockchain-specific functionality (chain module), external API calls (dexscreener), and the user session handling (repl).
- That the project is structured as a modular monolith with distinct responsibilities distributed among well-named modules.
- That dependency inversion is applied since external services (RPC and Dexscreener) can be swapped (e.g., for custom RPC endpoints).

## Diagram (Mermaid)

```mermaid
graph TD
    %% Main Components
    A["Main Entry (main.rs)"]:::main
    B["REPL Interface"]:::repl
    F["Local Encrypted Storage (.bop-data)"]:::storage
    G["External RPC Endpoints"]:::external
    H["Dexscreener API"]:::external

    %% Subgraphs for Modules
    subgraph "Chain Module"
        direction TB
        C["Chain Module"]:::module
        C1["chain_properties"]:::subModule
        C2["chain_type"]:::subModule
        C3["evm_chain"]:::subModule
        C4["sol_chain"]:::subModule
        C5["ton_chain"]:::subModule
        C6["token"]:::subModule
        C --> C1
        C --> C2
        C --> C3
        C --> C4
        C --> C5
        C --> C6
    end

    subgraph "Dexscreener Module"
        direction TB
        D["Dexscreener Module"]:::module
        D1["mod.rs"]:::subModuleDex
        D2["pairs.rs"]:::subModuleDex
        D --> D1
        D --> D2
    end

    subgraph "Utilities"
        direction TB
        E["Utilities"]:::util
        E1["float"]:::subModuleUtil
        E2["table"]:::subModuleUtil
        E3["text"]:::subModuleUtil
        E4["spinner"]:::subModuleUtil
        E5["retry"]:::subModuleUtil
        E6["support_option"]:::subModuleUtil
        E --> E1
        E --> E2
        E --> E3
        E --> E4
        E --> E5
        E --> E6
    end

    %% Connections
    A -->|"Initializes"| B
    B -->|"Read/Write"| F
    B -->|"ChainConnector"| C
    B -->|"FetchPrices"| D
    C -->|"RPCCall"| G
    D -->|"APIRequest"| H
    E -->|"SupportFunctions"| B
    E -->|"SupportFunctions"| C

    %% Click Events
    click A "https://github.com/ndavd/bop/blob/main/src/main.rs"
    click B "https://github.com/ndavd/bop/tree/main/src/repl"
    
    click C "https://github.com/ndavd/bop/tree/main/src/chain"
    click C1 "https://github.com/ndavd/bop/blob/main/src/chain/chain_properties.rs"
    click C2 "https://github.com/ndavd/bop/blob/main/src/chain/chain_type.rs"
    click C3 "https://github.com/ndavd/bop/blob/main/src/chain/evm_chain.rs"
    click C4 "https://github.com/ndavd/bop/blob/main/src/chain/sol_chain.rs"
    click C5 "https://github.com/ndavd/bop/blob/main/src/chain/ton_chain.rs"
    click C6 "https://github.com/ndavd/bop/blob/main/src/chain/token.rs"
    
    click D "https://github.com/ndavd/bop/tree/main/src/dexscreener"
    click D1 "https://github.com/ndavd/bop/blob/main/src/dexscreener/mod.rs"
    click D2 "https://github.com/ndavd/bop/blob/main/src/dexscreener/pairs.rs"
    
    click E "https://github.com/ndavd/bop/tree/main/src/utils"
    click E1 "https://github.com/ndavd/bop/blob/main/src/utils/float.rs"
    click E2 "https://github.com/ndavd/bop/blob/main/src/utils/table.rs"
    click E3 "https://github.com/ndavd/bop/blob/main/src/utils/text.rs"
    click E4 "https://github.com/ndavd/bop/blob/main/src/utils/spinner.rs"
    click E5 "https://github.com/ndavd/bop/blob/main/src/utils/retry.rs"
    click E6 "https://github.com/ndavd/bop/blob/main/src/utils/support_option.rs"

    %% Styles
    classDef main fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef repl fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
    classDef module fill:#fff9c4,stroke:#f57f17,stroke-width:2px;
    classDef util fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef storage fill:#ffccbc,stroke:#d84315,stroke-width:2px;
    classDef external fill:#ffecb3,stroke:#f9a825,stroke-width:2px;
    classDef subModule fill:#e0f7fa,stroke:#006064,stroke-width:1px;
    classDef subModuleDex fill:#e1bee7,stroke:#8e24aa,stroke-width:1px;
    classDef subModuleUtil fill:#f8bbd0,stroke:#c2185b,stroke-width:1px;
```
