Architecture

The lab stacks a backtest engine, REST API, and web dashboard. Data flows from Alpaca through backtests into SQLite, then through the API to the frontend.

System diagram

┌─────────────────────────────────────────────────────────────┐
│ Backtest Engine (scripts/backtest_hourly_agent.py)          │
│ ├─ Fetch Alpaca hourly bars                                 │
│ ├─ Run agent + baseline logic                               │
│ ├─ Write 3 runs (agent, buy-and-hold, DJIA)                 │
│ └─ Store in data/backtest.db (SQLite)                       │
└────────────────┬────────────────────────────────────────────┘
                 │
┌────────────────▼────────────────────────────────────────────┐
│ REST API (backend/app.py)                                   │
│ ├─ GET  /health                                             │
│ ├─ GET  /runs, /runs/{id}/equity, /compare                  │
│ ├─ POST /backtest/run, GET /backtest/status                 │
│ ├─ GET  /ticker                                             │
│ ├─ GET  /paper/account, /paper/positions, …                 │
│ └─ GET  /config/defaults                                    │
└────────────────┬────────────────────────────────────────────┘
                 │
┌────────────────▼────────────────────────────────────────────┐
│ Web Dashboard (frontend/)                                   │
│ ├─ index.html, app.js, styles.css                           │
│ └─ images/                                                  │
└─────────────────────────────────────────────────────────────┘

API surface (summary)

Endpoint

Purpose

GET /health GET /runs GET /runs/{id}/equity GET /compare POST /backtest/run GET /backtest/status GET /ticker GET /paper/* GET /config/defaults

Health check List backtest runs Equity curve for a run Compare multiple runs Start a backtest Poll backtest job status Market quote data Paper-trading account, positions, trades Default UI / run configuration

LLM integration example code lives in backend/llm_integration_example.py (reference only, not wired into the main app path).