# ranjeet867/metatrader architecture

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

- Interactive diagram: https://gitdiagram.com/ranjeet867/metatrader
- Repository: https://github.com/ranjeet867/metatrader

## Overview

Metatrader is an MT5 quant research, FTMO-risk, and trading operations platform. A trader refreshes broker candles, evaluates strategy cells through reconciliation-gated backtests and statistics, then manages deployments in the dashboard for paper or gated live execution; account, position, and journal views support operations. Research, compliance, and replay-parity are distinct product stages. The graph preserves README capabilities whose implementation was not sampled, but marks uncertain runtime connections dashed; source evidence is limited to the supplied excerpts and index.

Main entry points: [`dashboards/app.py`](https://github.com/ranjeet867/metatrader/blob/main/dashboards/app.py) (Operations dashboard), [`dashboards/pages/1_📊_Backtest.py`](https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/1_%F0%9F%93%8A_Backtest.py) (Backtest and research UI), [`core/backtest.py`](https://github.com/ranjeet867/metatrader/blob/main/core/backtest.py) (Backtest engine), [`scripts/optimize_portfolio.py`](https://github.com/ranjeet867/metatrader/blob/main/scripts/optimize_portfolio.py) (Portfolio optimizer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_research["Research and validation"]
  node_strategies["Strategy implementations"]
  node_backtest["Backtest engine<br/>[backtest.py]"]
  node_stats["Backtest statistics<br/>[backtest_stats.py]"]
  node_optimizer["Portfolio optimizer"]
  node_edge_catalog["Edge catalog<br/>[edge_catalog.py]"]
  node_parity["Replay parity gate<br/>[parity_gate.py]"]
end

subgraph group_marketdata["Market data"]
  node_data["Candle data service<br/>[data.py]"]
end

subgraph group_operations["Operations dashboard"]
  node_dashboard["Operations dashboard<br/>[app.py]"]
  node_backtest_ui["Backtest and research UI<br/>[1_📊_Backtest.py]"]
  node_library_ui["Strategy library UI"]
  node_data_ui["Data manager UI"]
  node_strategy_resolver["Strategy resolver"]
  node_session_state["Dashboard state<br/>[state.py]"]
end

subgraph group_execution["Risk and execution"]
  node_risk["Risk and time guards<br/>[risk_engine.py]"]
  node_deployment["Deployment registry<br/>[deployment.py]"]
  node_live["Live execution<br/>[live_executor.py]"]
  node_paper["Paper trading<br/>[paper_loop.py]"]
  node_position_manager["Position management"]
end

subgraph group_state["Accounts and state"]
  node_storage[("SQLite persistence<br/>[storage.py]")]
  node_account_manager["Multi-account registry<br/>[account_manager.py]"]
  node_journal["Trade journal<br/>[journal.py]"]
end

node_trader(("Trader"))
node_mt5_bridge{{"MT5 file bridge"}}

node_trader -->|"uses"| node_dashboard
node_dashboard -->|"loads state"| node_session_state
node_dashboard -.->|"offers research"| node_backtest_ui
node_dashboard -->|"offers data management"| node_data_ui
node_backtest_ui -->|"runs backtests"| node_backtest
node_backtest_ui -->|"computes metrics"| node_stats
node_backtest_ui -->|"resolves strategies"| node_strategy_resolver
node_library_ui -->|"reads edge data"| node_edge_catalog
node_library_ui -->|"checks parity"| node_parity
node_data_ui -->|"manages candles"| node_data
node_data -->|"fetches candles"| node_mt5_bridge
node_data -->|"persists candles"| node_storage
node_backtest -->|"evaluates signals"| node_strategies
node_backtest -.->|"produces results"| node_stats
node_optimizer -->|"sweeps candidates"| node_backtest
node_optimizer -->|"computes statistics"| node_stats
node_optimizer -.->|"updates catalog"| node_edge_catalog
node_deployment -->|"uses accounts"| node_account_manager
node_live -.->|"checks safety gates"| node_risk
node_deployment -.->|"starts live runs"| node_live
node_deployment -.->|"starts paper runs"| node_paper
node_position_manager -->|"records closes"| node_journal
node_position_manager -->|"scopes account"| node_account_manager
node_parity -->|"reads persisted results"| node_storage

click node_dashboard "https://github.com/ranjeet867/metatrader/blob/main/dashboards/app.py"
click node_backtest_ui "https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/1_%F0%9F%93%8A_Backtest.py"
click node_library_ui "https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/7_%F0%9F%8F%9B%EF%B8%8F_Strategy_Library.py"
click node_data_ui "https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/6_%F0%9F%92%BE_Data_Manager.py"
click node_strategy_resolver "https://github.com/ranjeet867/metatrader/blob/main/dashboards/components/strategy_resolver.py"
click node_session_state "https://github.com/ranjeet867/metatrader/blob/main/dashboards/components/state.py"
click node_data "https://github.com/ranjeet867/metatrader/blob/main/core/data.py"
click node_storage "https://github.com/ranjeet867/metatrader/blob/main/core/storage.py"
click node_strategies "https://github.com/ranjeet867/metatrader/tree/main/strategies"
click node_backtest "https://github.com/ranjeet867/metatrader/blob/main/core/backtest.py"
click node_stats "https://github.com/ranjeet867/metatrader/blob/main/core/backtest_stats.py"
click node_optimizer "https://github.com/ranjeet867/metatrader/blob/main/scripts/optimize_portfolio.py"
click node_edge_catalog "https://github.com/ranjeet867/metatrader/blob/main/core/edge_catalog.py"
click node_parity "https://github.com/ranjeet867/metatrader/blob/main/core/parity_gate.py"
click node_risk "https://github.com/ranjeet867/metatrader/blob/main/core/risk_engine.py"
click node_deployment "https://github.com/ranjeet867/metatrader/blob/main/core/deployment.py"
click node_live "https://github.com/ranjeet867/metatrader/blob/main/core/live_executor.py"
click node_paper "https://github.com/ranjeet867/metatrader/blob/main/core/paper_loop.py"
click node_position_manager "https://github.com/ranjeet867/metatrader/blob/main/core/position_manager.py"
click node_account_manager "https://github.com/ranjeet867/metatrader/blob/main/core/account_manager.py"
click node_journal "https://github.com/ranjeet867/metatrader/blob/main/core/journal.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_strategies,node_backtest,node_stats,node_optimizer,node_edge_catalog,node_parity toneBlue
class node_data toneAmber
class node_dashboard,node_backtest_ui,node_library_ui,node_data_ui,node_strategy_resolver,node_session_state toneMint
class node_risk,node_deployment,node_live,node_paper,node_position_manager toneRose
class node_storage,node_account_manager,node_journal,node_trader,node_mt5_bridge toneIndigo
```

## Components

### Research and validation

- [Strategy implementations](https://github.com/ranjeet867/metatrader/tree/main/strategies): `strategies`
- [Backtest engine](https://github.com/ranjeet867/metatrader/blob/main/core/backtest.py): `core/backtest.py`
- [Backtest statistics](https://github.com/ranjeet867/metatrader/blob/main/core/backtest_stats.py): `core/backtest_stats.py`
- [Portfolio optimizer](https://github.com/ranjeet867/metatrader/blob/main/scripts/optimize_portfolio.py): `scripts/optimize_portfolio.py`
- [Edge catalog](https://github.com/ranjeet867/metatrader/blob/main/core/edge_catalog.py): `core/edge_catalog.py`
- [Replay parity gate](https://github.com/ranjeet867/metatrader/blob/main/core/parity_gate.py): `core/parity_gate.py`

### Market data

- [Candle data service](https://github.com/ranjeet867/metatrader/blob/main/core/data.py): `core/data.py`

### Operations dashboard

- [Operations dashboard](https://github.com/ranjeet867/metatrader/blob/main/dashboards/app.py): `dashboards/app.py`
- [Backtest and research UI](https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/1_%F0%9F%93%8A_Backtest.py): `dashboards/pages/1_📊_Backtest.py`
- [Strategy library UI](https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/7_%F0%9F%8F%9B%EF%B8%8F_Strategy_Library.py): `dashboards/pages/7_🏛️_Strategy_Library.py`
- [Data manager UI](https://github.com/ranjeet867/metatrader/blob/main/dashboards/pages/6_%F0%9F%92%BE_Data_Manager.py): `dashboards/pages/6_💾_Data_Manager.py`
- [Strategy resolver](https://github.com/ranjeet867/metatrader/blob/main/dashboards/components/strategy_resolver.py): `dashboards/components/strategy_resolver.py`
- [Dashboard state](https://github.com/ranjeet867/metatrader/blob/main/dashboards/components/state.py): `dashboards/components/state.py`

### Risk and execution

- [Risk and time guards](https://github.com/ranjeet867/metatrader/blob/main/core/risk_engine.py): `core/risk_engine.py`
- [Deployment registry](https://github.com/ranjeet867/metatrader/blob/main/core/deployment.py): `core/deployment.py`
- [Live execution](https://github.com/ranjeet867/metatrader/blob/main/core/live_executor.py): `core/live_executor.py`
- [Paper trading](https://github.com/ranjeet867/metatrader/blob/main/core/paper_loop.py): `core/paper_loop.py`
- [Position management](https://github.com/ranjeet867/metatrader/blob/main/core/position_manager.py): `core/position_manager.py`

### Accounts and state

- [SQLite persistence](https://github.com/ranjeet867/metatrader/blob/main/core/storage.py): `core/storage.py`
- [Multi-account registry](https://github.com/ranjeet867/metatrader/blob/main/core/account_manager.py): `core/account_manager.py`
- [Trade journal](https://github.com/ranjeet867/metatrader/blob/main/core/journal.py): `core/journal.py`

### Other components

- **Trader**
- **MT5 file bridge**

## Connections

- Trader → Operations dashboard: uses (evidence: `README.md`)
- Operations dashboard → Dashboard state: loads state (evidence: `dashboards/app.py`)
- Operations dashboard → Backtest and research UI: offers research
- Operations dashboard → Data manager UI: offers data management (evidence: `dashboards/app.py`)
- Backtest and research UI → Backtest engine: runs backtests (evidence: `dashboards/pages/1_📊_Backtest.py`)
- Backtest and research UI → Backtest statistics: computes metrics (evidence: `dashboards/pages/1_📊_Backtest.py`)
- Backtest and research UI → Strategy resolver: resolves strategies (evidence: `dashboards/pages/1_📊_Backtest.py`)
- Strategy library UI → Edge catalog: reads edge data (evidence: `dashboards/pages/7_🏛️_Strategy_Library.py`)
- Strategy library UI → Replay parity gate: checks parity (evidence: `dashboards/pages/7_🏛️_Strategy_Library.py`)
- Data manager UI → Candle data service: manages candles (evidence: `dashboards/pages/6_💾_Data_Manager.py`)
- Candle data service → MT5 file bridge: fetches candles (evidence: `core/data.py`)
- Candle data service → SQLite persistence: persists candles (evidence: `core/data.py`)
- Backtest engine → Strategy implementations: evaluates signals (evidence: `core/backtest.py`)
- Backtest engine → Backtest statistics: produces results
- Portfolio optimizer → Backtest engine: sweeps candidates (evidence: `README.md`)
- Portfolio optimizer → Backtest statistics: computes statistics (evidence: `README.md`)
- Portfolio optimizer → Edge catalog: updates catalog
- Deployment registry → Multi-account registry: uses accounts (evidence: `core/deployment.py`)
- Live execution → Risk and time guards: checks safety gates
- Deployment registry → Live execution: starts live runs
- Deployment registry → Paper trading: starts paper runs
- Position management → Trade journal: records closes (evidence: `core/position_manager.py`)
- Position management → Multi-account registry: scopes account (evidence: `core/position_manager.py`)
- Replay parity gate → SQLite persistence: reads persisted results (evidence: `core/parity_gate.py`)
