# sparlit/forexscalpper architecture

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

- Interactive diagram: https://gitdiagram.com/sparlit/forexscalpper
- Repository: https://github.com/sparlit/forexscalpper

## Overview

#### Purpose and Entry Points
EAQTS is a Python-based autonomous multi-asset trading system centered on analysis, deterministic risk controls, broker execution, persistent trade state, and operator visibility. The primary launch path is `main.py`; its trading integration spans `connector.py` and the MetaTrader 5 Expert Advisor `ScalperBrainEA.mq5`. Desktop and browser-facing monitoring surfaces are represented by `gui.py` and `dashboard.html`.

#### Application Control and Orchestration
The runtime’s coordinating layer appears to combine a central trading loop with supervised AI/agent workflows. `main.py` is the process entry point, while `brain_agents_orchestrator.py` coordinates specialized brain agents and `supervisor_agent.py` provides higher-level oversight/intervention. `config.py` supplies runtime parameters rather than allowing intelligence components to define operational boundaries.

#### Market Intelligence and Signal Generation
Market inputs are transformed into trading opinions through conventional indicators, predictive models, and agent reasoning. `indicators.py` is the technical-analysis boundary; `predictive_brain.py` and `brain.py` provide model-driven decision logic. `eaqts_planes.py` likely organizes the broader control/data/intelligence/risk conceptual planes described by the system specification, making it a key integration point rather than a strategy leaf module.

#### Risk, Safety, and Release Governance
Trade admission is expected to be governed separately from signal generation: model recommendations must pass hard risk and safety checks before execution. `release_gates.py` is the explicit governance/release boundary, and `eaqts_planes.py` likely hosts plane-level safety coordination. The design documents establish a stateful safety model—normal, defensive, halted—with circuit-breaker and reconciliation requirements; operational detail is documented in `docs/CIRCUIT_BREAKER.md` and `docs/RUNBOOK.md`.

#### Execution, Broker, and External Integrations
`connector.py` forms the principal broker/MT5 boundary, with `ScalperBrainEA.mq5` implementing the terminal-side EA counterpart. The optional institutional integration layer broadens this boundary to FIX, universal brokers, execution algorithms, and a Go gateway: `institutional_integrations/fix_engine.py`, `institutional_integrations/universal_broker_adapter.py`, and `institutional_integrations/go_gateway.py`. This separation is material: internal decisions should become normalized orders before reaching venue-specific adapters.

#### State, Events, and Reconciliation
The system has explicit persistence and asynchronous coordination components. `database.py` owns durable application/trade state, while `event_bus.py` decouples publishers and consumers across market, decision, execution, and telemetry flows. Persistent reconciliation between recorded trades and broker positions is a critical safety boundary; durable state likely also supports restart recovery, auditability, and learning history.

#### Learning, Research, and Institutional Extensions
The repository includes an extensible advanced-analytics suite beyond the core scalp-trading path: `institutional_integrations/comprehensive_suite.py`, `institutional_integrations/backtest_engine.py`, and `institutional_integrations/trade_memory_protocol.py`. Additional modules cover portfolio optimization, causal/ML analysis, DRL execution, order-flow, and local/quantum-oriented model experiments. These should be treated as proposal or enrichment producers; their outputs remain downstream of deterministic risk and execution controls.

#### Operations and Notifications
Operators can inspect runtime behavior through `gui.py`, `dashboard.html`, and operational documentation in `docs/ARCHITECTURE.md`. `telegram_bot.py` is the alerting/remote-notification integration. The intended deployment is Python on desktop/server infrastructure, with MT5 as the material execution runtime and local database storage; institutional adapters may introduce external broker, FIX, gateway, and data-service dependencies.

Main entry points: [`event_bus.py`](https://github.com/sparlit/forexscalpper/blob/main/event_bus.py) (Event bus), [`brain.py`](https://github.com/sparlit/forexscalpper/blob/main/brain.py) (Trading brain), [`release_gates.py`](https://github.com/sparlit/forexscalpper/blob/main/release_gates.py) (Risk release gates), [`eaqts_planes.py`](https://github.com/sparlit/forexscalpper/blob/main/eaqts_planes.py) (Control planes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Trading Core"]
  node_main["Process entry<br/>Python entrypoint<br/>[main.py]"]
  node_config["Runtime configuration<br/>configuration boundary<br/>[config.py]"]
  node_planes{{"Control planes<br/>integration coordinator<br/>[eaqts_planes.py]"}}
  node_agent_orchestrator["Brain agent workflows<br/>agent orchestrator"]
  node_supervisor["Supervisor agent<br/>oversight agent"]
  node_indicators["Technical indicators<br/>market analysis<br/>[indicators.py]"]
  node_predictive_brain["Predictive model<br/>decision model"]
  node_brain["Trading brain<br/>decision logic<br/>[brain.py]"]
  node_release_gates{{"Risk release gates<br/>deterministic risk control<br/>[release_gates.py]"}}
end

subgraph group_execution["Execution &amp; State"]
  node_event_bus["Event bus<br/>asynchronous messaging<br/>[event_bus.py]"]
  node_database[("Trade state store<br/>durable state<br/>[database.py]")]
  node_connector["MT5 connector<br/>broker adapter<br/>[connector.py]"]
  node_mt5_ea["MT5 Expert Advisor<br/>terminal-side executor<br/>[ScalperBrainEA.mq5]"]
end

subgraph group_extensions["Institutional &amp; Research"]
  node_fix_engine["FIX engine<br/>institutional adapter<br/>[fix_engine.py]"]
  node_universal_broker["Universal broker adapter"]
  node_go_gateway["Go gateway<br/>external gateway<br/>[go_gateway.py]"]
  node_advanced_suite["Advanced analytics suite<br/>research coordinator"]
  node_backtest["Backtest engine<br/>research engine<br/>[backtest_engine.py]"]
  node_trade_memory["Trade memory protocol<br/>learning state"]
end

subgraph group_operations["Operations"]
  node_gui["Desktop monitor<br/>operator UI<br/>[gui.py]"]
  node_dashboard["Browser dashboard<br/>operator UI<br/>[dashboard.html]"]
  node_telegram["Telegram alerts<br/>notification integration<br/>[telegram_bot.py]"]
  node_circuit_breaker["Circuit-breaker procedure<br/>safety runbook<br/>[CIRCUIT_BREAKER.md]"]
  node_runbook["Operations runbook<br/>operational procedure<br/>[RUNBOOK.md]"]
end

node_main -->|"loads"| node_config
node_main -->|"starts"| node_planes
node_planes -->|"coordinates"| node_agent_orchestrator
node_agent_orchestrator -->|"supervised by"| node_supervisor
node_indicators -->|"market features"| node_brain
node_predictive_brain -->|"model opinion"| node_brain
node_agent_orchestrator -->|"agent reasoning"| node_brain
node_advanced_suite -.->|"enrichment proposals"| node_brain
node_backtest -->|"research results"| node_advanced_suite
node_trade_memory -->|"learning history"| node_advanced_suite
node_brain -->|"recommendation"| node_release_gates
node_planes -->|"safety coordination"| node_release_gates
node_config -->|"limits"| node_release_gates
node_release_gates -->|"approved normalized order"| node_connector
node_connector -->|"broker commands"| node_mt5_ea
node_fix_engine -->|"institutional order route"| node_universal_broker
node_universal_broker -->|"gateway route"| node_go_gateway
node_event_bus -->|"durable events"| node_database
node_connector -->|"trades and positions"| node_database
node_connector -->|"execution events"| node_event_bus
node_planes -->|"publishes telemetry"| node_event_bus
node_event_bus -->|"runtime status"| node_gui
node_event_bus -->|"runtime status"| node_dashboard
node_event_bus -->|"alerts"| node_telegram
node_circuit_breaker -.->|"halt policy"| node_release_gates
node_runbook -.->|"reconciliation procedure"| node_database

click node_main "https://github.com/sparlit/forexscalpper/blob/main/main.py"
click node_config "https://github.com/sparlit/forexscalpper/blob/main/config.py"
click node_planes "https://github.com/sparlit/forexscalpper/blob/main/eaqts_planes.py"
click node_agent_orchestrator "https://github.com/sparlit/forexscalpper/blob/main/brain_agents_orchestrator.py"
click node_supervisor "https://github.com/sparlit/forexscalpper/blob/main/supervisor_agent.py"
click node_indicators "https://github.com/sparlit/forexscalpper/blob/main/indicators.py"
click node_predictive_brain "https://github.com/sparlit/forexscalpper/blob/main/predictive_brain.py"
click node_brain "https://github.com/sparlit/forexscalpper/blob/main/brain.py"
click node_release_gates "https://github.com/sparlit/forexscalpper/blob/main/release_gates.py"
click node_event_bus "https://github.com/sparlit/forexscalpper/blob/main/event_bus.py"
click node_database "https://github.com/sparlit/forexscalpper/blob/main/database.py"
click node_connector "https://github.com/sparlit/forexscalpper/blob/main/connector.py"
click node_mt5_ea "https://github.com/sparlit/forexscalpper/blob/main/ScalperBrainEA.mq5"
click node_fix_engine "https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/fix_engine.py"
click node_universal_broker "https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/universal_broker_adapter.py"
click node_go_gateway "https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/go_gateway.py"
click node_advanced_suite "https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/comprehensive_suite.py"
click node_backtest "https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/backtest_engine.py"
click node_trade_memory "https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/trade_memory_protocol.py"
click node_gui "https://github.com/sparlit/forexscalpper/blob/main/gui.py"
click node_dashboard "https://github.com/sparlit/forexscalpper/blob/main/dashboard.html"
click node_telegram "https://github.com/sparlit/forexscalpper/blob/main/telegram_bot.py"
click node_circuit_breaker "https://github.com/sparlit/forexscalpper/blob/main/docs/CIRCUIT_BREAKER.md"
click node_runbook "https://github.com/sparlit/forexscalpper/blob/main/docs/RUNBOOK.md"

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_main,node_config,node_planes,node_agent_orchestrator,node_supervisor,node_indicators,node_predictive_brain,node_brain,node_release_gates toneBlue
class node_event_bus,node_database,node_connector,node_mt5_ea toneAmber
class node_fix_engine,node_universal_broker,node_go_gateway,node_advanced_suite,node_backtest,node_trade_memory toneMint
class node_gui,node_dashboard,node_telegram,node_circuit_breaker,node_runbook toneRose
```

## Components

### Trading Core

Coordinates analysis, agents, and deterministic admission.

- [Process entry](https://github.com/sparlit/forexscalpper/blob/main/main.py): Python entrypoint · `main.py`
- [Runtime configuration](https://github.com/sparlit/forexscalpper/blob/main/config.py): configuration boundary · Supplies operating parameters and limits. · `config.py`
- [Control planes](https://github.com/sparlit/forexscalpper/blob/main/eaqts_planes.py): integration coordinator · Coordinates intelligence, control, data, and safety planes. · `eaqts_planes.py`
- [Brain agent workflows](https://github.com/sparlit/forexscalpper/blob/main/brain_agents_orchestrator.py): agent orchestrator · `brain_agents_orchestrator.py`
- [Supervisor agent](https://github.com/sparlit/forexscalpper/blob/main/supervisor_agent.py): oversight agent · Can intervene in specialized agent workflows. · `supervisor_agent.py`
- [Technical indicators](https://github.com/sparlit/forexscalpper/blob/main/indicators.py): market analysis · `indicators.py`
- [Predictive model](https://github.com/sparlit/forexscalpper/blob/main/predictive_brain.py): decision model · `predictive_brain.py`
- [Trading brain](https://github.com/sparlit/forexscalpper/blob/main/brain.py): decision logic · `brain.py`
- [Risk release gates](https://github.com/sparlit/forexscalpper/blob/main/release_gates.py): deterministic risk control · Admits or blocks recommendations before execution. · `release_gates.py`

### Execution & State

Normalizes, executes, records, and reconciles trades.

- [Event bus](https://github.com/sparlit/forexscalpper/blob/main/event_bus.py): asynchronous messaging · Decouples market, decision, execution, and telemetry flows. · `event_bus.py`
- [Trade state store](https://github.com/sparlit/forexscalpper/blob/main/database.py): durable state · Stores trade records for recovery, audit, and reconciliation. · `database.py`
- [MT5 connector](https://github.com/sparlit/forexscalpper/blob/main/connector.py): broker adapter · Principal Python broker and MT5 boundary. · `connector.py`
- [MT5 Expert Advisor](https://github.com/sparlit/forexscalpper/blob/main/ScalperBrainEA.mq5): terminal-side executor · `ScalperBrainEA.mq5`

### Institutional & Research

Optional adapters and analytics enrich decision proposals.

- [FIX engine](https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/fix_engine.py): institutional adapter · `institutional_integrations/fix_engine.py`
- [Universal broker adapter](https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/universal_broker_adapter.py): broker adapter · `institutional_integrations/universal_broker_adapter.py`
- [Go gateway](https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/go_gateway.py): external gateway · `institutional_integrations/go_gateway.py`
- [Advanced analytics suite](https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/comprehensive_suite.py): research coordinator · Produces enriched proposals outside the deterministic execution path. · `institutional_integrations/comprehensive_suite.py`
- [Backtest engine](https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/backtest_engine.py): research engine · `institutional_integrations/backtest_engine.py`
- [Trade memory protocol](https://github.com/sparlit/forexscalpper/blob/main/institutional_integrations/trade_memory_protocol.py): learning state · `institutional_integrations/trade_memory_protocol.py`

### Operations

Operator visibility, alerts, and safety procedures.

- [Desktop monitor](https://github.com/sparlit/forexscalpper/blob/main/gui.py): operator UI · `gui.py`
- [Browser dashboard](https://github.com/sparlit/forexscalpper/blob/main/dashboard.html): operator UI · `dashboard.html`
- [Telegram alerts](https://github.com/sparlit/forexscalpper/blob/main/telegram_bot.py): notification integration · `telegram_bot.py`
- [Circuit-breaker procedure](https://github.com/sparlit/forexscalpper/blob/main/docs/CIRCUIT_BREAKER.md): safety runbook · Defines normal, defensive, and halted safety operation. · `docs/CIRCUIT_BREAKER.md`
- [Operations runbook](https://github.com/sparlit/forexscalpper/blob/main/docs/RUNBOOK.md): operational procedure · `docs/RUNBOOK.md`

## Connections

- Process entry → Runtime configuration: loads
- Process entry → Control planes: starts
- Control planes → Brain agent workflows: coordinates
- Brain agent workflows → Supervisor agent: supervised by
- Technical indicators → Trading brain: market features
- Predictive model → Trading brain: model opinion
- Brain agent workflows → Trading brain: agent reasoning
- Advanced analytics suite → Trading brain: enrichment proposals
- Backtest engine → Advanced analytics suite: research results
- Trade memory protocol → Advanced analytics suite: learning history
- Trading brain → Risk release gates: recommendation
- Control planes → Risk release gates: safety coordination
- Runtime configuration → Risk release gates: limits
- Risk release gates → MT5 connector: approved normalized order
- MT5 connector → MT5 Expert Advisor: broker commands
- FIX engine → Universal broker adapter: institutional order route
- Universal broker adapter → Go gateway: gateway route
- Event bus → Trade state store: durable events
- MT5 connector → Trade state store: trades and positions
- MT5 connector → Event bus: execution events
- Control planes → Event bus: publishes telemetry
- Event bus → Desktop monitor: runtime status
- Event bus → Browser dashboard: runtime status
- Event bus → Telegram alerts: alerts
- Circuit-breaker procedure → Risk release gates: halt policy
- Operations runbook → Trade state store: reconciliation procedure
