# latent-to/taohash architecture

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

- Interactive diagram: https://gitdiagram.com/latent-to/taohash
- Repository: https://github.com/latent-to/taohash

## Overview

##### Project type and purpose
- TAO Hash is an open-source, decentralized Subnet service on Bittensor that automates the exchange of proof-of-work hashrate (mining power) for on-chain rewards (Alpha). It consists of two roles—miners and validators—that communicate with external services (Braiins Pool, pricing APIs) and a local data store (Redis).

##### File structure
- Top-level directories:
- taohash/core – core library layers (chain_data, pool abstractions, pricing adapters, storage interfaces, utils)
- taohash/miner – miner role: allocation, Braiins proxy, scheduler, storage integration
- taohash/validator – validator role: Braiins API client, storage integration
- tests – unit and integration tests
- Config files and scripts: pyproject.toml (build), Dockerfile/docker-compose under proxy (containerized Braiins Farm), .env examples

##### README for additional insights
- Emphasizes extensibility: adding new pool implementations, new pricing sources, new storage backends

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Library
    subgraph "SDK / Core Library"
        direction TB
        ChainData["Chain Data Module"]:::core
        PoolAbstr["Pool Abstractions"]:::core
        BraiinsAdapter["Braiins Pool Adapter"]:::core
        PricingAdapters["Pricing Adapters"]:::core
        StorageInterfaces["Storage Interfaces"]:::core
        Utils["Utility Functions"]:::core
    end

    %% Roles and Services
    subgraph "Roles - Services"
        direction TB

        subgraph "Miner Service" 
            direction TB
            MinerAllocation["Allocation Logic"]:::service
            MinerBraiinsClient["Braiins Client Integration"]:::service
            MinerScheduler["Scheduler"]:::service
            MinerStorage["Storage Integration"]:::service
            MinerModels["Domain Models"]:::service
        end

        subgraph "Proxy Service (Braiins Farm Proxy)"
            direction TB
            ProxyBase["Base Proxy Interface"]:::service
            ProxyFarm["Braiins Farm Container"]:::service
        end

        subgraph "Validator Service"
            direction TB
            ValidatorBraiinsClient["Braiins API Client"]:::service
            ValidatorStorage["Storage Integration"]:::service
        end
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        BraiinsPoolAPI["Braiins Pool API"]:::external
        PricingAPIs["Pricing APIs (CoinGecko, CMC)"]:::external
        BittensorNetwork["Bittensor Network"]:::external
    end

    %% Data Storage
    subgraph "Data Storage"
        direction TB
        Redis(("Redis")):::storage
        JSONStorage["JSON Storage (fallback)"]:::storage
    end

    %% Interactions
    MinerScheduler -->|uses| PoolAbstr
    MinerScheduler -->|fetch price| PricingAdapters
    MinerScheduler -->|state read/write| StorageInterfaces
    MinerScheduler -->|orchestrates| MinerAllocation
    MinerAllocation -->|models| MinerModels
    MinerStorage -->|writes/reads| StorageInterfaces

    MinerScheduler -->|"mining traffic"| ProxyBase
    ProxyBase -->|routes| ProxyFarm
    ProxyFarm -->|proxy to| BraiinsPoolAPI

    ValidatorBraiinsClient -->|fetch metrics| BraiinsPoolAPI
    ValidatorStorage -->|writes/reads| StorageInterfaces
    ValidatorBraiinsClient -->|metrics| StorageInterfaces
    ValidatorBraiinsClient -->|uses chain data| ChainData
    ValidatorBraiinsClient -->|issues weights| BittensorNetwork
    ValidatorBraiinsClient -->|fetch price| PricingAdapters

    PoolAbstr -->|adapter impl| BraiinsAdapter
    StorageInterfaces -->|redis impl| Redis
    StorageInterfaces -->|json impl| JSONStorage
    PricingAdapters -->|fetch from| PricingAPIs

    %% Click Events - Core Library
    click ChainData "https://github.com/latent-to/taohash/tree/main/taohash/core/chain_data"
    click PoolAbstr "https://github.com/latent-to/taohash/tree/main/taohash/core/pool"
    click BraiinsAdapter "https://github.com/latent-to/taohash/tree/main/taohash/core/pool/braiins"
    click PricingAdapters "https://github.com/latent-to/taohash/tree/main/taohash/core/pricing"
    click StorageInterfaces "https://github.com/latent-to/taohash/tree/main/taohash/core/storage"
    click Utils "https://github.com/latent-to/taohash/blob/main/taohash/core/utils.py"

    %% Click Events - Miner Service
    click MinerAllocation "https://github.com/latent-to/taohash/blob/main/taohash/miner/allocation.py"
    click MinerBraiinsClient "https://github.com/latent-to/taohash/blob/main/taohash/miner/braiins.py"
    click MinerScheduler "https://github.com/latent-to/taohash/blob/main/taohash/miner/scheduler.py"
    click MinerStorage "https://github.com/latent-to/taohash/blob/main/taohash/miner/storage.py"
    click MinerModels "https://github.com/latent-to/taohash/blob/main/taohash/miner/models.py"

    %% Click Events - Proxy Service
    click ProxyBase "https://github.com/latent-to/taohash/blob/main/taohash/miner/proxy/base.py"
    click ProxyFarm "https://github.com/latent-to/taohash/tree/main/taohash/miner/proxy/braiins_farm"

    %% Click Events - Validator Service
    click ValidatorBraiinsClient "https://github.com/latent-to/taohash/blob/main/taohash/validator/braiins.py"
    click ValidatorStorage "https://github.com/latent-to/taohash/blob/main/taohash/validator/storage.py"

    %% Click Events - Data Storage
    click Redis "https://github.com/latent-to/taohash/blob/main/taohash/core/storage/redis_storage.py"
    click JSONStorage "https://github.com/latent-to/taohash/blob/main/taohash/core/storage/json_storage.py"

    %% Styles
    classDef core fill:#EFEFFF,stroke:#4444AA,stroke-width:1px
    classDef service fill:#E0FFE0,stroke:#22AA22,stroke-width:1px
    classDef external fill:#FFF0E0,stroke:#AA6600,stroke-width:1px
    classDef storage fill:#F0FFF0,stroke:#006600,stroke-width:1px
    class ChainData,PoolAbstr,BraiinsAdapter,PricingAdapters,StorageInterfaces,Utils core
    class MinerAllocation,MinerBraiinsClient,MinerScheduler,MinerStorage,MinerModels,ProxyBase,ProxyFarm,ValidatorBraiinsClient,ValidatorStorage service
    class Redis,JSONStorage storage
    class BraiinsPoolAPI,PricingAPIs,BittensorNetwork external
```
