# enduserrr/bagbot architecture

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

- Interactive diagram: https://gitdiagram.com/enduserrr/bagbot
- Repository: https://github.com/enduserrr/bagbot

## Overview

Bagbot is a Bittensor alpha-staking bot. The principal workflow starts with the command-line entry point, which starts an asynchronous bot loop; the bot loads subnet and wallet settings, gathers blockchain stake and subnet data, displays a portfolio table, and makes buy/sell decisions that submit stake changes. The code also supports per-subnet trade limits and power-curve thresholds, validator discovery, and configurable display themes. The blockchain excerpt is partial, so the connection from its loop to trade execution is shown as unverified rather than asserted.

Main entry points: [`src/blockchain.py`](https://github.com/enduserrr/bagbot/blob/main/src/blockchain.py) (Bot loop), [`src/trade.py`](https://github.com/enduserrr/bagbot/blob/main/src/trade.py) (Trade rules), [`src/settings_loader.py`](https://github.com/enduserrr/bagbot/blob/main/src/settings_loader.py) (Settings loader), [`bagbot.py`](https://github.com/enduserrr/bagbot/blob/main/bagbot.py) (CLI entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_entry["CLI entry<br/>[bagbot.py]"]
  node_engine["Bot loop<br/>[blockchain.py]"]
  node_chain{{"Bittensor network"}}
end

subgraph group_configuration["Configuration"]
  node_loader["Settings loader<br/>[settings_loader.py]"]
  node_settings["Bot settings<br/>[bagbot_settings.py]"]
end

subgraph group_trading["Trading"]
  node_trade["Trade rules<br/>[trade.py]"]
end

subgraph group_presentation["Portfolio display"]
  node_display["Portfolio table<br/>[printHelpers.py]"]
  node_theme["Display themes<br/>[theme.py]"]
end

node_operator(("Operator"))

node_operator -->|"starts"| node_entry
node_entry -->|"starts loop"| node_engine
node_loader -->|"reads settings"| node_settings
node_engine -->|"uses settings"| node_loader
node_engine -->|"queries chain"| node_chain
node_engine -->|"prints portfolio"| node_display
node_display -->|"gets theme"| node_theme
node_trade -->|"uses settings"| node_loader
node_engine -.->|"delegates trades"| node_trade
node_trade -->|"submits stake changes"| node_chain

click node_entry "https://github.com/enduserrr/bagbot/blob/main/bagbot.py"
click node_engine "https://github.com/enduserrr/bagbot/blob/main/src/blockchain.py"
click node_loader "https://github.com/enduserrr/bagbot/blob/main/src/settings_loader.py"
click node_settings "https://github.com/enduserrr/bagbot/blob/main/bagbot_settings.py"
click node_trade "https://github.com/enduserrr/bagbot/blob/main/src/trade.py"
click node_display "https://github.com/enduserrr/bagbot/blob/main/src/printHelpers.py"
click node_theme "https://github.com/enduserrr/bagbot/blob/main/src/theme.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_engine,node_chain toneBlue
class node_loader,node_settings toneAmber
class node_trade toneMint
class node_display,node_theme toneRose
class node_operator toneIndigo
```

## Components

### Bot runtime

- [CLI entry](https://github.com/enduserrr/bagbot/blob/main/bagbot.py): `bagbot.py`
- [Bot loop](https://github.com/enduserrr/bagbot/blob/main/src/blockchain.py): `src/blockchain.py`
- **Bittensor network**

### Configuration

- [Settings loader](https://github.com/enduserrr/bagbot/blob/main/src/settings_loader.py): `src/settings_loader.py`
- [Bot settings](https://github.com/enduserrr/bagbot/blob/main/bagbot_settings.py): `bagbot_settings.py`

### Trading

- [Trade rules](https://github.com/enduserrr/bagbot/blob/main/src/trade.py): `src/trade.py`

### Portfolio display

- [Portfolio table](https://github.com/enduserrr/bagbot/blob/main/src/printHelpers.py): `src/printHelpers.py`
- [Display themes](https://github.com/enduserrr/bagbot/blob/main/src/theme.py): `src/theme.py`

### Other components

- **Operator**

## Connections

- Operator → CLI entry: starts (evidence: `README.md`)
- CLI entry → Bot loop: starts loop (evidence: `bagbot.py`)
- Settings loader → Bot settings: reads settings (evidence: `src/settings_loader.py`)
- Bot loop → Settings loader: uses settings (evidence: `src/blockchain.py`)
- Bot loop → Bittensor network: queries chain (evidence: `src/blockchain.py`)
- Bot loop → Portfolio table: prints portfolio (evidence: `src/blockchain.py`)
- Portfolio table → Display themes: gets theme (evidence: `src/printHelpers.py`)
- Trade rules → Settings loader: uses settings (evidence: `src/trade.py`)
- Bot loop → Trade rules: delegates trades (evidence: `src/blockchain.py`)
- Trade rules → Bittensor network: submits stake changes (evidence: `src/trade.py`)
