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 executes 3x daily. Mock/rate-limited responses are automatically discarded. Buy signals trigger $1,000 paper trades. A separate validation cron closes positions when TP, SL, or a 14-day expiry is hit.

sequenceDiagram autonumber participant C as Cron participant S as Scanner participant AV as Alpha Vantage participant X as Xpoz participant AI as Gemini Flash participant DB as Supabase participant PT as Paper Trades C->>S: WAKE_UP (9:30, 12:00, 16:00) S->>AV: FETCH_TOP_GAINERS AV-->>S: Symbols + Gap% loop Per Candidate S->>AV: FETCH_TECHNICALS (RVOL, Float) S->>X: FETCH_SENTIMENT Note over S: Calculate Conviction Score S->>AI: ANALYZE (3:1 R/R Enforced) AI-->>S: {recommendation, take_profit, stop_loss} alt Mock/Rate-Limited Response S--xDB: DISCARD (DB Pollution Guard) else Valid Response S->>DB: PERSIST (opportunity + targets) alt recommendation == Buy DB->>PT: AUTO_OPEN ($1,000 position) end end end Note over C,PT: Later (Validation Cron) C->>DB: FETCH unvalidated recs loop Per Recommendation DB->>AV: FETCH_CURRENT_PRICE alt Price >= Take Profit DB->>PT: CLOSE (closed_win) else Price <= Stop Loss DB->>PT: CLOSE (closed_loss) else Age > 14 days DB->>PT: CLOSE (expired) end end

3:1 Risk/Reward Gate

Gemini Flash is explicitly banned from recommending "Buy" unless the profit target is ≥ 3× the stop-loss risk. If the math doesn't pass, the AI must output "Hold".

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["Gemini Flash Analysis"]:::calc TP_CALC["Calculate Take Profit"]:::calc SL_CALC["Calculate Stop Loss"]:::calc RR_CHECK{"R/R >= 3:1?"}:::gate INPUT --> AI AI --> TP_CALC & SL_CALC TP_CALC & SL_CALC --> RR_CHECK RR_CHECK -->|"Yes"| BUY["BUY Signal<br/>+ Paper Trade"]:::pass RR_CHECK -->|"No"| HOLD["HOLD<br/>Rejected"]:::fail

Paper Trade Lifecycle

Every Buy signal auto-opens a $1,000 simulated position. The validation cron closes it when the price hits the AI's exact take-profit or stop-loss target, or after 14 days.

stateDiagram-v2 [*] --> open: Buy Signal ($1,000) open --> closed_win: Price >= Take Profit open --> closed_loss: Price <= Stop Loss open --> expired: Age > 14 days 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 70B)Primary Engine

Lightning-fast inference prevents 10s serverless timeouts.

30 Req/min12,000 Tokens/min
2. Google (Gemini 2.0)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.