# spacerexxx/tradingagents-webui architecture

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

- Interactive diagram: https://gitdiagram.com/spacerexxx/tradingagents-webui
- Repository: https://github.com/spacerexxx/tradingagents-webui

## Overview

TradingAgents WebUI is an A-share-focused multi-agent investment research product, exposed through a React interface, FastAPI API, and a CLI that reuses the engine. The main workflow accepts a ticker and analysis settings, runs analyst research and quality checks, then forecasting, bull/bear debate, trading, risk review, and a portfolio decision; progress and reports are returned to the user. The README documents history, diagnostics, provider configuration, prompts, quotes, PDF export, and token/cost statistics. Engine-to-backend links are based on the documented architecture; unsampled route and service internals are not asserted.

Main entry points: [`tradingagents/graph/trading_graph.py`](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/graph/trading_graph.py) (TradingAgents graph), [`backend/main.py`](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/main.py) (FastAPI app), [`frontend/src/App.tsx`](https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/App.tsx) (React WebUI), [`backend/routes/analysis.py`](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/routes/analysis.py) (Analysis endpoints)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interfaces"]
  node_web["React WebUI<br/>[App.tsx]"]
  node_api_client["API client<br/>[client.ts]"]
  node_stream["Analysis stream"]
  node_cli["CLI<br/>[main.py]"]
end

subgraph group_api["API services"]
  node_fastapi["FastAPI app<br/>[main.py]"]
  node_analysis_route["Analysis endpoints<br/>[analysis.py]"]
  node_other_routes["History and utility endpoints<br/>[history.py]"]
  node_runner["Run orchestration<br/>[runner.py]"]
  node_registry["Active run registry<br/>[registry.py]"]
end

subgraph group_engine["Research engine"]
  node_engine["TradingAgents graph<br/>[trading_graph.py]"]
  node_analysts["Analyst team<br/>[analyst_team.py]"]
  node_quality["Quality gate<br/>[quality_gate.py]"]
  node_forecaster["Short-term forecast"]
  node_research["Bull-bear research"]
  node_trader["Trading plan<br/>[trader.py]"]
  node_risk["Risk debate"]
  node_portfolio["Portfolio decision"]
end

subgraph group_integrations["Data and models"]
  node_market_data["Market data sources<br/>[router.py]"]
  node_llm["Model clients<br/>[factory.py]"]
end

subgraph group_history["Reports and history"]
  node_history_service["History and persistence<br/>[history.py]"]
  node_sqlite[("SQLite history index<br/>[sqlite_history.py]")]
  node_reports["Saved analysis reports"]
end

node_user(("Research user"))
node_providers(("LLM providers"))
node_data_services(("Financial data services"))

node_user -->|"submits analysis"| node_web
node_web -->|"requests API"| node_api_client
node_api_client -->|"REST calls"| node_fastapi
node_web -->|"tracks run"| node_stream
node_stream -->|"receives progress"| node_fastapi
node_user -->|"runs research"| node_cli
node_cli -->|"invokes graph"| node_engine
node_fastapi -->|"dispatches routes"| node_analysis_route
node_analysis_route -->|"starts run"| node_runner
node_analysis_route -->|"tracks run"| node_registry
node_runner -->|"runs analysis"| node_engine
node_engine -->|"dispatches team"| node_analysts
node_analysts -->|"requests research data"| node_market_data
node_market_data -->|"fetches market data"| node_data_services
node_engine -->|"checks analyst evidence"| node_quality
node_engine -->|"runs forecast"| node_forecaster
node_engine -->|"runs debate"| node_research
node_engine -->|"creates plan"| node_trader
node_engine -->|"reviews risk"| node_risk
node_engine -->|"requests decision"| node_portfolio
node_analysts -->|"requests model output"| node_llm
node_llm -->|"calls model"| node_providers
node_portfolio -->|"requests decision output"| node_llm
node_runner -->|"saves run report"| node_reports
node_other_routes -->|"serves history"| node_history_service
node_history_service -->|"reads and writes index"| node_sqlite
node_history_service -->|"loads reports"| node_reports
node_fastapi -->|"dispatches routes"| node_other_routes

click node_web "https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/App.tsx"
click node_api_client "https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/api/client.ts"
click node_stream "https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/hooks/useAnalysisStream.ts"
click node_cli "https://github.com/spacerexxx/tradingagents-webui/blob/main/cli/main.py"
click node_fastapi "https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/main.py"
click node_analysis_route "https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/routes/analysis.py"
click node_other_routes "https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/routes/history.py"
click node_runner "https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/services/runner.py"
click node_registry "https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/services/registry.py"
click node_engine "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/graph/trading_graph.py"
click node_analysts "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/graph/analyst_team.py"
click node_quality "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/quality_gate.py"
click node_forecaster "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/forecasters/short_term_forecaster.py"
click node_research "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/managers/research_manager.py"
click node_trader "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/trader/trader.py"
click node_risk "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/risk_mgmt/aggressive_debator.py"
click node_portfolio "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/managers/portfolio_manager.py"
click node_market_data "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/dataflows/a_share_sources/router.py"
click node_llm "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/llm_clients/factory.py"
click node_history_service "https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/services/history.py"
click node_sqlite "https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/storage/sqlite_history.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_web,node_api_client,node_stream,node_cli,node_user toneBlue
class node_fastapi,node_analysis_route,node_other_routes,node_runner,node_registry toneAmber
class node_engine,node_analysts,node_quality,node_forecaster,node_research,node_trader,node_risk,node_portfolio toneMint
class node_market_data,node_llm toneRose
class node_history_service,node_sqlite,node_reports,node_providers,node_data_services toneIndigo
```

## Components

### User interfaces

- [React WebUI](https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [API client](https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/api/client.ts): `frontend/src/api/client.ts`
- [Analysis stream](https://github.com/spacerexxx/tradingagents-webui/blob/main/frontend/src/hooks/useAnalysisStream.ts): `frontend/src/hooks/useAnalysisStream.ts`
- [CLI](https://github.com/spacerexxx/tradingagents-webui/blob/main/cli/main.py): `cli/main.py`

### API services

- [FastAPI app](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/main.py): `backend/main.py`
- [Analysis endpoints](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/routes/analysis.py): `backend/routes/analysis.py`
- [History and utility endpoints](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/routes/history.py): `backend/routes/history.py`
- [Run orchestration](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/services/runner.py): `backend/services/runner.py`
- [Active run registry](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/services/registry.py): `backend/services/registry.py`

### Research engine

- [TradingAgents graph](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/graph/trading_graph.py): `tradingagents/graph/trading_graph.py`
- [Analyst team](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/graph/analyst_team.py): `tradingagents/graph/analyst_team.py`
- [Quality gate](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/quality_gate.py): `tradingagents/agents/quality_gate.py`
- [Short-term forecast](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/forecasters/short_term_forecaster.py): `tradingagents/agents/forecasters/short_term_forecaster.py`
- [Bull-bear research](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/managers/research_manager.py): `tradingagents/agents/managers/research_manager.py`
- [Trading plan](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/trader/trader.py): `tradingagents/agents/trader/trader.py`
- [Risk debate](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/risk_mgmt/aggressive_debator.py): `tradingagents/agents/risk_mgmt/aggressive_debator.py`
- [Portfolio decision](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/agents/managers/portfolio_manager.py): `tradingagents/agents/managers/portfolio_manager.py`

### Data and models

- [Market data sources](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/dataflows/a_share_sources/router.py): `tradingagents/dataflows/a_share_sources/router.py`
- [Model clients](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/llm_clients/factory.py): `tradingagents/llm_clients/factory.py`

### Reports and history

- [History and persistence](https://github.com/spacerexxx/tradingagents-webui/blob/main/backend/services/history.py): `backend/services/history.py`
- [SQLite history index](https://github.com/spacerexxx/tradingagents-webui/blob/main/tradingagents/storage/sqlite_history.py): `tradingagents/storage/sqlite_history.py`
- **Saved analysis reports**

### Other components

- **Research user**
- **LLM providers**
- **Financial data services**

## Connections

- Research user → React WebUI: submits analysis
- React WebUI → API client: requests API
- API client → FastAPI app: REST calls
- React WebUI → Analysis stream: tracks run
- Analysis stream → FastAPI app: receives progress
- Research user → CLI: runs research
- CLI → TradingAgents graph: invokes graph
- FastAPI app → Analysis endpoints: dispatches routes
- Analysis endpoints → Run orchestration: starts run
- Analysis endpoints → Active run registry: tracks run
- Run orchestration → TradingAgents graph: runs analysis
- TradingAgents graph → Analyst team: dispatches team
- Analyst team → Market data sources: requests research data
- Market data sources → Financial data services: fetches market data
- TradingAgents graph → Quality gate: checks analyst evidence
- TradingAgents graph → Short-term forecast: runs forecast
- TradingAgents graph → Bull-bear research: runs debate
- TradingAgents graph → Trading plan: creates plan
- TradingAgents graph → Risk debate: reviews risk
- TradingAgents graph → Portfolio decision: requests decision
- Analyst team → Model clients: requests model output
- Model clients → LLM providers: calls model
- Portfolio decision → Model clients: requests decision output
- Run orchestration → Saved analysis reports: saves run report
- History and utility endpoints → History and persistence: serves history
- History and persistence → SQLite history index: reads and writes index
- History and persistence → Saved analysis reports: loads reports
- FastAPI app → History and utility endpoints: dispatches routes
