# simonlin1212/tradingagents-astock architecture

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

## Overview

TradingAgents-Astock is an A-share investment-research framework that turns a stock and date into analyst reports and a final trading decision. The principal workflow runs seven A-share-aware analysts, a bull/bear research debate and plan, an A-share-constrained trader proposal, then a three-way risk debate and portfolio decision. Users can initiate analysis through the CLI or Web UI; the Web UI also supports progress and historical-report viewing. README documents the stages and data-source capabilities; unsampled subsystem wiring is shown only where documented.

Main entry points: [`tradingagents/graph/setup.py`](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/graph/setup.py) (Graph Setup), [`web/app.py`](https://github.com/simonlin1212/tradingagents-astock/blob/main/web/app.py) (Web UI), [`tradingagents/graph/trading_graph.py`](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/graph/trading_graph.py) (Trading Graph), [`tradingagents/agents/managers/research_manager.py`](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/managers/research_manager.py) (Research Manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["User Interfaces"]
  node_cli["CLI<br/>[main.py]"]
  node_web["Web UI<br/>[app.py]"]
  node_runner["Web Runner<br/>[runner.py]"]
  node_report_viewer["Report Viewer<br/>[report_viewer.py]"]
  node_history["Analysis History<br/>[history.py]"]
end

subgraph group_workflow["Analysis Workflow"]
  node_engine["Trading Graph<br/>[trading_graph.py]"]
  node_graph_setup["Graph Setup<br/>[setup.py]"]
end

subgraph group_research["Research and Debate"]
  node_analysts["Seven Analysts"]
  node_research_tools["Research Tools"]
  node_bull["Bull Researcher<br/>[bull_researcher.py]"]
  node_bear["Bear Researcher<br/>[bear_researcher.py]"]
  node_research_manager["Research Manager"]
end

subgraph group_decision["Trading Decision"]
  node_trader["Trader<br/>[trader.py]"]
  node_risk_debaters["Risk Debaters"]
  node_portfolio_manager["Portfolio Manager"]
end

subgraph group_services["Models and Data"]
  node_dataflows["A-Share Dataflows"]
  node_market_sources(("Market Data Sources"))
  node_llm_factory["LLM Factory<br/>[factory.py]"]
  node_llm_providers["LLM Providers"]
  node_model_services(("Model Services"))
end

node_user(("Research User"))

node_user -->|"starts analysis"| node_cli
node_user -->|"starts or views"| node_web
node_cli -->|"runs analysis"| node_engine
node_web -->|"starts analysis"| node_runner
node_runner -->|"runs analysis"| node_engine
node_engine -->|"builds workflow"| node_graph_setup
node_graph_setup -->|"dispatches"| node_analysts
node_graph_setup -->|"dispatches"| node_bull
node_graph_setup -->|"dispatches"| node_bear
node_graph_setup -->|"dispatches"| node_research_manager
node_graph_setup -->|"dispatches"| node_trader
node_graph_setup -->|"dispatches"| node_risk_debaters
node_graph_setup -->|"dispatches"| node_portfolio_manager
node_analysts -->|"uses tools"| node_research_tools
node_research_tools -->|"requests data"| node_dataflows
node_dataflows -->|"fetches from"| node_market_sources
node_bull -->|"debate informs plan"| node_research_manager
node_bear -->|"debate informs plan"| node_research_manager
node_research_manager -->|"provides plan"| node_trader
node_trader -->|"provides proposal"| node_risk_debaters
node_risk_debaters -->|"debate informs decision"| node_portfolio_manager
node_engine -->|"configures models"| node_llm_factory
node_llm_factory -->|"creates clients"| node_llm_providers
node_llm_providers -->|"calls models"| node_model_services
node_web -->|"renders report"| node_report_viewer
node_web -->|"loads history"| node_history
node_history -->|"supplies report"| node_report_viewer

click node_cli "https://github.com/simonlin1212/tradingagents-astock/blob/main/cli/main.py"
click node_web "https://github.com/simonlin1212/tradingagents-astock/blob/main/web/app.py"
click node_runner "https://github.com/simonlin1212/tradingagents-astock/blob/main/web/runner.py"
click node_engine "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/graph/trading_graph.py"
click node_graph_setup "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/graph/setup.py"
click node_analysts "https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/agents/analysts"
click node_research_tools "https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/agents/utils"
click node_dataflows "https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/dataflows"
click node_bull "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/researchers/bull_researcher.py"
click node_bear "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/researchers/bear_researcher.py"
click node_research_manager "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/managers/research_manager.py"
click node_trader "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/trader/trader.py"
click node_risk_debaters "https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/agents/risk_mgmt"
click node_portfolio_manager "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/managers/portfolio_manager.py"
click node_llm_factory "https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/llm_clients/factory.py"
click node_llm_providers "https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/llm_clients"
click node_report_viewer "https://github.com/simonlin1212/tradingagents-astock/blob/main/web/components/report_viewer.py"
click node_history "https://github.com/simonlin1212/tradingagents-astock/blob/main/web/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_cli,node_web,node_runner,node_report_viewer,node_history,node_user toneBlue
class node_engine,node_graph_setup toneAmber
class node_analysts,node_research_tools,node_bull,node_bear,node_research_manager toneMint
class node_trader,node_risk_debaters,node_portfolio_manager toneRose
class node_dataflows,node_market_sources,node_llm_factory,node_llm_providers,node_model_services toneIndigo
```

## Components

### User Interfaces

- [CLI](https://github.com/simonlin1212/tradingagents-astock/blob/main/cli/main.py): `cli/main.py`
- [Web UI](https://github.com/simonlin1212/tradingagents-astock/blob/main/web/app.py): `web/app.py`
- [Web Runner](https://github.com/simonlin1212/tradingagents-astock/blob/main/web/runner.py): `web/runner.py`
- [Report Viewer](https://github.com/simonlin1212/tradingagents-astock/blob/main/web/components/report_viewer.py): `web/components/report_viewer.py`
- [Analysis History](https://github.com/simonlin1212/tradingagents-astock/blob/main/web/history.py): `web/history.py`

### Analysis Workflow

- [Trading Graph](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/graph/trading_graph.py): `tradingagents/graph/trading_graph.py`
- [Graph Setup](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/graph/setup.py): `tradingagents/graph/setup.py`

### Research and Debate

- [Seven Analysts](https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/agents/analysts): `tradingagents/agents/analysts`
- [Research Tools](https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/agents/utils): `tradingagents/agents/utils`
- [Bull Researcher](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/researchers/bull_researcher.py): `tradingagents/agents/researchers/bull_researcher.py`
- [Bear Researcher](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/researchers/bear_researcher.py): `tradingagents/agents/researchers/bear_researcher.py`
- [Research Manager](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/managers/research_manager.py): `tradingagents/agents/managers/research_manager.py`

### Trading Decision

- [Trader](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/trader/trader.py): `tradingagents/agents/trader/trader.py`
- [Risk Debaters](https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/agents/risk_mgmt): `tradingagents/agents/risk_mgmt`
- [Portfolio Manager](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/agents/managers/portfolio_manager.py): `tradingagents/agents/managers/portfolio_manager.py`

### Models and Data

- [A-Share Dataflows](https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/dataflows): `tradingagents/dataflows`
- **Market Data Sources**
- [LLM Factory](https://github.com/simonlin1212/tradingagents-astock/blob/main/tradingagents/llm_clients/factory.py): `tradingagents/llm_clients/factory.py`
- [LLM Providers](https://github.com/simonlin1212/tradingagents-astock/tree/main/tradingagents/llm_clients): `tradingagents/llm_clients`
- **Model Services**

### Other components

- **Research User**

## Connections

- Research User → CLI: starts analysis
- Research User → Web UI: starts or views
- CLI → Trading Graph: runs analysis
- Web UI → Web Runner: starts analysis
- Web Runner → Trading Graph: runs analysis
- Trading Graph → Graph Setup: builds workflow
- Graph Setup → Seven Analysts: dispatches
- Graph Setup → Bull Researcher: dispatches
- Graph Setup → Bear Researcher: dispatches
- Graph Setup → Research Manager: dispatches
- Graph Setup → Trader: dispatches
- Graph Setup → Risk Debaters: dispatches
- Graph Setup → Portfolio Manager: dispatches
- Seven Analysts → Research Tools: uses tools
- Research Tools → A-Share Dataflows: requests data
- A-Share Dataflows → Market Data Sources: fetches from
- Bull Researcher → Research Manager: debate informs plan
- Bear Researcher → Research Manager: debate informs plan
- Research Manager → Trader: provides plan
- Trader → Risk Debaters: provides proposal
- Risk Debaters → Portfolio Manager: debate informs decision
- Trading Graph → LLM Factory: configures models
- LLM Factory → LLM Providers: creates clients
- LLM Providers → Model Services: calls models
- Web UI → Report Viewer: renders report
- Web UI → Analysis History: loads history
- Analysis History → Report Viewer: supplies report
