# mattmsh/chart-api architecture

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

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

## Overview

##### Main Components Identification

The project appears to be a blockchain data indexing service with the following key components:
- Blockchain Interaction Layer
- Data Processing Layer
- Database Layer
- API Layer
- Caching Layer

##### Component Relationships

- Viem Client ↔ Blockchain Networks
- Watcher Service → Viem Client
- Watcher Service → Cache Service
- Cache Service ↔ MongoDB
- Client API → Cache Service
- Client API → MongoDB

##### Specific Implementation Details

- Smart Contract ABIs (factoryAbi.js, poolAbi.js)
- Multiple Chain Support (from chains/index.js)
- Retry Mechanism (from retryOperation.js)
- Configuration Management (from config/index.js)

##### Additional Architectural Elements

Cross-cutting concerns:
- Environment Configuration (.env.example)
- Service Dependencies (package.json)

##### The separation between data collection and API serving layers

Key Technical Considerations to Highlight:
- Blockchain interaction through Viem client
- MongoDB as the primary data store
- Caching layer for performance optimization
- Retry mechanisms for reliability
- Multi-chain support architecture

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Blockchain Networks"
        BC1[Blockchain 1]:::blockchain
        BC2[Blockchain 2]:::blockchain
        BC3[Blockchain N]:::blockchain
    end

    subgraph "Smart Contracts"
        FC["Factory Contract"]:::contract
        PC["Pool Contract"]:::contract
    end

    subgraph "Blockchain Interaction"
        VC["Viem Client"]:::service
        CC["Chain Configuration"]:::service
        ABI["Contract ABIs"]:::service
        CI["Contract Implementation"]:::service
    end

    subgraph "Core Processing"
        WS["Watcher Service"]:::service
        RM["Retry Mechanism"]:::service
    end

    subgraph "Data Management"
        DB[(MongoDB)]:::database
        CS[("Cache Storage")]:::cache
    end

    subgraph "API Layer"
        API["Client API"]:::api
    end

    subgraph "Configuration"
        ENV["Environment Config"]:::config
        SYSCONF["System Config"]:::config
        CONST["Constants"]:::config
    end

    BC1 & BC2 & BC3 <--> VC
    FC & PC --> VC
    VC --> WS
    CC --> VC
    ABI --> VC
    CI --> VC
    WS --> RM
    RM --> DB
    WS --> CS
    CS <--> DB
    API --> CS
    API --> DB
    ENV & SYSCONF & CONST --> WS

    %% Click Events
    click VC "https://github.com/MattMsh/chart-api/blob/main/src/viemClient.js"
    click CC "https://github.com/MattMsh/chart-api/blob/main/src/chains/index.js"
    click ABI "https://github.com/MattMsh/chart-api/blob/main/src/abis/factoryAbi.js"
    click CI "https://github.com/MattMsh/chart-api/blob/main/src/contracts/index.js"
    click WS "https://github.com/MattMsh/chart-api/blob/main/src/watcher.js"
    click RM "https://github.com/MattMsh/chart-api/blob/main/src/utils/retryOperation.js"
    click DB "https://github.com/MattMsh/chart-api/blob/main/src/db/mongoConnector.js"
    click CS "https://github.com/MattMsh/chart-api/blob/main/src/services/cachePoolAndToken.js"
    click API "https://github.com/MattMsh/chart-api/blob/main/src/client_api.js"
    click ENV "https://github.com/MattMsh/chart-api/blob/main/.env.example"
    click SYSCONF "https://github.com/MattMsh/chart-api/blob/main/src/config/index.js"
    click CONST "https://github.com/MattMsh/chart-api/blob/main/src/constants/abis.js"

    %% Styling
    classDef blockchain fill:#a0d8ef,stroke:#333,stroke-width:2px
    classDef contract fill:#d4a5ff,stroke:#333,stroke-width:2px
    classDef service fill:#90EE90,stroke:#333,stroke-width:2px
    classDef database fill:#ffb347,stroke:#333,stroke-width:2px
    classDef cache fill:#fff176,stroke:#333,stroke-width:2px
    classDef api fill:#e6e6fa,stroke:#333,stroke-width:2px
    classDef config fill:#f5f5f5,stroke:#333,stroke-width:2px

    %% Legend
    subgraph Legend
        L1[Blockchain]:::blockchain
        L2[Contract]:::contract
        L3[Service]:::service
        L4[(Database)]:::database
        L5[("Cache")]:::cache
        L6[API]:::api
        L7[Config]:::config
    end
```
