How akhandhediya/openalgo_v2 works
Project Type & Purpose
• OpenAlgo is a monolithic, full-stack Flask application with:
• A unified REST API (Flask-RestX + Blueprints)
• Real-time WebSocket streaming (Flask-SocketIO + ZeroMQ)
• Modular broker integrations (24+ “broker/…” packages)
• Python strategy hosting, sandbox (simulated trading engine)
• UI layer (Jinja2 templates + static assets)
• Auxiliary services (Telegram bot, ChartInk, AI integrations)
• Multiple SQLite DBs (main, logs, latency, sandbox)
File Structure & Map to Layers
• Presentation Layer
• templates/ & static/ – Jinja2 HTML, Tailwind/DaisyUI CSS, JS
• playground/, examples/ – client-side demos
• API Layer
• app.py + blueprints/*.py – Flask app entry and route modules
• restx_api/*.py – OpenAPI schema + REST endpoints
• Service Layer
• services/*.py – Business logic for each endpoint (order, funds, quotes, sandbox, etc.)
• Data Access Layer
• database/*.py – SQLAlchemy models, initialization, caching hooks
• sandbox/*.py – In‐memory/simulated trading logic
• Broker Integration Layer
• broker/<broker-name>/* – Each broker adapter implements auth_api, data_api, order_api, streaming, mapping, plugin.json
• websocket_proxy/ – Unified WebSocket proxy, ZMQ bus, broker factory
• Utility Layer
• utils/*.py – config loader, encryption, rate limiter, logging, middleware, plugin loader
• Infrastructure & Config
• Dockerfile, docker-compose.yaml, .ebextensions, install/, design/, docs/
• .env/.sample.env, config files
• Databases
• SQLite files (main, logs, latency, sandbox) managed via SQLAlchemy
README for Architectural Highlights
• Shows four separate SQLite DBs, broker-pattern, ZeroMQ bus, Flask + SocketIO, Tailwind + DaisyUI
• Lists external clients: TradingView, Python/Go/Node SDKs, AI agents, Telegram, ChartInk
• Emphasizes sandbox isolation, action-center, strategy manager
1. Clients & Integrations
– Web UI (browser)
– REST clients (Python SDK, Go/Node SDK, Postman, Excel, TradingView webhooks)
– AI/MCP agents
– Telegram Bot
2. API & UI Server
– Flask App (app.py)
• Blueprints (auth, dashboard, analyzer, apikey, etc.)
• RESTX API layer
• SocketIO endpoints
3. Service Layer
– Order router, quote service, funds service, sandbox service, action center service, etc.
4. Broker Adapters
– Adapter modules under broker/*: each implements
• REST APIs (auth, data, order, margin)
• Streaming clients + mapping
5. WebSocket Proxy & Message Bus
– websocket_proxy/server.py
– ZeroMQ pub/sub bus
6. Data Layer & Databases
– SQLAlchemy models & multiple SQLite files
– Caching & hooks (master_contract_cache_hook)
7. Sandbox Engine
– sandbox/*.py modules: order_manager, execution_engine, fund_manager, etc.
– Clients → Flask App → Blueprints/RestX → Services → Broker Adapters → External Broker APIs
– Services ↔ Database (SQLAlchemy)
– Broker Adapters → ZMQ Bus → WebSocket Proxy → Clients (via SocketIO/WebSocket)
– UI/browser ↔ Flask (Jinja2 templates + SocketIO)
– Telegram Bot Service → Telegram API
– ChartInk Webhooks → Flask Blueprints → Services
– AI Agents ↔ MCP Server (external component) → Flask App
c. Architectural Patterns & Principles:
– Layered Architecture (Presentation → API → Service → Data)
– Broker-Pattern for pluggable integrations
– Plugin Loader (utils/plugin_loader) for dynamic broker discovery
– Separation of concerns: sandbox vs. live mode (isolated DB)
– Event-driven streaming: ZeroMQ message bus
– Monolithic deployment but modular code organization
– Flask 3.0, Flask-SocketIO, Flask-RestX
– SQLAlchemy 2.0 (SQLite)
– ZeroMQ
– Jinja2, Tailwind CSS + DaisyUI
– Python 3.11+
– Docker, AWS Elastic Beanstalk (.ebextensions)