# brainsonchain/worm-tracker architecture

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

- Interactive diagram: https://gitdiagram.com/brainsonchain/worm-tracker
- Repository: https://github.com/brainsonchain/worm-tracker

## Overview

##### Main Components

A. External Systems:
- Hyperliquid Blockchain
- DeepWorms Smart Contract

B. Backend Components:
- HTTP Server (main.go, server.go)
- Block Fetcher Service (fetcher.go)
- SQLite Database (db.go)
- Processor (position.go)
- ABI Interface (abi.json)

C. Frontend Component:
- Web Browser Interface

**[External Layer]**

**[Backend Layer]**

**[Frontend Layer]**

##### Component Relationships

a. Data Flow:
- Hyperliquid Blockchain → Block Fetcher
- Block Fetcher → SQLite Database
- HTTP Server ← SQLite Database
- HTTP Server → Web Browser Interface

b. API Endpoints (annotate with endpoints):
- "/" (HTML serving)
- "/worm/positions"
- "/worm/historical"

##### Component Details

Block Fetcher:
- Monitors blockchain
- Parses DeepWorms logs
- Updates database

HTTP Server:
- Serves static content
- Handles API requests
- Returns worm positions

Database:
- SQLite
- Stores position data
- Historical tracking

Frontend:
- 2D visualization
- Real-time updates
- Historical view

##### Additional Elements

Important aspects:
- Data flow direction indicators
- Request/response paths
- Database schema overview (simplified)
- API endpoint listing
- Component interaction frequency

##### Technical Details to Highlight

- Go version: 1.22.5
- Database: SQLite
- Container support (note Dockerfile presence)
- Deployment configuration (fly.toml)

## Diagram (Mermaid)

```mermaid
graph TB
    %% Define styles
    classDef external fill:#b3d1ff,stroke:#4d88ff
    classDef database fill:#90EE90,stroke:#2E8B57
    classDef processor fill:#FFB366,stroke:#FF8000
    classDef frontend fill:#DDA0DD,stroke:#9370DB
    classDef server fill:#A0522D,stroke:#8B4513
    classDef config fill:#D3D3D3,stroke:#808080

    %% External Layer
    subgraph ExternalSystems
        HL[Hyperliquid Blockchain]
        DW[DeepWorms Smart Contract]
    end
    
    %% Backend Layer
    subgraph Backend
        BF["Block Fetcher Service"]:::processor
        PP["Position Processor"]:::processor
        DB[(SQLite Database)]:::database
        HS["HTTP Server"]:::server
        ABI["ABI Interface"]:::config
        WL["Worm Logic Handler"]:::processor
    end

    %% Frontend Layer
    subgraph Frontend
        WEB["Web Browser Interface"]:::frontend
    end

    %% Relationships
    HL --> BF
    DW --> BF
    BF --> PP
    PP --> DB
    DB --> HS
    ABI --> BF
    HS --> WEB
    WL --> HS
    DB --> WL

    %% API Endpoints
    API1["/"]:::server
    API2["/worm/positions"]:::server
    API3["/worm/historical"]:::server
    
    HS --> API1
    HS --> API2
    HS --> API3
    
    %% Click events for component mapping
    click BF "https://github.com/BrainsOnChain/worm-tracker/blob/main/src/fetcher.go"
    click PP "https://github.com/BrainsOnChain/worm-tracker/blob/main/src/position.go"
    click DB "https://github.com/BrainsOnChain/worm-tracker/blob/main/src/db.go"
    click HS "https://github.com/BrainsOnChain/worm-tracker/blob/main/src/server.go"
    click ABI "https://github.com/BrainsOnChain/worm-tracker/blob/main/src/abi.json"
    click WL "https://github.com/BrainsOnChain/worm-tracker/blob/main/src/worm.go"
    
    %% Legend
    subgraph Legend
        L1["External Systems"]:::external
        L2["Database"]:::database
        L3["Processors"]:::processor
        L4["Frontend"]:::frontend
        L5["Server Components"]:::server
        L6["Configuration"]:::config
    end

    %% Additional click events for configuration files
    click DC "https://github.com/BrainsOnChain/worm-tracker/tree/main/Dockerfile"
    click DPC "https://github.com/BrainsOnChain/worm-tracker/blob/main/fly.toml"
    click MA "https://github.com/BrainsOnChain/worm-tracker/tree/main/Makefile"
    click ME "https://github.com/BrainsOnChain/worm-tracker/blob/main/main.go"
```
