# suriyagb/hermes-trading-agent- architecture

> Architecture diagram of the GitHub repository suriyagb/hermes-trading-agent-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/suriyagb/hermes-trading-agent-
- Repository: https://github.com/suriyagb/hermes-trading-agent-

## Overview

Hermes is an AAPL options-wheel trading agent with separate trading, Telegram analyst, and web-dashboard services. The primary flow is a scheduled market pulse: gather market and option data, obtain a constrained AI decision, apply execution safeguards, then persist portfolio and decision history and send an alert. The dashboard and assistant read that stored state. The README documents these service boundaries; sampled source confirms database writes and dashboard API configuration, but several internal call paths were not shown, so those links rely on the README.

Main entry points: [`core/executor.py`](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/executor.py) (Trade executor), [`core/assistant.py`](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/assistant.py) (RAG analyst), [`core/get_ibkr_analysis.py`](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/get_ibkr_analysis.py) (Market analysis), [`core/call_brain_direct.py`](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/call_brain_direct.py) (Decision brain)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_trading["Trading engine"]
  node_marketdata["Market analysis"]
  node_brain["Decision brain"]
  node_executor["Trade executor<br/>[executor.py]"]
  node_sim["Paper execution<br/>[sim_executor.py]"]
  node_ibkr["IBKR execution<br/>[executor.py]"]
end

subgraph group_assistant["Telegram analyst"]
  node_listener["Message listener"]
  node_analyst["RAG analyst<br/>[assistant.py]"]
end

subgraph group_dashboard["Web dashboard"]
  node_dashboard["Dashboard pages"]
  node_sidebar["Navigation settings<br/>[Sidebar.js]"]
  node_apiutil["API configuration<br/>[api.js]"]
  node_api["Read-only API<br/>[api.py]"]
end

subgraph group_state["Portfolio memory"]
  node_database[("Decision database<br/>[database.py]")]
  node_portfolio["Portfolio state"]
end

node_pulse(("Scheduled pulse"))
node_telegram_actor(("Telegram user"))
node_telegram{{"Telegram service"}}
node_browser(("Dashboard user"))
node_market_service{{"Market data sources"}}
node_llm{{"GPT-4o"}}

node_pulse -->|"starts pulse"| node_marketdata
node_marketdata -->|"fetches quotes"| node_market_service
node_marketdata -->|"sends analysis"| node_brain
node_brain -->|"requests decision"| node_llm
node_brain -->|"returns token"| node_executor
node_executor -->|"records trades"| node_database
node_executor -->|"updates state"| node_portfolio
node_executor -.->|"selects simulation"| node_sim
node_executor -.->|"selects live trades"| node_ibkr
node_executor -->|"sends alert"| node_telegram
node_telegram_actor -->|"sends query"| node_listener
node_listener -->|"forwards query"| node_analyst
node_analyst -->|"reads history"| node_database
node_analyst -->|"reads state"| node_portfolio
node_analyst -->|"sends reply"| node_telegram
node_browser -->|"views pages"| node_dashboard
node_dashboard -->|"resolves API"| node_apiutil
node_sidebar -->|"resolves endpoints"| node_apiutil
node_dashboard -->|"requests dashboard data"| node_api
node_api -->|"reads history"| node_database
node_api -->|"reads files"| node_portfolio

click node_marketdata "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/get_ibkr_analysis.py"
click node_brain "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/call_brain_direct.py"
click node_executor "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/executor.py"
click node_sim "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/sim_executor.py"
click node_ibkr "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/executor.py"
click node_listener "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/telegram_listener.py"
click node_analyst "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/assistant.py"
click node_dashboard "https://github.com/suriyagb/hermes-trading-agent-/tree/main/frontend/src/app"
click node_sidebar "https://github.com/suriyagb/hermes-trading-agent-/blob/main/frontend/src/components/Sidebar.js"
click node_apiutil "https://github.com/suriyagb/hermes-trading-agent-/blob/main/frontend/src/utils/api.js"
click node_api "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/api.py"
click node_database "https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/database.py"
click node_portfolio "https://github.com/suriyagb/hermes-trading-agent-/tree/main/data"

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_marketdata,node_brain,node_executor,node_sim,node_ibkr,node_telegram_actor,node_browser toneBlue
class node_listener,node_analyst toneAmber
class node_dashboard,node_sidebar,node_apiutil,node_api toneMint
class node_database,node_portfolio toneRose
class node_pulse,node_telegram,node_market_service,node_llm toneIndigo
```

## Components

### Trading engine

- [Market analysis](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/get_ibkr_analysis.py): `core/get_ibkr_analysis.py`
- [Decision brain](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/call_brain_direct.py): `core/call_brain_direct.py`
- [Trade executor](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/executor.py): `core/executor.py`
- [Paper execution](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/sim_executor.py): `core/sim_executor.py`
- [IBKR execution](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/executor.py): `core/executor.py`

### Telegram analyst

- [Message listener](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/telegram_listener.py): `core/telegram_listener.py`
- [RAG analyst](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/assistant.py): `core/assistant.py`

### Web dashboard

- [Dashboard pages](https://github.com/suriyagb/hermes-trading-agent-/tree/main/frontend/src/app): `frontend/src/app`
- [Navigation settings](https://github.com/suriyagb/hermes-trading-agent-/blob/main/frontend/src/components/Sidebar.js): `frontend/src/components/Sidebar.js`
- [API configuration](https://github.com/suriyagb/hermes-trading-agent-/blob/main/frontend/src/utils/api.js): `frontend/src/utils/api.js`
- [Read-only API](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/api.py): `core/api.py`

### Portfolio memory

- [Decision database](https://github.com/suriyagb/hermes-trading-agent-/blob/main/core/database.py): `core/database.py`
- [Portfolio state](https://github.com/suriyagb/hermes-trading-agent-/tree/main/data): `data`

### Other components

- **Scheduled pulse**
- **Telegram user**
- **Telegram service**
- **Dashboard user**
- **Market data sources**
- **GPT-4o**

## Connections

- Scheduled pulse → Market analysis: starts pulse (evidence: `README.md`)
- Market analysis → Market data sources: fetches quotes (evidence: `README.md`)
- Market analysis → Decision brain: sends analysis (evidence: `README.md`)
- Decision brain → GPT-4o: requests decision (evidence: `README.md`)
- Decision brain → Trade executor: returns token (evidence: `README.md`)
- Trade executor → Decision database: records trades (evidence: `core/executor.py`)
- Trade executor → Portfolio state: updates state (evidence: `README.md`)
- Trade executor → Paper execution: selects simulation
- Trade executor → IBKR execution: selects live trades (evidence: `core/executor.py`)
- Trade executor → Telegram service: sends alert (evidence: `README.md`)
- Telegram user → Message listener: sends query (evidence: `README.md`)
- Message listener → RAG analyst: forwards query (evidence: `README.md`)
- RAG analyst → Decision database: reads history (evidence: `README.md`)
- RAG analyst → Portfolio state: reads state (evidence: `README.md`)
- RAG analyst → Telegram service: sends reply (evidence: `README.md`)
- Dashboard user → Dashboard pages: views pages (evidence: `README.md`)
- Dashboard pages → API configuration: resolves API (evidence: `frontend/src/app/page.js`)
- Navigation settings → API configuration: resolves endpoints (evidence: `frontend/src/components/Sidebar.js`)
- Dashboard pages → Read-only API: requests dashboard data (evidence: `README.md`)
- Read-only API → Decision database: reads history (evidence: `README.md`)
- Read-only API → Portfolio state: reads files (evidence: `README.md`)
