20 - Design Principles

Overview

OpenAlgo follows specific design patterns and architectural principles to maintain code quality, extensibility, and reliability across the trading platform.

Core Design Principles

┌──────────────────────────────────────────────────────────────────────────────┐
│                          OpenAlgo Design Principles                          │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                                                                              │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐             │
│  │  Broker         │  │  Separation     │  │  Async          │             │
│  │  Agnostic       │  │  of Concerns    │  │  Operations     │             │
│  │                 │  │                 │  │                 │             │
│  │  Single API for │  │  API → Service  │  │  Non-blocking   │             │
│  │  29 brokers    │  │  → Broker       │  │  logging/alerts │             │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘             │
│                                                                              │
│  ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐             │
│  │  Plugin         │  │  Fail-Safe      │  │  Security       │             │
│  │  Architecture   │  │  Operations     │  │  First          │             │
│  │                 │  │                 │  │                 │             │
│  │  Dynamic broker │  │  Graceful       │  │  Encryption at  │             │
│  │  loading        │  │  degradation    │  │  rest & transit │             │
│  └─────────────────┘  └─────────────────┘  └─────────────────┘             │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘

1. Broker-Agnostic API

Principle

One unified API that works with all 29 supported brokers.

Implementation

Benefits

  • Users switch brokers without code changes

  • Consistent response formats

  • Single learning curve

2. Layered Architecture

Layer Structure

3. Dual Authentication Pattern

Support Both API Key and Direct Auth

4. Analyzer Mode Routing

Transparent Sandbox Integration

Benefits

  • Same API for both modes

  • Risk-free testing

  • Isolated virtual capital

5. Async Non-Blocking Operations

Never Block the Request Thread

Operations Made Async

  • Order logging

  • Socket.IO events

  • Telegram notifications

  • Database writes (non-critical)

6. Plugin Architecture

Dynamic Broker Loading

Plugin Discovery

7. Consistent Response Format

Standard Response Structure

HTTP Status Codes

Status
Meaning

200

Success

400

Validation error

403

Authentication failed

404

Resource not found

429

Rate limit exceeded

500

Server error

8. Caching Strategy

Multi-Level Caching

9. Security Layers

Defense in Depth

10. Error Handling

Graceful Degradation

11. Singleton Pattern

Thread-Safe Singleton

Used For

  • Market data service

  • WebSocket connections

  • HTTP client pools

12. Data Transformation

Broker Mapping Pattern

Key Files Reference

Pattern
Implementation

Plugin loader

utils/plugin_loader.py

Service layer

services/*.py

Broker interface

broker/*/api/*.py

Data transform

broker/*/mapping/*.py

Database layer

database/*.py

Constants

utils/constants.py

Last updated