# dsrsubbu/openalgo architecture

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

- Interactive diagram: https://gitdiagram.com/dsrsubbu/openalgo
- Repository: https://github.com/dsrsubbu/openalgo

## Overview

OpenAlgo is a self-hosted algorithmic trading platform spanning broker-connected APIs, hosted and visual strategies, AI-assisted trading, analytics, and simulated execution. A typical journey enters through an API, strategy surface, or user interface; market and symbol data inform analysis and order decisions; broker adapters provide live trading, while sandbox components support simulation. The graph combines README-documented capabilities with sampled implementation evidence. Several feature modules are represented at directory level because their source was not sampled; those links are dashed where implementation wiring is unverified.

Main entry points: [`services/market_data_service.py`](https://github.com/dsrsubbu/openalgo/blob/main/services/market_data_service.py) (Market data service), [`app.py`](https://github.com/dsrsubbu/openalgo/blob/main/app.py) (Flask application), [`blueprints/orders.py`](https://github.com/dsrsubbu/openalgo/blob/main/blueprints/orders.py) (Unified REST API), [`blueprints/agent.py`](https://github.com/dsrsubbu/openalgo/blob/main/blueprints/agent.py) (AI agent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Application entry"]
  node_app["Flask application<br/>[app.py]"]
  node_api["Unified REST API<br/>[orders.py]"]
end

subgraph group_strategy["Strategy surfaces"]
  node_python["Python strategy host<br/>[python_strategy.py]"]
  node_flow["Visual Flow"]
  node_agent["AI agent<br/>[agent.py]"]
  node_strategy_engine["Strategy module engine<br/>[engine.py]"]
end

subgraph group_market["Market and analytics"]
  node_market_data["Market data service"]
  node_symbols[("Symbol lookup<br/>[symbol.py]")]
  node_tokens[("Token cache")]
  node_options_tools["Options and portfolio tools"]
  node_analytics["Arbitrage scanner"]
end

subgraph group_execution["Execution"]
  node_analyzer["Order analyzer<br/>[analyzer.py]"]
  node_broker_adapters["Broker plugins"]
  node_sandbox_orders["Sandbox order manager<br/>[order_manager.py]"]
  node_sandbox_engine["Sandbox execution"]
  node_sandbox_funds["Sandbox funds<br/>[fund_manager.py]"]
end

subgraph group_platform["Platform services"]
  node_sandbox_store[("Sandbox records<br/>[sandbox_db.py]")]
  node_auth[("Broker sessions<br/>[auth_db.py]")]
  node_websocket["WebSocket proxy<br/>[server.py]"]
  node_alerts["Alerts and webhooks<br/>[router.py]"]
  node_mcp["MCP integration<br/>[client.py]"]
  node_event_bus["Event bus<br/>[event_bus.py]"]
end

node_trader(("Trader or client"))

node_trader -->|"uses"| node_app
node_app -->|"registers"| node_api
node_app -->|"registers"| node_python
node_app -->|"registers"| node_agent
node_trader -->|"builds strategies"| node_flow
node_trader -->|"analyzes markets"| node_options_tools
node_api -->|"may analyze orders"| node_analyzer
node_python -->|"may analyze orders"| node_analyzer
node_flow -->|"may analyze orders"| node_analyzer
node_api -.->|"dispatches trades"| node_broker_adapters
node_api -.->|"requests data"| node_market_data
node_agent -->|"reads market data"| node_market_data
node_agent -->|"approved orders"| node_broker_adapters
node_strategy_engine -->|"dispatches orders"| node_broker_adapters
node_market_data -->|"serves streaming"| node_websocket
node_options_tools -.->|"streams live data"| node_market_data
node_analytics -->|"reads contracts"| node_symbols
node_symbols -->|"uses token lookup"| node_tokens
node_sandbox_orders -->|"checks margin"| node_sandbox_funds
node_sandbox_orders -->|"writes orders"| node_sandbox_store
node_sandbox_engine -.->|"processes pending orders"| node_sandbox_orders
node_sandbox_engine -.->|"reads pending orders"| node_sandbox_store
node_sandbox_engine -.->|"fetches quotes"| node_market_data
node_broker_adapters -.->|"uses sessions"| node_auth
node_alerts -.->|"sends notifications"| node_trader
node_agent -.->|"offers MCP access"| node_mcp
node_sandbox_orders -.->|"publishes updates"| node_event_bus

click node_app "https://github.com/dsrsubbu/openalgo/blob/main/app.py"
click node_api "https://github.com/dsrsubbu/openalgo/blob/main/blueprints/orders.py"
click node_python "https://github.com/dsrsubbu/openalgo/blob/main/blueprints/python_strategy.py"
click node_flow "https://github.com/dsrsubbu/openalgo/blob/main/services/flow_executor_service.py"
click node_agent "https://github.com/dsrsubbu/openalgo/blob/main/blueprints/agent.py"
click node_strategy_engine "https://github.com/dsrsubbu/openalgo/blob/main/services/strategy_module/engine.py"
click node_analyzer "https://github.com/dsrsubbu/openalgo/blob/main/blueprints/analyzer.py"
click node_broker_adapters "https://github.com/dsrsubbu/openalgo/tree/main/broker"
click node_sandbox_orders "https://github.com/dsrsubbu/openalgo/blob/main/sandbox/order_manager.py"
click node_sandbox_engine "https://github.com/dsrsubbu/openalgo/blob/main/sandbox/execution_engine.py"
click node_sandbox_funds "https://github.com/dsrsubbu/openalgo/blob/main/sandbox/fund_manager.py"
click node_sandbox_store "https://github.com/dsrsubbu/openalgo/blob/main/database/sandbox_db.py"
click node_market_data "https://github.com/dsrsubbu/openalgo/blob/main/services/market_data_service.py"
click node_symbols "https://github.com/dsrsubbu/openalgo/blob/main/database/symbol.py"
click node_tokens "https://github.com/dsrsubbu/openalgo/blob/main/database/token_db_enhanced.py"
click node_options_tools "https://github.com/dsrsubbu/openalgo/tree/main/blueprints"
click node_analytics "https://github.com/dsrsubbu/openalgo/blob/main/services/arbitrage_service.py"
click node_auth "https://github.com/dsrsubbu/openalgo/blob/main/database/auth_db.py"
click node_websocket "https://github.com/dsrsubbu/openalgo/blob/main/websocket_proxy/server.py"
click node_alerts "https://github.com/dsrsubbu/openalgo/blob/main/services/alerts/router.py"
click node_mcp "https://github.com/dsrsubbu/openalgo/blob/main/services/agent/mcp/client.py"
click node_event_bus "https://github.com/dsrsubbu/openalgo/blob/main/utils/event_bus.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_app,node_api,node_trader toneBlue
class node_python,node_flow,node_agent,node_strategy_engine toneAmber
class node_market_data,node_symbols,node_tokens,node_options_tools,node_analytics toneMint
class node_analyzer,node_broker_adapters,node_sandbox_orders,node_sandbox_engine,node_sandbox_funds toneRose
class node_sandbox_store,node_auth,node_websocket,node_alerts,node_mcp,node_event_bus toneIndigo
```

## Components

### Application entry

- [Flask application](https://github.com/dsrsubbu/openalgo/blob/main/app.py): `app.py`
- [Unified REST API](https://github.com/dsrsubbu/openalgo/blob/main/blueprints/orders.py): `blueprints/orders.py`

### Strategy surfaces

- [Python strategy host](https://github.com/dsrsubbu/openalgo/blob/main/blueprints/python_strategy.py): `blueprints/python_strategy.py`
- [Visual Flow](https://github.com/dsrsubbu/openalgo/blob/main/services/flow_executor_service.py): `services/flow_executor_service.py`
- [AI agent](https://github.com/dsrsubbu/openalgo/blob/main/blueprints/agent.py): `blueprints/agent.py`
- [Strategy module engine](https://github.com/dsrsubbu/openalgo/blob/main/services/strategy_module/engine.py): `services/strategy_module/engine.py`

### Market and analytics

- [Market data service](https://github.com/dsrsubbu/openalgo/blob/main/services/market_data_service.py): `services/market_data_service.py`
- [Symbol lookup](https://github.com/dsrsubbu/openalgo/blob/main/database/symbol.py): `database/symbol.py`
- [Token cache](https://github.com/dsrsubbu/openalgo/blob/main/database/token_db_enhanced.py): `database/token_db_enhanced.py`
- [Options and portfolio tools](https://github.com/dsrsubbu/openalgo/tree/main/blueprints): `blueprints`
- [Arbitrage scanner](https://github.com/dsrsubbu/openalgo/blob/main/services/arbitrage_service.py): `services/arbitrage_service.py`

### Execution

- [Order analyzer](https://github.com/dsrsubbu/openalgo/blob/main/blueprints/analyzer.py): `blueprints/analyzer.py`
- [Broker plugins](https://github.com/dsrsubbu/openalgo/tree/main/broker): `broker`
- [Sandbox order manager](https://github.com/dsrsubbu/openalgo/blob/main/sandbox/order_manager.py): `sandbox/order_manager.py`
- [Sandbox execution](https://github.com/dsrsubbu/openalgo/blob/main/sandbox/execution_engine.py): `sandbox/execution_engine.py`
- [Sandbox funds](https://github.com/dsrsubbu/openalgo/blob/main/sandbox/fund_manager.py): `sandbox/fund_manager.py`

### Platform services

- [Sandbox records](https://github.com/dsrsubbu/openalgo/blob/main/database/sandbox_db.py): `database/sandbox_db.py`
- [Broker sessions](https://github.com/dsrsubbu/openalgo/blob/main/database/auth_db.py): `database/auth_db.py`
- [WebSocket proxy](https://github.com/dsrsubbu/openalgo/blob/main/websocket_proxy/server.py): `websocket_proxy/server.py`
- [Alerts and webhooks](https://github.com/dsrsubbu/openalgo/blob/main/services/alerts/router.py): `services/alerts/router.py`
- [MCP integration](https://github.com/dsrsubbu/openalgo/blob/main/services/agent/mcp/client.py): `services/agent/mcp/client.py`
- [Event bus](https://github.com/dsrsubbu/openalgo/blob/main/utils/event_bus.py): `utils/event_bus.py`

### Other components

- **Trader or client**

## Connections

- Trader or client → Flask application: uses (evidence: `README.md`)
- Flask application → Unified REST API: registers (evidence: `app.py`)
- Flask application → Python strategy host: registers (evidence: `app.py`)
- Flask application → AI agent: registers (evidence: `app.py`)
- Trader or client → Visual Flow: builds strategies (evidence: `README.md`)
- Trader or client → Options and portfolio tools: analyzes markets (evidence: `README.md`)
- Unified REST API → Order analyzer: may analyze orders (evidence: `README.md`)
- Python strategy host → Order analyzer: may analyze orders (evidence: `README.md`)
- Visual Flow → Order analyzer: may analyze orders (evidence: `README.md`)
- Unified REST API → Broker plugins: dispatches trades
- Unified REST API → Market data service: requests data
- AI agent → Market data service: reads market data (evidence: `README.md`)
- AI agent → Broker plugins: approved orders (evidence: `README.md`)
- Strategy module engine → Broker plugins: dispatches orders (evidence: `services/strategy_module/engine.py`)
- Market data service → WebSocket proxy: serves streaming (evidence: `services/market_data_service.py`)
- Options and portfolio tools → Market data service: streams live data
- Arbitrage scanner → Symbol lookup: reads contracts (evidence: `services/arbitrage_service.py`)
- Symbol lookup → Token cache: uses token lookup (evidence: `database/symbol.py`)
- Sandbox order manager → Sandbox funds: checks margin (evidence: `sandbox/order_manager.py`)
- Sandbox order manager → Sandbox records: writes orders (evidence: `sandbox/order_manager.py`)
- Sandbox execution → Sandbox order manager: processes pending orders (evidence: `sandbox/order_manager.py`)
- Sandbox execution → Sandbox records: reads pending orders (evidence: `sandbox/execution_engine.py`)
- Sandbox execution → Market data service: fetches quotes
- Broker plugins → Broker sessions: uses sessions (evidence: `broker/upstox/streaming/upstox_client.py`)
- Alerts and webhooks → Trader or client: sends notifications
- AI agent → MCP integration: offers MCP access
- Sandbox order manager → Event bus: publishes updates (evidence: `sandbox/order_manager.py`)
