Back to DashboardGitHub Repo
Technical Documentation

System Architecture

Under the hood of not-financial-advice — a 3-engine, AI-powered money maker.

System Overview

The architecture orchestrates market intelligence through a Tri-Tier AI framework. It dynamically adjusts to macroeconomic regimes, filters candidates via strict Risk/Reward math, and uses DeepSeek R1 to autonomously learn from failed paper trades.

graph TD classDef ai fill:#1e3a8a,stroke:#3b82f6,stroke-width:2px,color:#e0e7ff classDef core fill:#064e3b,stroke:#10b981,stroke-width:2px,color:#d1fae5 classDef data fill:#7c2d12,stroke:#f97316,stroke-width:2px,color:#ffedd5 DB[("Supabase<br/>Database")]:::data SCAN["Scanner & Engine<br/>(Metrics + Regimes)"]:::core AI["Tri-Tier AI<br/>(Groq/DeepSeek/Gemini)"]:::ai TRADE["Execution &<br/>Validation"]:::core LEARN["Post-Mortem<br/>Self-Learning"]:::ai SCAN -->|"Candidate Data"| AI AI -->|"Conviction Score"| TRADE TRADE -->|"Buy/Sell"| DB TRADE -->|"Closed Loss"| LEARN LEARN -->|"New Rules"| DB DB -->|"System Context"| AI

Execution Pipeline

The scanner runs at the open and midday; a third job validates before the close. Mock/rate-limited responses are automatically discarded. Buy and Sell (fade) signals open risk-sized paper trades — each risking 2% of the paper book, not a flat dollar amount. A separate validation cron closes positions when the take-profit, stop, breakeven ratchet, or a time-stop is hit.

graph TD classDef scan fill:#064e3b,stroke:#10b981,color:#d1fae5 classDef ai fill:#1e3a8a,stroke:#3b82f6,color:#dbeafe classDef money fill:#134e4a,stroke:#2dd4bf,color:#ccfbf1 classDef judge fill:#3b0764,stroke:#a855f7,color:#f3e8ff classDef bad fill:#7f1d1d,stroke:#ef4444,color:#fecaca subgraph SCAN["3x a day — the scan"] direction LR A["🛰️ find<br/>top movers"]:::scan --> B["keep<br/>top 3"]:::scan --> C["🧠 AI<br/>analysis"]:::ai --> D["🛡️ risk<br/>gate"]:::money --> E["📈 open<br/>paper trade"]:::money end subgraph GRADE["later — the grader"] direction LR F["💵 real<br/>price"]:::judge --> G["⚖️ win /<br/>loss / expire"]:::judge --> H["📓 learn<br/>a rule"]:::judge end SCAN --> GRADE C -. "mock data" .-> X["🚫 discard"]:::bad
Show the full play-by-play (every step)
sequenceDiagram autonumber participant C as Cron participant S as Scanner participant AV as Alpha Vantage participant X as Xpoz participant AI as AI Analyst participant DB as Supabase participant PT as Paper Trades C->>S: WAKE_UP (9:30, 12:30, 14:30 ET) S->>AV: FETCH_TOP_GAINERS AV-->>S: Symbols + Gap% loop Per Candidate (top 3) S->>AV: FETCH_TECHNICALS (RVOL, Float) S->>X: FETCH_SENTIMENT Note over S: Calculate Conviction Score S->>AI: ANALYZE (Wyckoff + 5 gates, R/R >= 3:1) AI-->>S: {recommendation, take_profit, stop_loss, conviction} alt Mock/Rate-Limited Response S--xDB: DISCARD (DB Pollution Guard) else Valid Response S->>DB: PERSIST (opportunity + targets) alt Buy (gates + R/R floor pass) DB->>PT: AUTO_OPEN LONG (risk-sized: 2% of book) else Sell (fade) DB->>PT: AUTO_OPEN SHORT (risk-sized: 2% of book) end end end Note over C,PT: Later (Validation Cron) C->>DB: FETCH unvalidated recs loop Per Recommendation DB->>AV: FETCH_CURRENT_PRICE + daily bars alt Take-profit touched DB->>PT: CLOSE (closed_win) else Stop / breakeven touched DB->>PT: CLOSE (closed_loss) else Time-stop or 14-day expiry DB->>PT: CLOSE (expired) end end

Risk/Reward Gates

The AI analyst is banned from recommending "Buy" unless the profit target is ≥ 3× the stop-loss risk. Then, before any (paper) capital moves, a server-side backstop independently re-checks the reward/risk at the real fill price and refuses anything below the ~1.22 break-even (floor 1.5×) — so a hallucinated gate can't open a losing-by-design trade.

graph TD classDef pass fill:#064e3b,stroke:#34d399,stroke-width:2px,color:#d1fae5 classDef fail fill:#7f1d1d,stroke:#ef4444,stroke-width:2px,color:#fecaca classDef calc fill:#1e3a8a,stroke:#3b82f6,stroke-width:2px,color:#dbeafe classDef gate fill:#581c87,stroke:#a855f7,stroke-width:3px,color:#f3e8ff INPUT["Stock Data + Sentiment"]:::calc AI["AI Analyst (Wyckoff + 5 gates)"]:::calc TP_CALC["Take Profit + Stop Loss"]:::calc RR_CHECK{"AI Gate 2:<br/>R/R >= 3:1?"}:::gate FLOOR{"Server backstop:<br/>R/R >= 1.5 (EV+)?"}:::gate INPUT --> AI --> TP_CALC --> RR_CHECK RR_CHECK -->|"Yes"| FLOOR RR_CHECK -->|"No"| HOLD["HOLD or Sell (fade)"]:::fail FLOOR -->|"Yes"| BUY["BUY Signal<br/>+ risk-sized Paper Trade"]:::pass FLOOR -->|"No"| REJECT["Rejected<br/>(negative-EV)"]:::fail

Paper Trade Lifecycle

Every Buy or Sell (fade) signal auto-opens a risk-sized simulated position — sized so a stop-out loses a fixed 2% of the book. The validation cron closes it on a take-profit or stop touch (with a breakeven ratchet once +1R is earned), or via a time-stop.

stateDiagram-v2 [*] --> open: Buy/Sell signal (risk-sized 2%) open --> open: +1R reached, stop to breakeven open --> closed_win: TP touched open --> closed_loss: stop / breakeven touched open --> expired: 14-day expiry or 7-day time-stop closed_win --> [*] closed_loss --> [*] expired --> [*]

Tri-Tier AI Strategy

The system is powered by a multi-provider fallback architecture to bypass free-tier rate limits and prevent timeouts.

1. Groq (Llama 3.3 70B)Primary Engine

Lightning-fast inference prevents 10s serverless timeouts.

30 Req/min12,000 Tokens/min
2. Google (Gemini 2.5 Flash)Fallback Engine

High token limit safety net.

15 Req/min1,500 Req/day
3. OpenRouter (DeepSeek R1)Manual Select

Deep quantitative reasoning (Slow: Warning 10s limits).

20 Req/min~1,000 Req/day

The Self-Learning Matrix

A fully autonomous money maker needs to evolve. We built a continuous feedback loop using the reasoning engine.

  • 1
    Algorithmic Post-MortemsWhen a Paper Trade hits a Stop Loss, DeepSeek R1 analyzes the failure.
  • 2
    Rule GenerationThe AI generates a permanent "Trading Rule" (e.g. "Do not buy gap ups in chop").
  • 3
    System Context UpdatesThese rules are injected into future AI prompt weights so the same mistake is never repeated.

Dynamic Macro-Regime

The system is no longer "blind" to broader market conditions. Every morning, DeepSeek R1 categorizes the SPY/QQQ into a specific regime (Bullish, Bearish, Choppy, Volatile). The intraday scanner automatically adjusts its conviction weights based on this bias—demanding higher volume in bearish conditions before firing a signal.

Mock Mode & DB Protection

When API limits are hit across all 3 providers, mock data is generated for UI display but is explicitly discarded from the database. DB pollution guards prevent fake data from corrupting historical analytics.

graph LR classDef check fill:#1e293b,stroke:#475569,color:#e2e8f0 classDef real fill:#064e3b,stroke:#10b981,color:#d1fae5 classDef mock fill:#7c2d12,stroke:#f97316,color:#ffedd5 API["API Call"]:::check --> Check{"Limit Hit?"}:::check Check -->|No| Real["Real Data"]:::real Check -->|Yes| Mock["Mock Data"]:::mock Mock --> Tag["Tag: mock_intraday"]:::mock Mock --> DISCARD["Discard from DB"]:::mock

The Gainer Fade Thesis

Empirical observation: stocks that gap up significantly on the daily Top Gainers list tend to fade sharply within 1-3 days. The larger the gap, the higher the probability of mean-reversion.

Low Fade Risk

3-8%

Moderate gap, sustainable momentum

Medium Fade Risk

8-15%

Overextended, watch for reversal

High Fade Risk

15%+

Extreme gap, likely to retrace hard

The Scanner UI now highlights the "Fade Risk" level on each candidate card. High-gap candidates that the AI rejects as "Hold" are potential short/fade opportunities.