# faithmanex/bot architecture

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

- Interactive diagram: https://gitdiagram.com/faithmanex/bot
- Repository: https://github.com/faithmanex/bot

## Overview

#### Purpose and Entry Points
This is a Python foreign-exchange/synthetic-index trading system supporting historical backtests, parameter optimization, live trading, and sharable HTML trade replays. Primary entry points are `gui.py`, `currency/unified_trading.py`, `currency/backtest/backtest.py`, `currency/live_trading/live_trading.py`, `optimization/optimization.py`, and `sharing_server.py`.

#### Unified Trading Orchestration
`currency/unified_trading.py` appears to coordinate common trading behavior across execution modes. Global configuration is centralized in `currency/settings.py` and `currency/settings.json`, providing a boundary between strategy/execution code and environment-specific parameters.

#### Strategy and Market Domain Layer
Reusable trading domain logic is concentrated under `currency/modules/`: `currency/modules/strategy.py` implements signal behavior, `currency/modules/trading_pairs.py` defines supported instruments or pair metadata, and `currency/modules/lot_size.py` determines position sizing. This shared layer is the intended common dependency for backtest and live workflows.

#### Historical Backtesting Pipeline
`currency/backtest/backtest.py` consumes historical candle CSVs, applies strategy and sizing logic, and emits result artifacts. Its local `currency/backtest/settings.json` and `currency/backtest/trading_pairs.py` allow backtest-specific instrument/settings control. Input datasets reside in `history_data/`, including `history_data/EURUSD_data_M5.csv` and `history_data/Volatility 100 Index_data_M5.csv`; outputs are stored in `backtest_summary/`, such as `backtest_summary/backtest_summary.csv` and replay HTML files.

#### Live Trading Boundary
`currency/live_trading/live_trading.py` is the live execution entry point, with mode-local strategy, sizing, instrument, and configuration files at `currency/live_trading/strategy.py`, `currency/live_trading/lot_size.py`, and `currency/live_trading/settings.json`. This is the material boundary where generated signals become broker/platform actions; the file tree does not identify the broker integration explicitly.

#### Optimization Workflow
`optimization/optimization.py` runs strategy parameter searches against historical data. It has a dedicated implementation/configuration boundary in `optimization/strategy.py`, `optimization/trading_pairs.py`, and `optimization/settings.json`. Optimization results include ranked sweep data such as `backtest_summary/sweep_top10_Volatility 100 Index.json`, which can feed selected parameters back into backtest or live settings.

#### Results, Replay, and Publishing
Backtesting produces detailed per-instrument CSVs and browser-viewable replay pages in `backtest_summary/`. `currency/backtest_sharing.py` and `sharing_server.py` support publishing or serving replay content. Persistent shared artifacts are held in `shared_replays/`, indexed by `shared_replays/_index.json`; static hosting assets/configuration live in `share/index.html` and `share/vercel.json`, indicating Vercel-compatible deployment.

#### Supporting Runtime and Data
The system is Python-based, with dependencies declared in `requirements.txt`. Historical CSV data is repository-local rather than fetched at runtime. `Misc/` contains exploratory scripts and notebooks, while `backtest_summary/` and `shared_replays/` are generated/reporting-oriented data boundaries rather than core execution code.

Main entry points: [`currency/backtest/backtest.py`](https://github.com/faithmanex/bot/blob/main/currency/backtest/backtest.py) (Backtest runner), [`currency/unified_trading.py`](https://github.com/faithmanex/bot/blob/main/currency/unified_trading.py) (Unified trading), [`currency/live_trading/live_trading.py`](https://github.com/faithmanex/bot/blob/main/currency/live_trading/live_trading.py) (Live trading), [`optimization/optimization.py`](https://github.com/faithmanex/bot/blob/main/optimization/optimization.py) (Parameter optimizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_gui["GUI launcher<br/>Python entry point<br/>[gui.py]"]
  node_unified["Unified trading<br/>orchestrator<br/>[unified_trading.py]"]
end

subgraph group_shared["Shared trading domain"]
  node_settings["Global settings<br/>configuration<br/>[settings.py]"]
  node_shared_strategy["Shared strategy<br/>signal logic<br/>[strategy.py]"]
  node_shared_pairs["Trading pairs<br/>instrument domain<br/>[trading_pairs.py]"]
  node_shared_sizing["Lot sizing<br/>position sizing<br/>[lot_size.py]"]
end

subgraph group_backtest["Historical backtesting"]
  node_backtest_runner["Backtest runner<br/>historical executor<br/>[backtest.py]"]
  node_historical_data[("Historical candles<br/>CSV datasets")]
  node_backtest_config["Backtest controls<br/>mode configuration<br/>[settings.json]"]
  node_backtest_results[("Backtest results<br/>reports and replays")]
end

subgraph group_live["Live execution"]
  node_live_runner["Live trading<br/>execution boundary<br/>[live_trading.py]"]
  node_live_strategy["Live mode logic<br/>local strategy and sizing<br/>[strategy.py]"]
  node_live_config["Live settings<br/>mode configuration<br/>[settings.json]"]
end

subgraph group_publishing["Replay publishing"]
  node_replay_publisher["Replay publisher<br/>sharing workflow"]
  node_sharing_server["Sharing server<br/>content server<br/>[sharing_server.py]"]
  node_shared_replays[("Shared replays<br/>published artifacts")]
  node_static_hosting["Static share site<br/>Vercel assets<br/>[index.html]"]
end

subgraph group_optimization["Optimization"]
  node_optimizer["Parameter optimizer<br/>search runner<br/>[optimization.py]"]
  node_optimization_logic["Optimization strategy<br/>search implementation<br/>[strategy.py]"]
  node_sweep_results["Ranked sweep results<br/>parameter artifacts"]
end

node_gui -->|"launches"| node_unified
node_unified -->|"loads"| node_settings
node_unified -->|"orchestrates"| node_backtest_runner
node_unified -->|"orchestrates"| node_live_runner
node_backtest_runner -->|"reads candles"| node_historical_data
node_backtest_runner -->|"uses"| node_backtest_config
node_backtest_runner -->|"applies"| node_shared_strategy
node_backtest_runner -->|"selects instruments"| node_shared_pairs
node_backtest_runner -->|"sizes positions"| node_shared_sizing
node_backtest_runner -->|"writes"| node_backtest_results
node_live_runner -->|"uses"| node_live_strategy
node_live_runner -->|"loads"| node_live_config
node_live_runner -.->|"uses instruments"| node_shared_pairs
node_optimizer -->|"evaluates on"| node_historical_data
node_optimizer -->|"searches"| node_optimization_logic
node_optimizer -->|"writes rankings"| node_sweep_results
node_sweep_results -.->|"selected parameters"| node_backtest_config
node_sweep_results -.->|"selected parameters"| node_live_config
node_backtest_results -->|"supplies replays"| node_replay_publisher
node_replay_publisher -->|"publishes"| node_shared_replays
node_sharing_server -->|"serves"| node_shared_replays
node_static_hosting -.->|"hosts frontend for"| node_sharing_server

click node_gui "https://github.com/faithmanex/bot/blob/main/gui.py"
click node_unified "https://github.com/faithmanex/bot/blob/main/currency/unified_trading.py"
click node_settings "https://github.com/faithmanex/bot/blob/main/currency/settings.py"
click node_shared_strategy "https://github.com/faithmanex/bot/blob/main/currency/modules/strategy.py"
click node_shared_pairs "https://github.com/faithmanex/bot/blob/main/currency/modules/trading_pairs.py"
click node_shared_sizing "https://github.com/faithmanex/bot/blob/main/currency/modules/lot_size.py"
click node_backtest_runner "https://github.com/faithmanex/bot/blob/main/currency/backtest/backtest.py"
click node_backtest_config "https://github.com/faithmanex/bot/blob/main/currency/backtest/settings.json"
click node_live_runner "https://github.com/faithmanex/bot/blob/main/currency/live_trading/live_trading.py"
click node_live_strategy "https://github.com/faithmanex/bot/blob/main/currency/live_trading/strategy.py"
click node_live_config "https://github.com/faithmanex/bot/blob/main/currency/live_trading/settings.json"
click node_optimizer "https://github.com/faithmanex/bot/blob/main/optimization/optimization.py"
click node_optimization_logic "https://github.com/faithmanex/bot/blob/main/optimization/strategy.py"
click node_sweep_results "https://github.com/faithmanex/bot/blob/main/backtest_summary/sweep_top10_Volatility%20100%20Index.json"
click node_replay_publisher "https://github.com/faithmanex/bot/blob/main/currency/backtest_sharing.py"
click node_sharing_server "https://github.com/faithmanex/bot/blob/main/sharing_server.py"
click node_static_hosting "https://github.com/faithmanex/bot/blob/main/share/index.html"

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_gui,node_unified toneBlue
class node_settings,node_shared_strategy,node_shared_pairs,node_shared_sizing toneAmber
class node_backtest_runner,node_historical_data,node_backtest_config,node_backtest_results toneMint
class node_live_runner,node_live_strategy,node_live_config toneRose
class node_replay_publisher,node_sharing_server,node_shared_replays,node_static_hosting toneIndigo
class node_optimizer,node_optimization_logic,node_sweep_results toneTeal
```

## Components

### Entry points

- [GUI launcher](https://github.com/faithmanex/bot/blob/main/gui.py): Python entry point · `gui.py`
- [Unified trading](https://github.com/faithmanex/bot/blob/main/currency/unified_trading.py): orchestrator · Coordinates common behavior across execution modes. · `currency/unified_trading.py`

### Shared trading domain

- [Global settings](https://github.com/faithmanex/bot/blob/main/currency/settings.py): configuration · `currency/settings.py`
- [Shared strategy](https://github.com/faithmanex/bot/blob/main/currency/modules/strategy.py): signal logic · `currency/modules/strategy.py`
- [Trading pairs](https://github.com/faithmanex/bot/blob/main/currency/modules/trading_pairs.py): instrument domain · `currency/modules/trading_pairs.py`
- [Lot sizing](https://github.com/faithmanex/bot/blob/main/currency/modules/lot_size.py): position sizing · `currency/modules/lot_size.py`

### Historical backtesting

- [Backtest runner](https://github.com/faithmanex/bot/blob/main/currency/backtest/backtest.py): historical executor · `currency/backtest/backtest.py`
- **Historical candles**: CSV datasets · Repository-local market data.
- [Backtest controls](https://github.com/faithmanex/bot/blob/main/currency/backtest/settings.json): mode configuration · Local settings and instrument definitions. · `currency/backtest/settings.json`
- **Backtest results**: reports and replays · Per-instrument summaries, CSVs, and replay HTML.

### Live execution

- [Live trading](https://github.com/faithmanex/bot/blob/main/currency/live_trading/live_trading.py): execution boundary · Converts signals into broker or platform actions. · `currency/live_trading/live_trading.py`
- [Live mode logic](https://github.com/faithmanex/bot/blob/main/currency/live_trading/strategy.py): local strategy and sizing · `currency/live_trading/strategy.py`
- [Live settings](https://github.com/faithmanex/bot/blob/main/currency/live_trading/settings.json): mode configuration · `currency/live_trading/settings.json`

### Replay publishing

- [Replay publisher](https://github.com/faithmanex/bot/blob/main/currency/backtest_sharing.py): sharing workflow · `currency/backtest_sharing.py`
- [Sharing server](https://github.com/faithmanex/bot/blob/main/sharing_server.py): content server · `sharing_server.py`
- **Shared replays**: published artifacts · Indexed persistent replay content.
- [Static share site](https://github.com/faithmanex/bot/blob/main/share/index.html): Vercel assets · `share/index.html`

### Optimization

- [Parameter optimizer](https://github.com/faithmanex/bot/blob/main/optimization/optimization.py): search runner · `optimization/optimization.py`
- [Optimization strategy](https://github.com/faithmanex/bot/blob/main/optimization/strategy.py): search implementation · `optimization/strategy.py`
- [Ranked sweep results](https://github.com/faithmanex/bot/blob/main/backtest_summary/sweep_top10_Volatility%20100%20Index.json): parameter artifacts · `backtest_summary/sweep_top10_Volatility 100 Index.json`

## Connections

- GUI launcher → Unified trading: launches
- Unified trading → Global settings: loads
- Unified trading → Backtest runner: orchestrates
- Unified trading → Live trading: orchestrates
- Backtest runner → Historical candles: reads candles
- Backtest runner → Backtest controls: uses
- Backtest runner → Shared strategy: applies
- Backtest runner → Trading pairs: selects instruments
- Backtest runner → Lot sizing: sizes positions
- Backtest runner → Backtest results: writes
- Live trading → Live mode logic: uses
- Live trading → Live settings: loads
- Live trading → Trading pairs: uses instruments
- Parameter optimizer → Historical candles: evaluates on
- Parameter optimizer → Optimization strategy: searches
- Parameter optimizer → Ranked sweep results: writes rankings
- Ranked sweep results → Backtest controls: selected parameters
- Ranked sweep results → Live settings: selected parameters
- Backtest results → Replay publisher: supplies replays
- Replay publisher → Shared replays: publishes
- Sharing server → Shared replays: serves
- Static share site → Sharing server: hosts frontend for
