# condenses/subnet-miner architecture

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

- Interactive diagram: https://gitdiagram.com/condenses/subnet-miner
- Repository: https://github.com/condenses/subnet-miner

## Overview

##### Main Components
- Condense Miner Core – This is the main logic found in the “condense_miner” directory with files such as main.py, config.py, protocol.py, and redis_manager.py. It handles setup, configuration, protocol logic, and manages connections to Redis.
- Redis Datastore – The project uses Redis (as indicated by the redis_manager.py and install_redis.sh script) to handle caching or data storage.
- Sidecar Bittensor Service – As described in the README’s “Sidecar Bittensor” section, this process, started via pm2, runs a uvicorn server that provides metagraph and chain functionality. Even though its code isn’t in this repository, it is an essential integration point.
- Environment and Deployment Scripts – The “scripts” directory (containing install_redis.sh and update_env.py) includes deployment and environment-setup utilities to manage environment variables critical for configuration.
- Containerization (via Dockerfile) – The Dockerfile indicates that there is a containerized deployment option.

##### Relationships and Interactions
- The Condense Miner (main.py) is the central process. It retrieves its configuration and possibly connection parameters from config.py and update_env.py.
- The Condense Miner process interfaces with the Sidecar Bittensor service through specified API calls, as indicated by the requirement to set “SIDECAR_BITTENSOR__BASE_URL” via environment variables.
- Deployment and startup are managed by external orchestration processes (pm2 and Docker) as described in the README.

##### Architectural Patterns and Design Principles
- Modular Design – The clear division into a core miner module, configuration, and Redis integration supports a separation of concerns.
- Microservices/Process-Oriented – The use of separate processes (Condense Miner and Sidecar) and containerization (Dockerfile) suggests that the project is built using a microservices-like approach. Each component is confined to its responsibility.
- Environment-Driven Configuration – The use of update-env scripts and environment variables underscores the principle of externalizing configuration for flexibility.

##### Relevant Technologies and Frameworks
- Python – The overall project is Python-based. The presence of a Dockerfile suggests containerized deployments.
- Redis – For caching/data storage.
- pm2 and uvicorn – pm2 is used for process management while uvicorn is used for serving the sidecar’s API.
- Version/Dependency Management – The pyproject.toml file indicates use of modern Python packaging approaches.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top level Deployment & Orchestration node
    Deployment["Deployment & Orchestration (pm2,Docker)"]:::process

    %% Subgraph for Condense Miner Engine
    subgraph "Condense Miner Engine"
        MinerMain["Main Process (main.py)"]:::process
        MinerConfig["Configuration (config.py)"]:::process
        MinerProtocol["Protocol Logic (protocol.py)"]:::process
        MinerRedis["Redis Manager (redis_manager.py)"]:::process
    end

    %% Other core components
    RedisDB["Redis Datastore"]:::database
    Sidecar["Sidecar Bittensor Service (uvicorn)"]:::process

    %% Subgraph for Environment & Setup Scripts
    subgraph "Environment & Setup"
        UpdateEnv["Update Env (update_env.py)"]:::script
        InstallRedis["Install Redis Script (install_redis.sh)"]:::script
    end

    %% Connections among components with directional arrows
    Deployment -->|"start"| MinerMain
    MinerMain -->|"loads_config"| MinerConfig
    MinerMain -->|"executes_protocol"| MinerProtocol
    MinerMain -->|"calls_redis"| MinerRedis
    MinerRedis -->|"read/write"| RedisDB
    MinerMain -->|"api_call"| Sidecar
    Deployment -->|"orchestrates"| Sidecar

    %% Environment flows (dotted arrows)
    UpdateEnv ---|"configures"| MinerConfig
    InstallRedis ---|"sets_up"| RedisDB

    %% Styles for clarity
    classDef process fill:#d0e9ff,stroke:#1e90ff,stroke-width:2px;
    classDef database fill:#ffe6a7,stroke:#d6962a,stroke-width:2px;
    classDef script fill:#e0ffe6,stroke:#66cc66,stroke-width:2px;

    %% Click Events
    click MinerMain "https://github.com/condenses/subnet-miner/blob/main/condense_miner/main.py"
    click MinerConfig "https://github.com/condenses/subnet-miner/blob/main/condense_miner/config.py"
    click MinerProtocol "https://github.com/condenses/subnet-miner/blob/main/condense_miner/protocol.py"
    click MinerRedis "https://github.com/condenses/subnet-miner/blob/main/condense_miner/redis_manager.py"
    click Deployment "https://github.com/condenses/subnet-miner/tree/main/Dockerfile"
    click UpdateEnv "https://github.com/condenses/subnet-miner/blob/main/scripts/update_env.py"
    click InstallRedis "https://github.com/condenses/subnet-miner/blob/main/scripts/install_redis.sh"
```
