# marketcalls/openbull architecture

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

- Interactive diagram: https://gitdiagram.com/marketcalls/openbull
- Repository: https://github.com/marketcalls/openbull

## Overview

OpenBull is a self-hosted, multi-user options-trading platform for Indian markets. Users authenticate, configure a broker, then use the web UI or typed API for market data, analytics, and orders; broker plugins normalize account/order operations and stream ticks through a shared WebSocket proxy. Users can switch the same trading paths between live and simulated execution. Separate product branches cover strategy design and automated strategy runs, options analytics, sandbox lifecycle/P&L, and interactive API testing. Edges cite README-documented relationships or shown source references; several subsystem internals were not sampled, so their links are documentation-based.

Main entry points: [`backend/main.py`](https://github.com/marketcalls/openbull/blob/main/backend/main.py) (Web and external API), [`backend/services/market_data_cache.py`](https://github.com/marketcalls/openbull/blob/main/backend/services/market_data_cache.py) (Market data cache), [`backend/sandbox/execution_engine.py`](https://github.com/marketcalls/openbull/blob/main/backend/sandbox/execution_engine.py) (Sandbox execution), [`frontend/src/App.tsx`](https://github.com/marketcalls/openbull/blob/main/frontend/src/App.tsx) (Trading UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client applications"]
  node_web["Trading UI<br/>[App.tsx]"]
  node_playground["API Playground<br/>[Playground.tsx]"]
end

subgraph group_backend["API and trading"]
  node_api["Web and external API<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_services["Trading services"]
  node_database[("Application database<br/>[database.py]")]
  node_redis[("Redis cache<br/>[redis_client.py]")]
end

subgraph group_brokers["Broker integrations"]
  node_broker_plugins["Broker APIs"]
  node_stream_adapters["Streaming adapters"]
  node_ws_proxy["WebSocket proxy<br/>[server.py]"]
  node_broker_services["Broker services"]
end

subgraph group_strategies["Strategies"]
  node_builder["Strategy builder"]
  node_strategy_engine["Strategy engine<br/>[engine.py]"]
  node_strategy_webhook["Strategy webhooks<br/>[webhook_handler.py]"]
end

subgraph group_market["Market data and analytics"]
  node_analytics["Options analytics"]
  node_market_cache[("Market data cache")]
end

subgraph group_sandbox["Sandbox trading"]
  node_sandbox_service["Sandbox service<br/>[sandbox_service.py]"]
  node_sandbox_execution["Sandbox execution"]
  node_sandbox_books["Sandbox books"]
end

node_user(("Trader"))
node_broker_network(("Broker systems"))
node_postgres[("PostgreSQL")]

node_user -->|"uses"| node_web
node_user -->|"tests endpoints"| node_playground
node_web -.->|"calls web API"| node_api
node_playground -->|"tests API"| node_api
node_api -->|"routes auth"| node_auth
node_api -->|"dispatches requests"| node_services
node_services -->|"dispatches broker calls"| node_broker_plugins
node_broker_plugins -->|"calls"| node_broker_network
node_broker_network -->|"streams ticks"| node_stream_adapters
node_stream_adapters -->|"publishes ticks"| node_ws_proxy
node_ws_proxy -->|"streams market data"| node_web
node_broker_services -.->|"updates cache"| node_market_cache
node_api -->|"routes strategy tools"| node_builder
node_builder -.->|"starts strategy runs"| node_strategy_engine
node_strategy_webhook -->|"dispatches actions"| node_strategy_engine
node_strategy_engine -->|"dispatches orders"| node_services
node_api -->|"serves analytics"| node_analytics
node_analytics -.->|"reads ticks"| node_market_cache
node_api -->|"dispatches by mode"| node_sandbox_service
node_sandbox_service -->|"manages execution"| node_sandbox_execution
node_sandbox_execution -->|"subscribes to ticks"| node_market_cache
node_sandbox_execution -->|"updates fills and books"| node_sandbox_books
node_sandbox_books -->|"reads and writes"| node_postgres
node_database -->|"connects"| node_postgres
node_redis -.->|"backs cache layer"| node_market_cache

click node_web "https://github.com/marketcalls/openbull/blob/main/frontend/src/App.tsx"
click node_playground "https://github.com/marketcalls/openbull/blob/main/frontend/src/pages/Playground.tsx"
click node_api "https://github.com/marketcalls/openbull/blob/main/backend/main.py"
click node_auth "https://github.com/marketcalls/openbull/blob/main/backend/routers/auth.py"
click node_services "https://github.com/marketcalls/openbull/tree/main/backend/services"
click node_database "https://github.com/marketcalls/openbull/blob/main/backend/database.py"
click node_redis "https://github.com/marketcalls/openbull/blob/main/backend/utils/redis_client.py"
click node_broker_plugins "https://github.com/marketcalls/openbull/tree/main/backend/broker"
click node_stream_adapters "https://github.com/marketcalls/openbull/tree/main/backend/broker"
click node_ws_proxy "https://github.com/marketcalls/openbull/blob/main/backend/websocket_proxy/server.py"
click node_broker_services "https://github.com/marketcalls/openbull/blob/main/backend/services/market_data_service.py"
click node_builder "https://github.com/marketcalls/openbull/blob/main/backend/services/strategy_builder_service.py"
click node_strategy_engine "https://github.com/marketcalls/openbull/blob/main/backend/strategy/engine.py"
click node_strategy_webhook "https://github.com/marketcalls/openbull/blob/main/backend/strategy/webhook_handler.py"
click node_analytics "https://github.com/marketcalls/openbull/tree/main/backend/services"
click node_market_cache "https://github.com/marketcalls/openbull/blob/main/backend/services/market_data_cache.py"
click node_sandbox_service "https://github.com/marketcalls/openbull/blob/main/backend/services/sandbox_service.py"
click node_sandbox_execution "https://github.com/marketcalls/openbull/blob/main/backend/sandbox/execution_engine.py"
click node_sandbox_books "https://github.com/marketcalls/openbull/tree/main/backend/sandbox"

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_playground toneBlue
class node_api,node_auth,node_services,node_database,node_redis,node_postgres toneAmber
class node_broker_plugins,node_stream_adapters,node_ws_proxy,node_broker_services toneMint
class node_builder,node_strategy_engine,node_strategy_webhook toneRose
class node_analytics,node_market_cache,node_user,node_broker_network toneIndigo
class node_sandbox_service,node_sandbox_execution,node_sandbox_books toneTeal
```

## Components

### Client applications

- [Trading UI](https://github.com/marketcalls/openbull/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [API Playground](https://github.com/marketcalls/openbull/blob/main/frontend/src/pages/Playground.tsx): `frontend/src/pages/Playground.tsx`

### API and trading

- [Web and external API](https://github.com/marketcalls/openbull/blob/main/backend/main.py): `backend/main.py`
- [Authentication](https://github.com/marketcalls/openbull/blob/main/backend/routers/auth.py): `backend/routers/auth.py`
- [Trading services](https://github.com/marketcalls/openbull/tree/main/backend/services): `backend/services`
- [Application database](https://github.com/marketcalls/openbull/blob/main/backend/database.py): `backend/database.py`
- [Redis cache](https://github.com/marketcalls/openbull/blob/main/backend/utils/redis_client.py): `backend/utils/redis_client.py`

### Broker integrations

- [Broker APIs](https://github.com/marketcalls/openbull/tree/main/backend/broker): `backend/broker`
- [Streaming adapters](https://github.com/marketcalls/openbull/tree/main/backend/broker): `backend/broker`
- [WebSocket proxy](https://github.com/marketcalls/openbull/blob/main/backend/websocket_proxy/server.py): `backend/websocket_proxy/server.py`
- [Broker services](https://github.com/marketcalls/openbull/blob/main/backend/services/market_data_service.py): `backend/services/market_data_service.py`

### Strategies

- [Strategy builder](https://github.com/marketcalls/openbull/blob/main/backend/services/strategy_builder_service.py): `backend/services/strategy_builder_service.py`
- [Strategy engine](https://github.com/marketcalls/openbull/blob/main/backend/strategy/engine.py): `backend/strategy/engine.py`
- [Strategy webhooks](https://github.com/marketcalls/openbull/blob/main/backend/strategy/webhook_handler.py): `backend/strategy/webhook_handler.py`

### Market data and analytics

- [Options analytics](https://github.com/marketcalls/openbull/tree/main/backend/services): `backend/services`
- [Market data cache](https://github.com/marketcalls/openbull/blob/main/backend/services/market_data_cache.py): `backend/services/market_data_cache.py`

### Sandbox trading

- [Sandbox service](https://github.com/marketcalls/openbull/blob/main/backend/services/sandbox_service.py): `backend/services/sandbox_service.py`
- [Sandbox execution](https://github.com/marketcalls/openbull/blob/main/backend/sandbox/execution_engine.py): `backend/sandbox/execution_engine.py`
- [Sandbox books](https://github.com/marketcalls/openbull/tree/main/backend/sandbox): `backend/sandbox`

### Other components

- **Trader**
- **Broker systems**
- **PostgreSQL**

## Connections

- Trader → Trading UI: uses (evidence: `README.md`)
- Trader → API Playground: tests endpoints (evidence: `README.md`)
- Trading UI → Web and external API: calls web API
- API Playground → Web and external API: tests API (evidence: `README.md`)
- Web and external API → Authentication: routes auth (evidence: `README.md`)
- Web and external API → Trading services: dispatches requests (evidence: `README.md`)
- Trading services → Broker APIs: dispatches broker calls (evidence: `README.md`)
- Broker APIs → Broker systems: calls (evidence: `README.md`)
- Broker systems → Streaming adapters: streams ticks (evidence: `README.md`)
- Streaming adapters → WebSocket proxy: publishes ticks (evidence: `README.md`)
- WebSocket proxy → Trading UI: streams market data (evidence: `README.md`)
- Broker services → Market data cache: updates cache
- Web and external API → Strategy builder: routes strategy tools (evidence: `README.md`)
- Strategy builder → Strategy engine: starts strategy runs
- Strategy webhooks → Strategy engine: dispatches actions (evidence: `backend/strategy/webhook_handler.py`)
- Strategy engine → Trading services: dispatches orders (evidence: `backend/strategy/engine.py`)
- Web and external API → Options analytics: serves analytics (evidence: `README.md`)
- Options analytics → Market data cache: reads ticks (evidence: `backend/services/sandbox_service.py`)
- Web and external API → Sandbox service: dispatches by mode (evidence: `README.md`)
- Sandbox service → Sandbox execution: manages execution (evidence: `backend/services/sandbox_service.py`)
- Sandbox execution → Market data cache: subscribes to ticks (evidence: `backend/sandbox/execution_engine.py`)
- Sandbox execution → Sandbox books: updates fills and books (evidence: `backend/sandbox/execution_engine.py`)
- Sandbox books → PostgreSQL: reads and writes (evidence: `backend/sandbox/_db.py`)
- Application database → PostgreSQL: connects (evidence: `backend/database.py`)
- Redis cache → Market data cache: backs cache layer (evidence: `backend/services/market_data_cache.py`)
