# mingyuj666/stockagent architecture

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

- Interactive diagram: https://gitdiagram.com/mingyuj666/stockagent
- Repository: https://github.com/mingyuj666/stockagent

## Overview

StockAgent is a simulated stock-trading environment in which LLM-driven trader agents respond to market information, place orders, and interact through a daily forum. The principal workflow is launched by `main.py`: initialize the simulation, apply scheduled events and loan handling, collect agent decisions, match orders, update prices, and record results. Agent prompts and response validation support those decisions; stock state and agent portfolios represent market state. The README also describes initial, trading, post-trading, and specific-event phases. The graph follows the sampled code and README; some phase details and the implementation of `Secretary` were not sampled.

Main entry points: [`main.py`](https://github.com/mingyuj666/stockagent/blob/main/main.py) (Simulation Runner), [`agent.py`](https://github.com/mingyuj666/stockagent/blob/main/agent.py) (Trader Agent), [`stock.py`](https://github.com/mingyuj666/stockagent/blob/main/stock.py) (Stock State), [`util.py`](https://github.com/mingyuj666/stockagent/blob/main/util.py) (Simulation Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_simulation["Simulation Control"]
  node_main["Simulation Runner<br/>[main.py]"]
  node_initialization["Initial Phase<br/>[main.py]"]
  node_trading_phase["Trading Phase<br/>[main.py]"]
  node_post_phase["Post-Trading Phase<br/>[main.py]"]
  node_special_events["Special Events<br/>[main.py]"]
end

subgraph group_trading["Trading Domain"]
  node_order_matching["Order Matching<br/>[main.py]"]
  node_market_state["Stock State<br/>[stock.py]"]
end

subgraph group_agents["Agent Decisions"]
  node_trader["Trader Agent<br/>[agent.py]"]
  node_prompt_templates["Decision Prompts<br/>[agent_prompt.py]"]
  node_decision_validation["Decision Validation<br/>[secretary.py]"]
end

subgraph group_support["Configuration and Records"]
  node_configuration["Simulation Configuration<br/>[util.py]"]
  node_records["Simulation Records<br/>[record.py]"]
  node_logging["Logging<br/>[custom_logger.py]"]
end

node_user(("Simulation User"))
node_llm_provider["LLM Provider"]

node_user -->|"starts run"| node_main
node_main -->|"initializes"| node_initialization
node_main -->|"runs sessions"| node_trading_phase
node_main -.->|"runs post-day"| node_post_phase
node_main -->|"applies events"| node_special_events
node_main -->|"dispatches orders"| node_order_matching
node_order_matching -->|"updates holdings"| node_trader
node_order_matching -->|"adds deals"| node_market_state
node_trading_phase -->|"requests plans"| node_trader
node_trading_phase -->|"updates prices"| node_market_state
node_trading_phase -->|"writes records"| node_records
node_post_phase -.->|"requests posts"| node_trader
node_trader -->|"formats decisions"| node_prompt_templates
node_trader -->|"checks responses"| node_decision_validation
node_trader -->|"sends prompts"| node_llm_provider
node_initialization -->|"loads settings"| node_configuration
node_market_state -->|"reads reports"| node_configuration
node_trading_phase -->|"logs activity"| node_logging

click node_main "https://github.com/mingyuj666/stockagent/blob/main/main.py"
click node_initialization "https://github.com/mingyuj666/stockagent/blob/main/main.py"
click node_trading_phase "https://github.com/mingyuj666/stockagent/blob/main/main.py"
click node_post_phase "https://github.com/mingyuj666/stockagent/blob/main/main.py"
click node_special_events "https://github.com/mingyuj666/stockagent/blob/main/main.py"
click node_order_matching "https://github.com/mingyuj666/stockagent/blob/main/main.py"
click node_market_state "https://github.com/mingyuj666/stockagent/blob/main/stock.py"
click node_trader "https://github.com/mingyuj666/stockagent/blob/main/agent.py"
click node_prompt_templates "https://github.com/mingyuj666/stockagent/blob/main/prompt/agent_prompt.py"
click node_decision_validation "https://github.com/mingyuj666/stockagent/blob/main/secretary.py"
click node_configuration "https://github.com/mingyuj666/stockagent/blob/main/util.py"
click node_records "https://github.com/mingyuj666/stockagent/blob/main/record.py"
click node_logging "https://github.com/mingyuj666/stockagent/blob/main/log/custom_logger.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_main,node_initialization,node_trading_phase,node_post_phase,node_special_events,node_user toneBlue
class node_order_matching,node_market_state toneAmber
class node_trader,node_prompt_templates,node_decision_validation toneMint
class node_configuration,node_records,node_logging toneRose
class node_llm_provider toneIndigo
```

## Components

### Simulation Control

- [Simulation Runner](https://github.com/mingyuj666/stockagent/blob/main/main.py): `main.py`
- [Initial Phase](https://github.com/mingyuj666/stockagent/blob/main/main.py): `main.py`
- [Trading Phase](https://github.com/mingyuj666/stockagent/blob/main/main.py): `main.py`
- [Post-Trading Phase](https://github.com/mingyuj666/stockagent/blob/main/main.py): `main.py`
- [Special Events](https://github.com/mingyuj666/stockagent/blob/main/main.py): `main.py`

### Trading Domain

- [Order Matching](https://github.com/mingyuj666/stockagent/blob/main/main.py): `main.py`
- [Stock State](https://github.com/mingyuj666/stockagent/blob/main/stock.py): `stock.py`

### Agent Decisions

- [Trader Agent](https://github.com/mingyuj666/stockagent/blob/main/agent.py): `agent.py`
- [Decision Prompts](https://github.com/mingyuj666/stockagent/blob/main/prompt/agent_prompt.py): `prompt/agent_prompt.py`
- [Decision Validation](https://github.com/mingyuj666/stockagent/blob/main/secretary.py): `secretary.py`

### Configuration and Records

- [Simulation Configuration](https://github.com/mingyuj666/stockagent/blob/main/util.py): `util.py`
- [Simulation Records](https://github.com/mingyuj666/stockagent/blob/main/record.py): `record.py`
- [Logging](https://github.com/mingyuj666/stockagent/blob/main/log/custom_logger.py): `log/custom_logger.py`

### Other components

- **Simulation User**
- **LLM Provider**

## Connections

- Simulation User → Simulation Runner: starts run (evidence: `README.md`)
- Simulation Runner → Initial Phase: initializes (evidence: `main.py`)
- Simulation Runner → Trading Phase: runs sessions (evidence: `main.py`)
- Simulation Runner → Post-Trading Phase: runs post-day (evidence: `README.md`)
- Simulation Runner → Special Events: applies events (evidence: `main.py`)
- Simulation Runner → Order Matching: dispatches orders (evidence: `main.py`)
- Order Matching → Trader Agent: updates holdings (evidence: `main.py`)
- Order Matching → Stock State: adds deals (evidence: `main.py`)
- Trading Phase → Trader Agent: requests plans (evidence: `main.py`)
- Trading Phase → Stock State: updates prices (evidence: `main.py`)
- Trading Phase → Simulation Records: writes records (evidence: `main.py`)
- Post-Trading Phase → Trader Agent: requests posts (evidence: `README.md`)
- Trader Agent → Decision Prompts: formats decisions (evidence: `agent.py`)
- Trader Agent → Decision Validation: checks responses (evidence: `agent.py`)
- Trader Agent → LLM Provider: sends prompts (evidence: `agent.py`)
- Initial Phase → Simulation Configuration: loads settings (evidence: `main.py`)
- Stock State → Simulation Configuration: reads reports (evidence: `stock.py`)
- Trading Phase → Logging: logs activity (evidence: `main.py`)
