Architecture
System Architecture
┌─────────────────┐
│ Frontend │
│ (Next.js) │
└────────┬────────┘
│
├─── Dashboard Page
├─── Chat Page
├─── Trading Page
├─── Backrooms Page
└─── Agent Page
│
┌────────▼────────┐
│ API Routes │
│ (Next.js) │
└────────┬────────┘
│
├─── Trading API
├─── Dashboard API
├─── Chat API
└─── Backrooms API
│
┌────────▼────────┐
│ External APIs │
└────────┬────────┘
│
├─── DexScreener
├─── Polymarket
├─── Hyperliquid
└─── Anthropic Claude
│
┌────────▼────────┐
│ MongoDB │
│ (Atlas) │
└─────────────────┘Data Flow
Trading Bot Flow
Background worker triggers every 30 seconds
Fetches market data from all sources
Gets AI decision from Claude
Executes trade via Trading API
Updates MongoDB state
Clients sync state every 1 second
Dashboard Data Flow
Client requests data from Dashboard API
API checks cache (10 seconds TTL)
If cache miss, fetches from external APIs
Returns cached or fresh data
Client updates UI
Auto-refreshes at configured intervals
Chat Flow
User sends message
Chat API receives message
Fetches current market data
Sends context to Claude
Receives AI response
Returns response to user
Caching Strategy
Server-Side Caching
In-Memory Cache: 10 seconds TTL for dashboard data
Vercel Edge Cache: CDN caching with stale-while-revalidate
Cache Headers: Optimized for performance
Client-Side Caching
React State: Local component state
Real-Time Sync: Periodic database sync
Optimistic Updates: Immediate UI updates
Database Schema
Trading State Collection
Reflections Collection
Last updated

