# score-technologies/score-predict architecture

> Architecture diagram of the GitHub repository score-technologies/score-predict, 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/score-technologies/score-predict
- Repository: https://github.com/score-technologies/score-predict

## Overview

Based on our analysis of the file tree and README, the Score Predict Subnet is a specialized blockchain subnet aimed at predicting football (soccer) match outcomes by having two primary roles: miners (which generate predictions using a base ML model like a Random Forest classifier) and validators (which challenge and score those predictions before setting on-chain weights). The project is a hybrid full-stack/subnet design, where there’s not only an on-chain prediction scoring system but also a centralized API (for match data fetch) plus a frontend “Score Predict App” used by end users to submit their own predictions.

##### Main components
- Miners: Represented by components such as neurons/miner.py, scorepredict/base/miner.py and all related utilities that support prediction generation.
- Validators: Represented by components such as neurons/validator.py, scorepredict/base/validator.py, and scorepredict/validator/forward.py & reward.py – these modules fetch upcoming matches, send challenges to miners, aggregate and score responses.
- Centralized API/Match Data Service: Even though its code isn’t deeply detailed here, the README explains that a centralized API is initially used to fetch upcoming matches and results. Include this as a distinct service.
- Supporting Modules: Additional libraries and utilities (e.g., config, logging, protocol definitions, and utility scripts) that help with configuration, data flow, and integration. These backend “glue” components support the miner and validator functionalities.
- Deployment and Infrastructure: Include elements such as script-based installations (install_miner.sh, install_validator.sh), CI/CD pipelines (.circleci folder), and deployment processes (pm2 usage) that indicate methods for managing the production servers.

##### Relationships and interactions
- Flow from the Centralized API to Validators:
- The API is used to fetch upcoming football matches and match outcomes.
- Validation Cycle:
- Validators use the match data fetched from the API to send out prediction challenges to miners.
- Miners’ prediction responses flow back to Validators.
- Scoring and Weight Setting:
- Once predictions are received, the scoring logic (detailed in scorepredict/protocol.py along with reward computation in validator/reward.py) calculates scores and applies multipliers.
- User Interaction:
- Deployment and Automated Updates:
- Components where automated scripts (validator_auto_update.sh, install scripts) manage deployment, node updates, and process management (pm2) as supporting infrastructure.

##### Architectural patterns and design principles
- Modular Design: The project splits its functionalities into modular components (miners, validators, API, base utilities) organized by directories such as neurons/, scorepredict/, and contrib/.
- Decoupled Services: Although the system is centrally coordinated (especially with the API), there is clear responsibility separation between generating predictions (miner) and processing/validating predictions (validator).
- Pluggability & Extensibility: The existence of a “base” model that miners can replace (or fine-tune) implies an architecture designed to be easily extended.
- Infrastructure Automation: The scripts and CI/CD configuration (in .circleci) illustrate that deployment and operational maintenance are factored into the design.

##### Technologies and libraries
- Python 3.8+ environment with pip dependencies (as specified in requirements.txt).
- PM2 for process management.
- External dependencies: interfacing with the Bittensor network (as noted in instructions), use of Random Forest classifier, etc.
- Shell scripts for installation and automated deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Centralized Services
    subgraph "Centralized Services"
        API["Centralized Match API"]:::api
        UI["Score Predict App (User Interface)"]:::ui
    end

    %% Processor Components: Miners and Validators
    subgraph "Processor Components"
        subgraph "Miners"
            Miner1["Miner Node - neurons/miner.py"]:::miner
            Miner2["Miner Node - scorepredict/base/miner.py"]:::miner
        end
        subgraph "Validators"
            Validator1["Validator Node - neurons/validator.py"]:::validator
            Validator2["Validator Node - scorepredict/base/validator.py"]:::validator
            Validator3["Forward Module - scorepredict/validator/forward.py"]:::validator
            Validator4["Reward Module - scorepredict/validator/reward.py"]:::validator
        end
        OnChain["On-Chain Weights"]:::onchain
    end

    %% Supporting Modules & Utilities
    subgraph "Supporting Modules"
        Utils1["Weight Utils - scorepredict/base/utils/weight_utils.py"]:::utils
        Utils2["General Utils - scorepredict/utils"]:::utils
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        InstallMiner["Install Miner Script - install_miner.sh"]:::deployment
        InstallValidator["Install Validator Script - install_validator.sh"]:::deployment
        AutoUpdate["Validator Auto-Update Script - validator_auto_update.sh"]:::deployment
        CICD["CI/CD Pipeline - .circleci/config.yml"]:::deployment
        Scripts["Deployment Scripts - scripts/"]:::deployment
    end

    %% Data Flow Connections
    API -->|"fetchMatches"| Validator1
    API -->|"fetchMatches"| Validator2
    API -->|"fetchMatches"| Validator3
    API -->|"fetchMatches"| Validator4

    UI -->|"submitPrediction"| Validator2

    %% Validators send challenge to Miners
    Validator1 -->|"challengeRequest"| Miner1
    Validator1 -->|"challengeRequest"| Miner2
    %% Miners respond to Validators
    Miner1 -->|"predictionResponse"| Validator1
    Miner2 -->|"predictionResponse"| Validator1

    %% Validators update on-chain weights
    Validator4 -->|"scoreCalculation"| OnChain

    %% Supporting Modules provide utility support to Miner and Validator components
    Utils1 --- Miner1
    Utils1 --- Validator1
    Utils2 --- Miner2
    Utils2 --- Validator2

    %% Deployment scripts manage deployment of core components
    InstallMiner --- Miner1
    InstallValidator --- Validator1
    AutoUpdate --- Validator1
    CICD --- API
    CICD --- Validator1
    Scripts --- API
    Scripts --- Miner1

    %% Click Events for Miner Components
    click Miner1 "https://github.com/score-technologies/score-predict/blob/main/neurons/miner.py"
    click Miner2 "https://github.com/score-technologies/score-predict/blob/main/scorepredict/base/miner.py"

    %% Click Events for Validator Components
    click Validator1 "https://github.com/score-technologies/score-predict/blob/main/neurons/validator.py"
    click Validator2 "https://github.com/score-technologies/score-predict/blob/main/scorepredict/base/validator.py"
    click Validator3 "https://github.com/score-technologies/score-predict/blob/main/scorepredict/validator/forward.py"
    click Validator4 "https://github.com/score-technologies/score-predict/blob/main/scorepredict/validator/reward.py"

    %% Click Event for API Component
    click API "https://github.com/score-technologies/score-predict/tree/main/scorepredict/api"

    %% Click Events for Supporting Modules
    click Utils1 "https://github.com/score-technologies/score-predict/blob/main/scorepredict/base/utils/weight_utils.py"
    click Utils2 "https://github.com/score-technologies/score-predict/tree/main/scorepredict/utils"

    %% Click Events for Deployment & Infrastructure
    click InstallMiner "https://github.com/score-technologies/score-predict/blob/main/install_miner.sh"
    click InstallValidator "https://github.com/score-technologies/score-predict/blob/main/install_validator.sh"
    click AutoUpdate "https://github.com/score-technologies/score-predict/blob/main/validator_auto_update.sh"
    click CICD "https://github.com/score-technologies/score-predict/blob/main/.circleci/config.yml"
    click Scripts "https://github.com/score-technologies/score-predict/tree/main/scripts/"

    %% Styles
    classDef miner fill:#cce5ff,stroke:#009,stroke-width:2px;
    classDef validator fill:#ffe5cc,stroke:#f80,stroke-width:2px;
    classDef api fill:#e5ccff,stroke:#800,stroke-width:2px;
    classDef ui fill:#ccffcc,stroke:#060,stroke-width:2px;
    classDef utils fill:#e6e6e6,stroke:#666,stroke-width:2px;
    classDef deployment fill:#ffccff,stroke:#c06,stroke-width:2px;
    classDef onchain fill:#ffffcc,stroke:#aa0,stroke-width:2px;
```
