# etrobot/open-alpha-arena architecture

> Architecture diagram of the GitHub repository etrobot/open-alpha-arena, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/etrobot/open-alpha-arena
- Repository: https://github.com/etrobot/open-alpha-arena

## Overview

##### Project type and purpose
- This is a full-stack web application (“Open Alpha Arena”) that lets users configure and run AI-driven crypto trading bots.
- Frontend: A React+TypeScript SPA (Vite) that communicates over REST and WebSockets.
- Backend: A Python 3.10+ FastAPI service with multiple domain services (market data ingestion, AI decisioning, order scheduling/execution), a database layer, and external integrations (CCXT, OpenAI).

##### File structure
- Top-level:
- backend/ – FastAPI app (“main.py”), subdivided into api/, services/, repositories/, database/, schemas/, factors/, config/
- frontend/ – Vite React app (components/, lib/, main.tsx, index.html, config files)
- docker-compose.yml + Dockerfile + monorepo package.json/pnpm-workspace.yaml
- Patterns:
- MVC-ish: api/routes → services → repositories → database models
- Domain services: auto_trader, order_scheduler, ai_decision_service
- Repos abstract DB ops; SQLAlchemy or similar in backend/database/*
- WebSocket endpoint (“/ws”) for streaming updates, plus REST routes for CRUD and trading commands

##### Extract additional insights from README
- Dev servers: backend on 5611, frontend on 5621
- Backend uses Uvicorn (ASGI) with no special build step
- Dependencies: CCXT for market data, OpenAI API, FastAPI, uv (for sync with Python venv), pnpm for JS

##### Detail without over-splitting
- Major services (market_data, ai_decision, order_matching, scheduler).
- WebSocket gateway as a first-class element.
- Cron/scheduler triggers as timed events into services.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Frontend Layer
    subgraph "Frontend (React SPA)" 
        direction TB
        FE_ENTRY["main.tsx"]:::frontend
        FE_API["API Utilities (REST/WebSocket Client)"]:::frontend
        FE_UI["UI Components"]:::frontend
    end

    %% Backend Layer
    subgraph "Backend (FastAPI Service)"
        direction TB
        subgraph "API Layer"
            direction TB
            REST["REST Controllers"]:::api
            WS["WebSocket Gateway Endpoint (/ws)"]:::api
        end

        subgraph "Domain Services"
            direction TB
            MD["Market Data Service"]:::domain
            HLM["HyperLiquid Market Data"]:::domain
            AI["AI Decision Service"]:::domain
            AT["Auto Trader Service"]:::domain
            OSCHED["Order Scheduler Service"]:::domain
            OEXEC["Order Executor Service"]:::domain
            OMATCH["Order Matching Service"]:::domain
            OMON["Order Monitor Service"]:::domain
            TCMD["Trading Commands Interface"]:::domain
            SCHED["Scheduler (Cron Jobs)"]:::domain
            NEWS["News Feed Ingestion"]:::domain
            ACALC["Asset Calculator"]:::domain
            ACURVE["Asset Curve Calculator"]:::domain
        end

        subgraph "Persistence Layer"
            direction TB
            REPO["Repositories"]:::persistence
            DB["Database (SQLAlchemy)"]:::persistence
        end

        subgraph "Support Modules"
            direction TB
            SCHEMA["Pydantic Schemas"]:::support
            CONFIG["Configuration Management"]:::support
            FACTORS["Factor Calculations"]:::support
            STARTUP["Startup & Wiring"]:::support
        end
    end

    %% External Services
    subgraph "External Systems"
        direction TB
        CRYPTO["Crypto Exchanges (CCXT)"]:::external
        OPENAI["OpenAI API"]:::external
        NEWS_SRC["News Feed Sources"]:::external
    end

    %% Infrastructure
    subgraph "Infrastructure"
        direction TB
        DOCKER["Docker & Docker-Compose"]:::infra
        MONOREPO["Monorepo & PNPM"]:::infra
    end

    %% Interactions
    FE_ENTRY -->|"imports"| FE_API
    FE_UI -->|"uses"| FE_API
    FE_API -->|"HTTP (REST)"| REST
    FE_API -->|"WebSocket"| WS
    REST -->|"calls"| MD
    REST -->|"routes to"| AI
    REST -->|"routes to"| AT
    REST -->|"routes to"| OSCHED
    WS -->|"streams from"| MD
    WS -->|"streams from"| OMON
    MD -->|"wraps CCXT"| HLM
    MD -->|"saves data"| REPO
    AI -->|"calls"| OPENAI
    AI -->|"sends signals to"| AT
    AT -->|"places orders via"| OEXEC
    OSCHED -->|"triggers"| AT
    OSCHED -->|"triggers"| OEXEC
    OEXEC -->|"executes via CCXT"| CRYPTO
    OEXEC -->|"records"| REPO
    OMATCH -->|"matches orders"| REPO
    OMON -->|"polls status from"| CRYPTO
    OMON -->|"updates"| REPO
    TCMD -->|"interfaces with"| AT
    SCHED -->|"runs jobs (factors/news)"| FACTORS
    SCHED -->|"runs jobs"| NEWS
    FACTORS -->|"uses"| REPO
    NEWS -->|"ingests from"| NEWS_SRC
    ACALC -->|"calculates"| REPO
    ACURVE -->|"generates curves"| REPO
    REPO -->|"CRUD operations"| DB
    REST -->|"validates with"| SCHEMA
    STARTUP -->|"wires services"| REST
    STARTUP -->|"wires services"| MD
    CONFIG -->|"provides settings to"| STARTUP

    %% Infra connections
    STARTUP -->|"runs on"| DOCKER
    FE_ENTRY -->|"served by"| DOCKER
    REST -->|"served by Uvicorn"| DOCKER
    MONOREPO -->|"manages"| FE_ENTRY

    %% Click events
    click FE_ENTRY "https://github.com/etrobot/open-alpha-arena/blob/main/frontend/app/main.tsx"
    click FE_API "https://github.com/etrobot/open-alpha-arena/blob/main/frontend/app/lib/api.ts"
    click FE_UI "https://github.com/etrobot/open-alpha-arena/tree/main/frontend/app/components"
    click REST "https://github.com/etrobot/open-alpha-arena/tree/main/backend/api"
    click WS "https://github.com/etrobot/open-alpha-arena/blob/main/backend/api/ws.py"
    click CONFIG "https://github.com/etrobot/open-alpha-arena/blob/main/backend/config/settings.py"
    click MD "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/market_data.py"
    click HLM "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/hyperliquid_market_data.py"
    click AI "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/ai_decision_service.py"
    click AT "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/auto_trader.py"
    click OSCHED "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/order_scheduler.py"
    click OEXEC "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/order_executor.py"
    click OMATCH "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/order_matching.py"
    click OMON "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/order_monitor.py"
    click TCMD "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/trading_commands.py"
    click SCHED "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/scheduler.py"
    click NEWS "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/news_feed.py"
    click ACALC "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/asset_calculator.py"
    click ACURVE "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/asset_curve_calculator.py"
    click REPO "https://github.com/etrobot/open-alpha-arena/tree/main/backend/repositories"
    click DB "https://github.com/etrobot/open-alpha-arena/blob/main/backend/database/connection.py"
    click DB "https://github.com/etrobot/open-alpha-arena/blob/main/backend/database/models.py"
    click SCHEMA "https://github.com/etrobot/open-alpha-arena/tree/main/backend/schemas"
    click FACTORS "https://github.com/etrobot/open-alpha-arena/tree/main/backend/factors"
    click STARTUP "https://github.com/etrobot/open-alpha-arena/blob/main/backend/services/startup.py"
    click STARTUP "https://github.com/etrobot/open-alpha-arena/blob/main/backend/main.py"
    click DOCKER "https://github.com/etrobot/open-alpha-arena/tree/main/Dockerfile"
    click DOCKER "https://github.com/etrobot/open-alpha-arena/blob/main/docker-compose.yml"
    click MONOREPO "https://github.com/etrobot/open-alpha-arena/blob/main/pnpm-workspace.yaml"
    click MONOREPO "https://github.com/etrobot/open-alpha-arena/blob/main/package.json"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef api fill:#E2F0D9,stroke:#2E8B57,color:#2E8B57
    classDef domain fill:#E8F4E8,stroke:#228B22,color:#228B22
    classDef persistence fill:#FFE5B4,stroke:#FF8C00,color:#FF8C00
    classDef support fill:#F5F5F5,stroke:#A9A9A9,color:#696969
    classDef external fill:#F0F0F0,stroke:#696969,color:#696969
    classDef infra fill:#F3E5F5,stroke:#8A2BE2,color:#8A2BE2
```
