# jdchoutrade/trading architecture

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

## Overview

QRA Gold Terminal is a multi-asset technical-analysis and trading terminal, centered on live XAUUSD signals. The principal workflow is market-feed ticks and candles → source-specific analysis through the quantitative pipeline → qualified signals and optional asynchronous AI review → persisted signal history and spread-aware outcome tracking → terminal views and alerts. The README also describes macro/news intelligence, replay, paper trading, statistics, and settings; these are represented where the tree supports them. Some page/API wiring and unsampled subsystems are documented rather than verified in source excerpts.

Main entry points: [`server/engine/pipeline.ts`](https://github.com/jdchoutrade/trading/blob/main/server/engine/pipeline.ts) (Analysis Pipeline), [`server.ts`](https://github.com/jdchoutrade/trading/blob/main/server.ts) (Server Bootstrap), [`src/App.tsx`](https://github.com/jdchoutrade/trading/blob/main/src/App.tsx) (Terminal Shell), [`server/routes.ts`](https://github.com/jdchoutrade/trading/blob/main/server/routes.ts) (HTTP API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Terminal UI"]
  node_app["Terminal Shell<br/>[App.tsx]"]
  node_context["Terminal State"]
  node_indicators_ui["Indicators View<br/>[IndicatorsPage.tsx]"]
  node_desk_ui["Market Desk<br/>[DeskPage.tsx]"]
  node_signals_ui["Signal History<br/>[SignalsPage.tsx]"]
  node_paper_ui["Paper Trading"]
  node_replay_ui["Replay Backtest"]
  node_settings_ui["Settings<br/>[SettingsPage.tsx]"]
end

subgraph group_market["Market Inputs"]
  node_feed["TradingView Feed<br/>[tvFeed.ts]"]
  node_aggregator["Tick Aggregator<br/>[aggregator.ts]"]
  node_provider["Market Provider<br/>[dataProvider.ts]"]
  node_intelligence["Market Intelligence"]
end

subgraph group_analysis["Signal Analysis"]
  node_ingest["Signal Ingest<br/>[sourceIngest.ts]"]
  node_pipeline["Analysis Pipeline<br/>[pipeline.ts]"]
  node_regime["Regime Analysis<br/>[L1_regime.ts]"]
  node_mtf["Timeframe Analysis"]
  node_liquidity["Liquidity Mapping<br/>[L3_liquidity.ts]"]
  node_smc["SMC Structures<br/>[L4_smc.ts]"]
  node_patterns["Patterns and Momentum<br/>[L5_L8_patterns.ts]"]
  node_session["Session Filter<br/>[L9_session.ts]"]
  node_confirmation["Confirmations"]
  node_scoring["Signal and Plan<br/>[L11_scoring.ts]"]
  node_weights["Source Weights<br/>[sourceConfig.ts]"]
end

subgraph group_lifecycle["Signal Lifecycle"]
  node_emitter["Signal Emitter<br/>[signalEmitter.ts]"]
  node_outcomes["Outcome Tracker<br/>[outcomeTracker.ts]"]
  node_stats["Signal Statistics<br/>[statsEngine.ts]"]
end

subgraph group_storage["Persistence"]
  node_sqlite[("Signal Store<br/>[sqliteStore.ts]")]
  node_store[("General Store<br/>[store.ts]")]
  node_neon[("Neon Snapshots")]
end

subgraph group_api["API and Integrations"]
  node_ai["AI Review<br/>[deepseek.ts]"]
  node_server["Server Bootstrap<br/>[server.ts]"]
  node_routes["HTTP API<br/>[routes.ts]"]
  node_telegram["Telegram Alerts<br/>[bot.ts]"]
end

node_user(("Trader"))

node_user -->|"uses"| node_app
node_app -->|"provides state"| node_context
node_app -->|"renders"| node_indicators_ui
node_app -->|"renders"| node_desk_ui
node_app -->|"renders"| node_signals_ui
node_app -->|"renders"| node_paper_ui
node_app -->|"renders"| node_replay_ui
node_app -->|"renders"| node_settings_ui
node_indicators_ui -->|"uses state"| node_context
node_desk_ui -->|"uses state"| node_context
node_paper_ui -->|"uses state"| node_context
node_settings_ui -->|"uses state"| node_context
node_context -.->|"requests snapshot"| node_routes
node_server -->|"mounts"| node_routes
node_server -->|"starts"| node_provider
node_server -->|"starts"| node_intelligence
node_server -->|"starts"| node_outcomes
node_server -->|"starts"| node_emitter
node_server -->|"configures"| node_sqlite
node_server -->|"configures"| node_store
node_server -->|"configures"| node_neon
node_feed -->|"streams ticks"| node_provider
node_aggregator -->|"aggregates ticks"| node_provider
node_provider -->|"supplies candles"| node_ingest
node_intelligence -->|"supplies context"| node_ingest
node_ingest -->|"loads configs"| node_weights
node_ingest -->|"runs analyses"| node_pipeline
node_pipeline -->|"evaluates regime"| node_regime
node_pipeline -->|"evaluates timeframes"| node_mtf
node_pipeline -->|"maps levels"| node_liquidity
node_pipeline -->|"detects structures"| node_smc
node_pipeline -->|"analyzes momentum"| node_patterns
node_pipeline -->|"filters session"| node_session
node_pipeline -->|"evaluates confirmations"| node_confirmation
node_pipeline -->|"builds trade plan"| node_scoring
node_ingest -->|"requests review"| node_ai
node_ingest -->|"publishes signals"| node_emitter
node_emitter -->|"persists signals"| node_sqlite
node_emitter -->|"registers signals"| node_outcomes
node_emitter -->|"sends alerts"| node_telegram
node_outcomes -->|"updates outcomes"| node_sqlite
node_outcomes -->|"reads candles"| node_provider
node_outcomes -->|"sends lifecycle alerts"| node_telegram
node_routes -->|"runs analysis"| node_pipeline
node_routes -->|"serves desk data"| node_intelligence
node_routes -->|"requests review"| node_ai
node_routes -->|"reads signal history"| node_sqlite
node_routes -->|"uses persistence"| node_store

click node_app "https://github.com/jdchoutrade/trading/blob/main/src/App.tsx"
click node_context "https://github.com/jdchoutrade/trading/blob/main/src/context/TerminalContext.tsx"
click node_indicators_ui "https://github.com/jdchoutrade/trading/blob/main/src/pages/IndicatorsPage.tsx"
click node_desk_ui "https://github.com/jdchoutrade/trading/blob/main/src/pages/DeskPage.tsx"
click node_signals_ui "https://github.com/jdchoutrade/trading/blob/main/src/pages/SignalsPage.tsx"
click node_paper_ui "https://github.com/jdchoutrade/trading/blob/main/src/pages/PaperTradingPage.tsx"
click node_replay_ui "https://github.com/jdchoutrade/trading/blob/main/src/pages/ReplayBacktestPage.tsx"
click node_settings_ui "https://github.com/jdchoutrade/trading/blob/main/src/pages/SettingsPage.tsx"
click node_feed "https://github.com/jdchoutrade/trading/blob/main/server/market/tvFeed.ts"
click node_aggregator "https://github.com/jdchoutrade/trading/blob/main/server/market/aggregator.ts"
click node_provider "https://github.com/jdchoutrade/trading/blob/main/server/market/dataProvider.ts"
click node_intelligence "https://github.com/jdchoutrade/trading/blob/main/server/intel/marketIntelligence.ts"
click node_ingest "https://github.com/jdchoutrade/trading/blob/main/server/engine/sourceIngest.ts"
click node_pipeline "https://github.com/jdchoutrade/trading/blob/main/server/engine/pipeline.ts"
click node_regime "https://github.com/jdchoutrade/trading/blob/main/server/engine/L1_regime.ts"
click node_mtf "https://github.com/jdchoutrade/trading/blob/main/server/engine/L2_multitimeframe.ts"
click node_liquidity "https://github.com/jdchoutrade/trading/blob/main/server/engine/L3_liquidity.ts"
click node_smc "https://github.com/jdchoutrade/trading/blob/main/server/engine/L4_smc.ts"
click node_patterns "https://github.com/jdchoutrade/trading/blob/main/server/engine/L5_L8_patterns.ts"
click node_session "https://github.com/jdchoutrade/trading/blob/main/server/engine/L9_session.ts"
click node_confirmation "https://github.com/jdchoutrade/trading/blob/main/server/engine/L10_confirmation.ts"
click node_scoring "https://github.com/jdchoutrade/trading/blob/main/server/engine/L11_scoring.ts"
click node_weights "https://github.com/jdchoutrade/trading/blob/main/server/engine/sourceConfig.ts"
click node_ai "https://github.com/jdchoutrade/trading/blob/main/server/ai/deepseek.ts"
click node_emitter "https://github.com/jdchoutrade/trading/blob/main/server/engine/signalEmitter.ts"
click node_outcomes "https://github.com/jdchoutrade/trading/blob/main/server/market/outcomeTracker.ts"
click node_stats "https://github.com/jdchoutrade/trading/blob/main/server/stats/statsEngine.ts"
click node_sqlite "https://github.com/jdchoutrade/trading/blob/main/server/db/sqliteStore.ts"
click node_store "https://github.com/jdchoutrade/trading/blob/main/server/db/store.ts"
click node_neon "https://github.com/jdchoutrade/trading/blob/main/server/db/neonSnapshotStore.ts"
click node_server "https://github.com/jdchoutrade/trading/blob/main/server.ts"
click node_routes "https://github.com/jdchoutrade/trading/blob/main/server/routes.ts"
click node_telegram "https://github.com/jdchoutrade/trading/blob/main/server/telegram/bot.ts"

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_app,node_context,node_indicators_ui,node_desk_ui,node_signals_ui,node_paper_ui,node_replay_ui,node_settings_ui toneBlue
class node_feed,node_aggregator,node_provider,node_intelligence toneAmber
class node_ingest,node_pipeline,node_regime,node_mtf,node_liquidity,node_smc,node_patterns,node_session,node_confirmation,node_scoring,node_weights toneMint
class node_emitter,node_outcomes,node_stats toneRose
class node_sqlite,node_store,node_neon,node_user toneIndigo
class node_ai,node_server,node_routes,node_telegram toneTeal
```

## Components

### Terminal UI

- [Terminal Shell](https://github.com/jdchoutrade/trading/blob/main/src/App.tsx): `src/App.tsx`
- [Terminal State](https://github.com/jdchoutrade/trading/blob/main/src/context/TerminalContext.tsx): `src/context/TerminalContext.tsx`
- [Indicators View](https://github.com/jdchoutrade/trading/blob/main/src/pages/IndicatorsPage.tsx): `src/pages/IndicatorsPage.tsx`
- [Market Desk](https://github.com/jdchoutrade/trading/blob/main/src/pages/DeskPage.tsx): `src/pages/DeskPage.tsx`
- [Signal History](https://github.com/jdchoutrade/trading/blob/main/src/pages/SignalsPage.tsx): `src/pages/SignalsPage.tsx`
- [Paper Trading](https://github.com/jdchoutrade/trading/blob/main/src/pages/PaperTradingPage.tsx): `src/pages/PaperTradingPage.tsx`
- [Replay Backtest](https://github.com/jdchoutrade/trading/blob/main/src/pages/ReplayBacktestPage.tsx): `src/pages/ReplayBacktestPage.tsx`
- [Settings](https://github.com/jdchoutrade/trading/blob/main/src/pages/SettingsPage.tsx): `src/pages/SettingsPage.tsx`

### Market Inputs

- [TradingView Feed](https://github.com/jdchoutrade/trading/blob/main/server/market/tvFeed.ts): `server/market/tvFeed.ts`
- [Tick Aggregator](https://github.com/jdchoutrade/trading/blob/main/server/market/aggregator.ts): `server/market/aggregator.ts`
- [Market Provider](https://github.com/jdchoutrade/trading/blob/main/server/market/dataProvider.ts): `server/market/dataProvider.ts`
- [Market Intelligence](https://github.com/jdchoutrade/trading/blob/main/server/intel/marketIntelligence.ts): `server/intel/marketIntelligence.ts`

### Signal Analysis

- [Signal Ingest](https://github.com/jdchoutrade/trading/blob/main/server/engine/sourceIngest.ts): `server/engine/sourceIngest.ts`
- [Analysis Pipeline](https://github.com/jdchoutrade/trading/blob/main/server/engine/pipeline.ts): `server/engine/pipeline.ts`
- [Regime Analysis](https://github.com/jdchoutrade/trading/blob/main/server/engine/L1_regime.ts): `server/engine/L1_regime.ts`
- [Timeframe Analysis](https://github.com/jdchoutrade/trading/blob/main/server/engine/L2_multitimeframe.ts): `server/engine/L2_multitimeframe.ts`
- [Liquidity Mapping](https://github.com/jdchoutrade/trading/blob/main/server/engine/L3_liquidity.ts): `server/engine/L3_liquidity.ts`
- [SMC Structures](https://github.com/jdchoutrade/trading/blob/main/server/engine/L4_smc.ts): `server/engine/L4_smc.ts`
- [Patterns and Momentum](https://github.com/jdchoutrade/trading/blob/main/server/engine/L5_L8_patterns.ts): `server/engine/L5_L8_patterns.ts`
- [Session Filter](https://github.com/jdchoutrade/trading/blob/main/server/engine/L9_session.ts): `server/engine/L9_session.ts`
- [Confirmations](https://github.com/jdchoutrade/trading/blob/main/server/engine/L10_confirmation.ts): `server/engine/L10_confirmation.ts`
- [Signal and Plan](https://github.com/jdchoutrade/trading/blob/main/server/engine/L11_scoring.ts): `server/engine/L11_scoring.ts`
- [Source Weights](https://github.com/jdchoutrade/trading/blob/main/server/engine/sourceConfig.ts): `server/engine/sourceConfig.ts`

### Signal Lifecycle

- [Signal Emitter](https://github.com/jdchoutrade/trading/blob/main/server/engine/signalEmitter.ts): `server/engine/signalEmitter.ts`
- [Outcome Tracker](https://github.com/jdchoutrade/trading/blob/main/server/market/outcomeTracker.ts): `server/market/outcomeTracker.ts`
- [Signal Statistics](https://github.com/jdchoutrade/trading/blob/main/server/stats/statsEngine.ts): `server/stats/statsEngine.ts`

### Persistence

- [Signal Store](https://github.com/jdchoutrade/trading/blob/main/server/db/sqliteStore.ts): `server/db/sqliteStore.ts`
- [General Store](https://github.com/jdchoutrade/trading/blob/main/server/db/store.ts): `server/db/store.ts`
- [Neon Snapshots](https://github.com/jdchoutrade/trading/blob/main/server/db/neonSnapshotStore.ts): `server/db/neonSnapshotStore.ts`

### API and Integrations

- [AI Review](https://github.com/jdchoutrade/trading/blob/main/server/ai/deepseek.ts): `server/ai/deepseek.ts`
- [Server Bootstrap](https://github.com/jdchoutrade/trading/blob/main/server.ts): `server.ts`
- [HTTP API](https://github.com/jdchoutrade/trading/blob/main/server/routes.ts): `server/routes.ts`
- [Telegram Alerts](https://github.com/jdchoutrade/trading/blob/main/server/telegram/bot.ts): `server/telegram/bot.ts`

### Other components

- **Trader**

## Connections

- Trader → Terminal Shell: uses
- Terminal Shell → Terminal State: provides state (evidence: `src/App.tsx`)
- Terminal Shell → Indicators View: renders (evidence: `src/App.tsx`)
- Terminal Shell → Market Desk: renders (evidence: `src/App.tsx`)
- Terminal Shell → Signal History: renders (evidence: `src/App.tsx`)
- Terminal Shell → Paper Trading: renders (evidence: `src/App.tsx`)
- Terminal Shell → Replay Backtest: renders (evidence: `src/App.tsx`)
- Terminal Shell → Settings: renders (evidence: `src/App.tsx`)
- Indicators View → Terminal State: uses state (evidence: `src/pages/IndicatorsPage.tsx`)
- Market Desk → Terminal State: uses state (evidence: `src/pages/DeskPage.tsx`)
- Paper Trading → Terminal State: uses state (evidence: `src/pages/PaperTradingPage.tsx`)
- Settings → Terminal State: uses state (evidence: `src/pages/SettingsPage.tsx`)
- Terminal State → HTTP API: requests snapshot
- Server Bootstrap → HTTP API: mounts (evidence: `server.ts`)
- Server Bootstrap → Market Provider: starts (evidence: `server.ts`)
- Server Bootstrap → Market Intelligence: starts (evidence: `server.ts`)
- Server Bootstrap → Outcome Tracker: starts (evidence: `server.ts`)
- Server Bootstrap → Signal Emitter: starts (evidence: `server.ts`)
- Server Bootstrap → Signal Store: configures (evidence: `server.ts`)
- Server Bootstrap → General Store: configures (evidence: `server.ts`)
- Server Bootstrap → Neon Snapshots: configures (evidence: `server.ts`)
- TradingView Feed → Market Provider: streams ticks (evidence: `server/market/dataProvider.ts`)
- Tick Aggregator → Market Provider: aggregates ticks (evidence: `server/market/dataProvider.ts`)
- Market Provider → Signal Ingest: supplies candles (evidence: `server/engine/sourceIngest.ts`)
- Market Intelligence → Signal Ingest: supplies context (evidence: `server/engine/sourceIngest.ts`)
- Signal Ingest → Source Weights: loads configs (evidence: `server/engine/sourceIngest.ts`)
- Signal Ingest → Analysis Pipeline: runs analyses (evidence: `server/engine/sourceIngest.ts`)
- Analysis Pipeline → Regime Analysis: evaluates regime (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → Timeframe Analysis: evaluates timeframes (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → Liquidity Mapping: maps levels (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → SMC Structures: detects structures (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → Patterns and Momentum: analyzes momentum (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → Session Filter: filters session (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → Confirmations: evaluates confirmations (evidence: `server/engine/pipeline.ts`)
- Analysis Pipeline → Signal and Plan: builds trade plan (evidence: `server/engine/pipeline.ts`)
- Signal Ingest → AI Review: requests review (evidence: `server/engine/sourceIngest.ts`)
- Signal Ingest → Signal Emitter: publishes signals (evidence: `server/engine/sourceIngest.ts`)
- Signal Emitter → Signal Store: persists signals (evidence: `server/engine/signalEmitter.ts`)
- Signal Emitter → Outcome Tracker: registers signals (evidence: `server/engine/signalEmitter.ts`)
- Signal Emitter → Telegram Alerts: sends alerts (evidence: `server/engine/signalEmitter.ts`)
- Outcome Tracker → Signal Store: updates outcomes (evidence: `server/market/outcomeTracker.ts`)
- Outcome Tracker → Market Provider: reads candles (evidence: `server/market/outcomeTracker.ts`)
- Outcome Tracker → Telegram Alerts: sends lifecycle alerts (evidence: `server/market/outcomeTracker.ts`)
- HTTP API → Analysis Pipeline: runs analysis (evidence: `server/routes.ts`)
- HTTP API → Market Intelligence: serves desk data (evidence: `server/routes.ts`)
- HTTP API → AI Review: requests review (evidence: `server/routes.ts`)
- HTTP API → Signal Store: reads signal history (evidence: `server/routes.ts`)
- HTTP API → General Store: uses persistence (evidence: `server/routes.ts`)
