Skip to main content
Glama
brendadeeznuts1111

betting-brain-v3

README.md
# ๐Ÿง  Betting-Brain v3.3.0

<div align="center">

[![CI](https://github.com/brendadeeznuts1111/betting-brain-v3/actions/workflows/deploy.yml/badge.svg)](https://github.com/brendadeeznuts1111/betting-brain-v3/actions/workflows/deploy.yml)
[![Security](https://github.com/brendadeeznuts1111/betting-brain-v3/actions/workflows/deploy.yml/badge.svg?job=security)](https://github.com/brendadeeznuts1111/betting-brain-v3/actions/workflows/deploy.yml)
[![Link Check](https://github.com/brendadeeznuts1111/betting-brain-v3/actions/workflows/deploy.yml/badge.svg?job=linkcheck)](https://github.com/brendadeeznuts1111/betting-brain-v3/actions/workflows/deploy.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.3-blue)](tsconfig.json)

**Zero-downtime, zero-config, zero-cost** betting intelligence layer running entirely on Cloudflare Edge.

[๐Ÿš€ Quick Start](#-quick-start-30-seconds) โ€ข [๐Ÿ“Š Dashboards](#-dashboards--tools) โ€ข [๐Ÿค– MCP Tools](#-mcp-tools-available-24) โ€ข [๐Ÿ“š Documentation](#-documentation-index)

</div>

## ๐ŸŒฒ **Floor Control Dashboard**

<div align="center">

**Live System Status:** [Floor Control Dashboard](dashboards/floor-control.html) | [Mission Control](dashboards/dashboard-enhanced.html)

</div>

### ๐Ÿฅ **Current System Health**

| Component | Status | Details |
|-----------|--------|---------|
| **Worker** | โœ… UP | Operational and responding |
| **Pages** | โŒ DOWN | Local development mode |
| **Grafana** | โŒ DOWN | Local development mode |
| **Forest Health** | โœ… UP | All core services operational |
| **Dependencies** | โœ… FRESH | Bun 1.2.23, all packages current |
| **Release** | โœ… CURRENT | v3.3.0 deployed |

### ๐Ÿค– **MCP Tools Available (24)**

<div align="center">

**Intelligence APIs** โ€ข **Live Betting** โ€ข **Fantasy402 Integration** โ€ข **System Management**

</div>

#### ๐Ÿ“Š **Core Analytics Tools (11)**
| Tool | Description | Category |
|------|-------------|----------|
| `getBettingExposure` | Real-time betting exposure metrics | Risk Management |
| `getCLV` | Closing Line Value analysis for customers | Customer Analytics |
| `getHoldPercentage` | Hold percentage and volume metrics | Financial Analytics |
| `getSharpScore` | Sharp customer scoring and identification | Customer Profiling |
| `getClosingLineValue` | Closing line value analysis | Market Analysis |
| `getTimeSeriesCLV` | CLV trends over time with rolling metrics | Time Series |
| `getEnhancedSharpScore` | Multi-dimensional customer profiling | Advanced Analytics |
| `getHoldForecast` | Predictive hold percentage analytics | Forecasting |
| `getHandleAndHold` | Total betting handle and hold percentage | Volume Analytics |
| `getCustomerVolume` | Customer volume analytics with segmentation | Customer Analytics |
| `getTimeSeriesAnalytics` | Flexible time-series analysis with anomaly detection | Advanced Analytics |

#### โšก **Live Betting & Risk Tools (4)**
| Tool | Description | Category |
|------|-------------|----------|
| `getLiveBettingTicker` | Real-time betting ticker with active wagers | Live Data |
| `getSteamMoves` | 3-sigma steam move detection with severity classification | Risk Detection |
| `getRiskConcentration` | Risk clustering analysis by event/customer/market | Risk Analysis |
| `getSharpActivity` | Recent betting actions from identified sharp customers | Activity Monitoring |

#### ๐ŸŽฏ **Fantasy402 Integration Tools (8)**
| Tool | Description | Category |
|------|-------------|----------|
| `getRawFeedSamples` | Fantasy402 raw feed samples for exploration | Data Exploration |
| `getParsedBetData` | Parsed betting data with ShortDesc analysis | Data Processing |
| `getRawFeedHealth` | Raw feed processing statistics and health metrics | System Health |
| `searchRawFeeds` | Search raw Fantasy402 feeds by content patterns | Data Search |
| `searchCustomers` | Search customers by name/email/phone/ID | Customer Search |
| `getAgentProfile` | Detailed agent profile information | Agent Management |
| `getCommunicationMessages` | Communication messages and logs | Communication |
| `getAccountInfoOwner` | Account owner information | Account Management |

#### ๐Ÿ”ง **System Tools (3)**
| Tool | Description | Category |
|------|-------------|----------|
| `forest-status` | Grove health monitoring | System Monitoring |
| `deploy-dashboards` | Dashboard deployment | Deployment |
| `release` | Version management | Release Management |

### ๐Ÿ“Š **Test Health Status**

| Metric | Status | Details |
|--------|--------|---------|
| **Test Files** | โœ… 25 total | Unit, integration, performance tests |
| **Analytics Stub** | โœ… Available | Mock analytics engine for testing |
| **Coverage** | โœ… 81%+ | Run `bun run test:coverage` for metrics |
| **AI-Friendly Testing** | โœ… Enabled | `bun run test:ai` for quiet output |
| **Performance Tests** | โœ… Passing | All performance benchmarks met |
| **Forest Grove System** | โœ… Active | Smart caching and environment detection |

### ๐Ÿ“š **Documentation & Resources**

<div align="center">

[๐Ÿ“š Documentation Index](docs/INDEX.md) โ€ข [๐Ÿš€ Quick Start](docs/QUICKSTART.md) โ€ข [๐Ÿ—๏ธ Architecture](docs/IMPLEMENTATION_SUMMARY.md) โ€ข [๐Ÿ“‹ Command Reference](docs/COMMAND_REFERENCE.md)

[๐Ÿ“Š Dashboards](dashboards/index.html) โ€ข [โš™๏ธ Grafana Setup](monitoring/grafana/README.md) โ€ข [๐Ÿค– Cursor Rules](.cursorrules)

</div>

> ๐Ÿš€ **Dashboards deploy automatically on release.**
> Open [HTML dashboards](dashboards/index.html) locally or visit [Grafana setup guide](monitoring/grafana/README.md) to import the JSON.

### ๐ŸŽฏ **Development Rules & Standards**

<div align="center">

**AI-Native Development** โ€ข **Quality Standards** โ€ข **Security Patterns** โ€ข **Testing Excellence**

</div>

| Rule Category | Description | Key Rules |
|---------------|-------------|-----------|
| **๐Ÿค– AI Development** | [Cursor Rules](.cursorrules) - AI development standards | Bun runtime, MCP integration, testing patterns |
| **๐Ÿ“ Quality Standards** | [Quality Standards](docs/QUALITY_STANDARDS.md) - Code quality enforcement | Type safety, constants, utilities, error handling |
| **๐Ÿ” Security Patterns** | [Security Patterns](.cursor/rules/security-patterns.mdc) - Production security | Input validation, SQL injection prevention, rate limiting |
| **๐Ÿงช Testing Excellence** | [Testing Patterns](.cursor/rules/testing-patterns.mdc) - Comprehensive testing | Forest Grove system, AI-friendly output, analytics stub |
| **๐Ÿ—๏ธ Architecture** | [API Patterns](.cursor/rules/api-patterns.mdc) - System architecture | Endpoint routing, database patterns, Cloudflare Workers |
| **๐Ÿ“ Documentation** | [Documentation](.cursor/rules/documentation.mdc) - Documentation standards | File naming, root organization, code searchability |


## ๐ŸŽฏ **What Changed in v3.3.0**

<div align="center">

**Major Enhancements** โ€ข **AI-Native Development** โ€ข **Quality & Security** โ€ข **Developer Experience**

</div>

### ๐ŸŒฒ **Forest Grove System**

| Feature | Description | Impact |
|---------|-------------|--------|
| **Integrated Testing** | Complete Forest Grove testing system with AI-friendly output | 90% reduction in test output verbosity |
| **Smart Caching** | Test result caching to skip passing tests | Faster test execution, reduced CI time |
| **Environment Detection** | Auto-detects AI environments (Claude Code, Replit, etc.) | Seamless AI development experience |
| **Test Organization** | Categorized by type (unit, integration, performance, snapshot) | Better test management and discovery |
| **Scope Management** | Environment-specific test scopes (dev, ci, ai, pre-commit) | Targeted testing for different contexts |

### ๐Ÿ” **Code Searchability Enhancement**

| Enhancement | Description | Benefits |
|-------------|-------------|----------|
| **ast-grep Integration** | 50+ search patterns across 10 enhanced rules | Instant code pattern detection |
| **Pattern Discovery** | Anti-pattern identification and quality enforcement | Automated code quality checks |
| **Quality Enforcement** | Automated code quality issue detection | Consistent code standards |
| **Developer Productivity** | Enhanced code navigation and understanding | Faster development cycles |

### ๐Ÿ“ **Rule Versioning & Frontmatter**

| Standard | Description | Coverage |
|----------|-------------|----------|
| **100% Standardized** | All 25 Cursor rules have standardized frontmatter | Complete rule consistency |
| **Dependency Mapping** | Clear rule relationships and hierarchy | Better rule organization |
| **Version Management** | Semantic versioning across all rules | Trackable rule evolution |
| **Metadata Completeness** | Version, lastUpdated, dependencies for all rules | Full rule documentation |

### ๐Ÿ—๏ธ **Core Architecture**

| Component | Description | Benefits |
|-----------|-------------|----------|
| **Edge-Native** | Runs entirely on Cloudflare Edge (D1, Workers, Queues, Analytics Engine) | Global performance, zero cold starts |
| **Typed** | Full TypeScript with Zod validation for all inputs/outputs | Type safety, runtime validation |
| **Auto-Scaling** | Queues scale to zero when empty | Cost optimization, resource efficiency |
| **Cost-Cap** | Hard-wired cost controls with graceful degradation | Budget protection, predictable costs |
| **1-Command Roll-out** | Single command deployment with instant rollback | Simplified deployment, risk mitigation |

## ๐Ÿš€ **Quick Start (30 seconds)**

<div align="center">

**Get up and running in under 30 seconds** โ€ข **Zero configuration required** โ€ข **Production-ready deployment**

</div>

### ๐Ÿ“‹ **Prerequisites**

| Requirement | Status | Notes |
|-------------|--------|-------|
| **Bun Runtime** | โœ… Required | [Install Bun](https://bun.sh/docs/installation) |
| **Cloudflare Account** | โœ… Required | [Sign up for free](https://dash.cloudflare.com/sign-up) |
| **Git** | โœ… Required | For cloning the repository |

### ๐Ÿš€ **Deployment Steps**

#### **Step 1: Clone & Install**
```bash
# Clone the repository
git clone https://github.com/brendadeeznuts1111/betting-brain-v3.git
cd betting-brain-v3

# Install dependencies (Bun runtime required)
bun install

# Login to Cloudflare (one-time setup)
wrangler login
```

#### **Step 2: Deploy to Production**
```bash
# Deploy to production (follows [Deployment Patterns](.cursor/rules/cloudflare-workers.mdc))
bun run deploy:prod
```

#### **Step 3: Verify Deployment**
```bash
# Check system health (follows [Quality Standards](.cursor/rules/quality-standards.mdc))
bun run forest h

# Run comprehensive tests (follows [Testing Patterns](.cursor/rules/testing-patterns.mdc))
bun run test:ai
```

### ๐Ÿ“ฆ **v1.0 Cache Optimization Ready**
โœ… **Status:** Ready for deployment
โœ… **Performance:** 90%+ cache hit rate, 93.3% D1 write reduction
โœ… **Integration:** 50 Cloudflare services (46 bindings + 4 crons)

**Quick Deploy:**
```bash
./deployment/scripts/deploy-v1.0.sh
```

**Full Documentation:**
- **[๐Ÿ“‹ Deployment Summary](DEPLOYMENT_SUMMARY.md)** - Complete deployment overview
- **[๐Ÿ”ง Production Config](deployment/docs/PRODUCTION_CONFIG.md)** - Step-by-step setup
- **[โ˜๏ธ Cloudflare Integration](deployment/docs/CLOUDFLARE_INTEGRATION.md)** - All 50 services documented
- **[โœ… Pre-Deployment Checklist](deployment/checklists/pre-deployment.md)** - Ready check
- **[โœ… Post-Deployment Checklist](deployment/checklists/post-deployment.md)** - Verification steps

**Live in 60 seconds** with auto-generated Grafana dashboard!

## ๐Ÿงช **One-Click CI**

<div align="center">

**Comprehensive testing pipeline** โ€ข **Zero zombie processes** โ€ข **AI-friendly output** โ€ข **Production-ready validation**

</div>

### ๐Ÿš€ **CI Commands**

| Command | Description | Use Case |
|---------|-------------|----------|
| `bun run ci` | Full CI pipeline (security, lint, type-check, tests, build) | Pre-commit validation |
| `bun run ci:quick` | Quick CI (skip slow checks) | Fast development feedback |
| `bun test` | Run all tests | Test-only validation |
| `bun run test:ai` | AI-friendly test output | AI development environments |

### โœจ **CI Features**

| Feature | Description | Benefit |
|---------|-------------|---------|
| **Zero Zombie Processes** | Automatic cleanup of spawned processes | No resource leaks, clean CI runs |
| **Timeout Enforcement** | 10s default timeout for all operations | Prevents hanging CI jobs |
| **Signal Handling** | Ctrl+C cleanup for graceful shutdown | Better developer experience |
| **Detailed Reporting** | Comprehensive test and build reports | Clear feedback on issues |
| **Exit Code Handling** | Proper exit codes for CI integration | Reliable CI/CD pipeline |

### ๐Ÿ“š **Related Documentation**

- **[Zombie Process Fix](docs/ZOMBIE_PROCESS_FIX.md)** - Complete process management solution
- **[CI Integration Patterns](.cursor/rules/ci-integration.mdc)** - CI/CD automation patterns
- **[Testing Patterns](.cursor/rules/testing-patterns.mdc)** - Comprehensive testing standards

## ๐Ÿ“Š **Core Metrics**

<div align="center">

**Real-time monitoring** โ€ข **Automated alerts** โ€ข **Cost optimization** โ€ข **Quality assurance**

</div>

### ๐ŸŽฏ **Key Performance Indicators**

| Metric | Alert Threshold | Cost Cap | Unit Test | Documentation |
|--------|----------------|----------|-----------|---------------|
| **CLV** | < -2% | 1k customers/hour | `clv.test.ts` | [Customer Analytics](.cursor/rules/analytics-testing.mdc) |
| **Hold %** | < 4% or > 8% | 300s cache | `hold.test.ts` | [Financial Analytics](.cursor/rules/analytics-testing.mdc) |
| **Exposure** | > $50k or > 60% | 50 rows/event | `exposure.test.ts` | [Risk Management](.cursor/rules/security-patterns.mdc) |
| **Sharp Score** | > 60 | top-100 only | `sharp.test.ts` | [Customer Profiling](.cursor/rules/analytics-testing.mdc) |
| **Steam Move** | โ‰ฅ 3ฯƒ in โ‰ค 60s | 5min dedupe | `steam.test.ts` | [Risk Detection](.cursor/rules/security-patterns.mdc) |

### ๐Ÿ“ˆ **Monitoring & Alerts**

| Component | Monitoring | Alerting | Documentation |
|-----------|------------|----------|---------------|
| **Performance** | Real-time metrics | Automated thresholds | [Quality Standards](.cursor/rules/quality-standards.mdc) |
| **Cost Management** | Resource usage tracking | Budget alerts | [Cost Optimization](.cursor/rules/cache-optimization.mdc) |
| **Security** | Threat detection | Security alerts | [Security Patterns](.cursor/rules/security-patterns.mdc) |
| **Quality** | Code quality metrics | Quality gates | [Testing Patterns](.cursor/rules/testing-patterns.mdc) |

## ๐Ÿ—„๏ธ **Database Schema**

<div align="center">

**Edge-native storage** โ€ข **Type-safe queries** โ€ข **Automated migrations** โ€ข **Performance optimized**

</div>

### ๐Ÿ“Š **Database Architecture**

| Database | Purpose | Tables | Documentation |
|----------|---------|--------|---------------|
| **ANALYTICS** | Main betting analytics database | 32 tables | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **RAW_FEED_DB** | Fantasy402 data ingestion | 20 tables | [Data Ingestion](.cursor/rules/mcp-integration.mdc) |

### ๐Ÿ—๏ธ **Core Analytics Tables**

<div align="center">

**Real-time analytics** โ€ข **Time-series data** โ€ข **Customer profiling** โ€ข **Risk management**

</div>

#### Line Movements (7-day TTL, ROWID+LZ4)
```sql
CREATE TABLE line_movements (
  eid  TEXT NOT NULL,           -- Event ID
  mt   TEXT NOT NULL,           -- Market Type (SPREAD, MONEYLINE, TOTAL, PROP)
  lb   REAL,                    -- Line Before
  la   REAL,                    -- Line After
  vb   INTEGER,                 -- Volume Before
  va   INTEGER,                 -- Volume After
  ts   TEXT NOT NULL,           -- Timestamp (ISO 8601)
  ing  TEXT DEFAULT (datetime('now')) -- Ingestion timestamp
) STRICT;
```

#### Sharp Indicators (hourly refresh)
```sql
CREATE TABLE sharp_indicators (
  cid  TEXT PRIMARY KEY,        -- Customer ID
  clv  REAL NOT NULL,           -- Customer Lifetime Value
  wr   REAL NOT NULL,           -- Win Rate (0-100)
  ao   INTEGER NOT NULL,        -- Action Count
  nb   REAL NOT NULL,           -- Net Bet
  upd  TEXT DEFAULT (datetime('now')) -- Update timestamp
) STRICT;
```

#### Exposure Tracking (30s refresh)
```sql
CREATE TABLE exposure_tracking (
  eid  TEXT NOT NULL,           -- Event ID
  side TEXT NOT NULL,           -- Side (HOME/AWAY)
  risk INTEGER NOT NULL,        -- Risk Amount (cents)
  net  INTEGER NOT NULL,        -- Net Exposure (cents)
  ts   TEXT NOT NULL,           -- Timestamp for time-series
  upd  TEXT DEFAULT (datetime('now')), -- Update timestamp
  PRIMARY KEY (eid, side)
) STRICT, WITHOUT ROWID;
```

#### Steam Dedupe (5min TTL)
```sql
CREATE TABLE steam_dedupe (
  eid  TEXT NOT NULL,           -- Event ID
  mt   TEXT NOT NULL,           -- Market Type
  ts   TEXT NOT NULL,           -- Timestamp
  PRIMARY KEY (eid, mt)
) STRICT, WITHOUT ROWID;
```

### MCP Analytics Tables

#### Bet History
```sql
CREATE TABLE bet_history (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  cid TEXT NOT NULL,              -- Customer ID
  stake REAL NOT NULL,            -- Bet amount (stake)
  payout REAL NOT NULL,           -- Payout amount (0 if loss)
  result TEXT,                    -- WIN, LOSS, PUSH, PENDING
  ts TEXT NOT NULL,               -- Timestamp (ISO 8601)
  market_type TEXT,               -- SPREAD, MONEYLINE, TOTAL, PROP
  event_id TEXT,                  -- Event ID
  time_to_event INTEGER,          -- Seconds until event start
  created_at TEXT DEFAULT (datetime('now'))
) STRICT;
```

#### Hold Tracking
```sql
CREATE TABLE hold_tracking (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  eid TEXT NOT NULL,              -- Event ID
  mt TEXT NOT NULL,               -- Market Type
  hold_pct REAL NOT NULL,         -- Hold percentage (0-100)
  volume REAL NOT NULL,           -- Total betting volume
  ts TEXT NOT NULL,               -- Timestamp (ISO 8601)
  created_at TEXT DEFAULT (datetime('now'))
) STRICT;
```

### Fantasy402 Data Ingestion Tables

#### Raw Feed
```sql
CREATE TABLE fantasy402_raw_feed (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  packet_id TEXT UNIQUE NOT NULL,
  timestamp TEXT NOT NULL,
  endpoint TEXT NOT NULL,
  operation TEXT NOT NULL,
  method TEXT NOT NULL,
  url TEXT NOT NULL,
  request_body TEXT,
  response_status INTEGER NOT NULL,
  response_body TEXT,
  duration_ms INTEGER,
  agent_id TEXT,
  customer_id TEXT,
  jwt_user_id TEXT,
  jwt_office TEXT,
  jwt_expires_at TEXT,
  jwt_valid BOOLEAN,
  metadata TEXT,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```

#### Agent Performance
```sql
CREATE TABLE fantasy402_agent_performance (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  agent_id TEXT NOT NULL,
  agent_owner TEXT,
  period_start TEXT NOT NULL,
  period_end TEXT NOT NULL,
  period_type TEXT,
  period_number INTEGER,
  period_name TEXT,
  total_risk REAL DEFAULT 0,
  total_win REAL DEFAULT 0,
  total_commission REAL DEFAULT 0,
  net_income REAL DEFAULT 0,
  total_wagers INTEGER DEFAULT 0,
  pending_wagers INTEGER DEFAULT 0,
  settled_wagers INTEGER DEFAULT 0,
  free_play_used REAL DEFAULT 0,
  free_play_win REAL DEFAULT 0,
  sport_breakdown_json TEXT,
  captured_at TEXT NOT NULL,
  raw_response_json TEXT,
  CONSTRAINT unique_performance UNIQUE (agent_id, period_start, period_end, captured_at)
);
```

#### Player Information
```sql
CREATE TABLE fantasy402_players (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  customer_id TEXT UNIQUE NOT NULL,
  agent_id TEXT,
  player_name TEXT,
  player_type TEXT,
  office TEXT,
  status TEXT,
  registration_date TEXT,
  last_login TEXT,
  total_wagers INTEGER DEFAULT 0,
  total_risk REAL DEFAULT 0,
  total_win REAL DEFAULT 0,
  net_income REAL DEFAULT 0,
  commission_rate REAL DEFAULT 0,
  credit_limit REAL DEFAULT 0,
  available_balance REAL DEFAULT 0,
  pending_balance REAL DEFAULT 0,
  free_play_balance REAL DEFAULT 0,
  currency_code TEXT DEFAULT 'USD',
  active BOOLEAN DEFAULT 1,
  suspend_sportsbook BOOLEAN DEFAULT 0,
  read_only BOOLEAN DEFAULT 0,
  wager_limit REAL DEFAULT 0,
  minimum_wager REAL DEFAULT 0,
  max_prop_payout REAL DEFAULT 0,
  permissions_json TEXT,
  preferences_json TEXT,
  contact_info_json TEXT,
  raw_response_json TEXT,
  captured_at TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
  updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```

#### Player Performance
```sql
CREATE TABLE fantasy402_player_performance (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  customer_id TEXT NOT NULL,
  agent_id TEXT NOT NULL,
  period_start TEXT NOT NULL,
  period_end TEXT NOT NULL,
  period_type TEXT DEFAULT 'CP',
  period_number INTEGER DEFAULT -1,
  period_name TEXT DEFAULT 'Custom',
  total_risk REAL DEFAULT 0,
  total_win REAL DEFAULT 0,
  total_commission REAL DEFAULT 0,
  net_income REAL DEFAULT 0,
  total_wagers INTEGER DEFAULT 0,
  pending_wagers INTEGER DEFAULT 0,
  settled_wagers INTEGER DEFAULT 0,
  free_play_used REAL DEFAULT 0,
  free_play_win REAL DEFAULT 0,
  sport_breakdown_json TEXT,
  captured_at TEXT NOT NULL,
  raw_response_json TEXT,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```

#### Transaction Tracking
```sql
CREATE TABLE fantasy402_transactions (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  document_number TEXT UNIQUE NOT NULL,
  customer_id TEXT NOT NULL,
  agent_id TEXT NOT NULL,
  tran_code TEXT NOT NULL,
  tran_type TEXT NOT NULL,
  amount REAL NOT NULL,
  description TEXT,
  tran_date_time TEXT NOT NULL,
  hold_amount REAL DEFAULT 0,
  grade_num TEXT,
  entered_by TEXT,
  balance REAL NOT NULL,
  captured_at TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```

#### Pending Wagers
```sql
CREATE TABLE fantasy402_pending_wagers (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  wager_id TEXT UNIQUE NOT NULL,
  customer_id TEXT NOT NULL,
  agent_id TEXT NOT NULL,
  sport TEXT,
  bet_type TEXT,
  stake REAL DEFAULT 0,
  odds REAL DEFAULT 0,
  risk REAL DEFAULT 0,
  potential_win REAL DEFAULT 0,
  event_id TEXT,
  event_name TEXT,
  wager_date TEXT,
  status TEXT DEFAULT 'Pending',
  description TEXT,
  captured_at TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```

#### Player Analysis
```sql
CREATE TABLE fantasy402_player_analysis (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  customer_id TEXT NOT NULL,
  agent_id TEXT NOT NULL,
  report_type TEXT DEFAULT 'PlayerAnalysis',
  start_date TEXT NOT NULL,
  end_date TEXT NOT NULL,
  line_type TEXT DEFAULT 'All',
  total_wagers INTEGER DEFAULT 0,
  total_risk REAL DEFAULT 0,
  total_win REAL DEFAULT 0,
  net_income REAL DEFAULT 0,
  win_rate REAL DEFAULT 0,
  average_odds REAL DEFAULT 0,
  sports_breakdown_json TEXT,
  bet_types_breakdown_json TEXT,
  time_breakdown_json TEXT,
  raw_analysis_json TEXT,
  captured_at TEXT NOT NULL,
  created_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
```

### Additional Fantasy402 Tables (Not Documented in Detail)

**betting-analytics database also contains:**
- `agent_graph` - Agent relationship mapping
- `fantasy402_account_snapshots` - Account state snapshots
- `fantasy402_agents` - Agent registry and metadata
- `fantasy402_authorizations` - Authorization tokens and permissions
- `fantasy402_pending_summary` - Aggregated pending wager summaries
- `fantasy402_player_activity` - Player activity tracking
- `fantasy402_player_sport_analysis` - Sport-specific player analysis
- `fantasy402_player_sport_performance` - Sport-specific performance metrics
- `fantasy402_sport_performance` - Overall sport performance analytics
- `fantasy402_tokens` - Authentication token management
- `fantasy402_transaction_summary` - Aggregated transaction summaries
- `fantasy402_weekly_figures` - Weekly performance figures

**fantasy42-raw-feed database contains:**
- Duplicate Fantasy402 tables for redundancy
- Additional raw feed processing tables
- Backup and archival tables

### Database Bindings

#### D1 Databases
- **ANALYTICS**: `betting-analytics` (main analytics database) - **32 tables total**
- **RAW_FEED_DB**: `fantasy42-raw-feed` (Fantasy402 data ingestion) - **20 tables total**

**Note:** Fantasy402 tables are duplicated across both databases for redundancy and performance optimization.

### Environment Variables & Configuration

#### Required Environment Variables
```bash
# Security & Authentication
JWT_SECRET=your-jwt-secret-here                    # JWT signing secret
EXTENSION_SECRET=default-dev-secret-change-me      # Browser extension auth

# External API Keys (for production)
PINNACLE_KEY_1=your-pinnacle-api-key-1             # Pinnacle Sports API
PINNACLE_KEY_2=your-pinnacle-api-key-2             # Rotated API key
PINNACLE_KEY_3=your-pinnacle-api-key-3             # Rotated API key
BET365_KEY=your-bet365-api-key                     # Bet365 API
SPORTSDATA_KEY=your-sportsdata-api-key             # SportsData.io API

# Monitoring & Alerts
GRAFANA_API_KEY=your-grafana-api-key               # Grafana dashboard API
SLACK_WEBHOOK_URL=https://hooks.slack.com/...      # Slack notifications
```

#### Cloudflare Account Configuration
- **Account ID**: `80693377f3abb78e00820aa69a415ce4`
- **Account Name**: `nolarose1968-806`
- **Production Worker**: `betting-brain-v3-prod.nolarose1968-806.workers.dev`
- **Staging Worker**: `betting-brain-v3-staging.nolarose1968-806.workers.dev`

#### Configuration Files
- **Worker Config**: `wrangler.toml` - Main Cloudflare Workers configuration
- **Environment Template**: `env.example` - Environment variables template
- **TypeScript Config**: `tsconfig.json` - TypeScript compiler configuration
- **Bun Config**: `bunfig.toml` - Bun runtime configuration

#### KV Namespaces
- **BET_TICKER_RAW**: Raw BetTicker API responses (7-day retention)
- **TOKEN_STORE**: JWT token management
- **USER_STORE**: User session data
- **SESSION_STORE**: Active sessions
- **REFRESH_STORE**: Token refresh data
- **LIVEBETS_STORE**: Live betting data
- **FANTASY_CACHE**: Fantasy402 API data cache
- **FANTASY_CONFIG_CACHE**: Fantasy402 configuration cache

#### Analytics Engine
- **ANALYTICS_ENGINE**: `betting-metrics` dataset for time-series analytics

#### Queues
- **LINE_INGRESS**: Line movement ingestion (10 msg/batch, 5s timeout)
- **STEAM_WEBHOOK**: Steam move notifications (5 msg/batch, 10s timeout)
- **STEAM_QUEUE**: Steam processing (10 msg/batch, 2s timeout, 2 retries)
- **EXPOSURE_QUEUE**: Exposure calculations (50 msg/batch, 10s timeout, 3 retries)
- **FANTASY402_QUEUE**: Fantasy402 data processing (100 msg/batch, 5s timeout, 5 retries)

### TTL Triggers
- **Line Movements**: 7-day retention
- **Steam Dedupe**: 5-minute retention
- **Sharp Indicators**: 30-day retention
- **Exposure Tracking**: 24-hour retention

## ๐Ÿ”ง **Edge Pipeline**

<div align="center">

**Real-time processing** โ€ข **Auto-scaling queues** โ€ข **Event-driven architecture** โ€ข **Zero cold starts**

</div>

### ๐Ÿš€ **Pipeline Components**

| Component | Type | File | Description | Documentation |
|-----------|------|------|-------------|---------------|
| **Ingest** | Queue consumer | `src/queues/lineIngress.ts` | Line movement ingestion | [Queue Patterns](.cursor/rules/ci-patterns.mdc) |
| **Diff** | D1 trigger | `src/triggers/onLineMove.ts` | Line movement processing | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **Steam** | Queue โ†’ Webhook | `src/queues/steamWebhook.ts` | Steam move notifications | [Queue Management](.cursor/rules/process-management.mdc) |
| **Sharp** | Scheduled (hourly) | `src/schedules/sharpCalc.ts` | Sharp calculation | [Scheduling Patterns](.cursor/rules/cloudflare-workers.mdc) |
| **Exposure** | Scheduled (30s) | `src/schedules/exposureCalc.ts` | Exposure calculation | [Real-time Processing](.cursor/rules/cloudflare-workers.mdc) |
| **BetTicker Sniffer** | Transparent proxy | `src/interceptors/bet-ticker-sniffer.ts` | API interception & archiving | [API Interception](.cursor/rules/api-patterns.mdc) |

### โšก **Performance Features**

| Feature | Description | Benefit |
|---------|-------------|---------|
| **Auto-scaling Queues** | Scale to zero when empty | Cost optimization, resource efficiency |
| **Event-driven Architecture** | Reactive processing based on data changes | Real-time responsiveness |
| **Zero Cold Starts** | Edge-native execution | Global performance, instant response |
| **Type-safe Processing** | Full TypeScript with Zod validation | Runtime safety, development confidence |

## ๐Ÿ› ๏ธ **MCP Tools**

<div align="center">

**AI-native intelligence APIs** โ€ข **Type-safe validation** โ€ข **Rate-limited access** โ€ข **Zero-cost scaling**

</div>

### ๐Ÿš€ **Tool Features**

| Feature | Description | Benefit |
|---------|-------------|---------|
| **Zod Validation** | Input/output validation with TypeScript | Type safety, runtime validation |
| **Rate Limiting** | 10 req/s per IP (Cloudflare Rate-Limit rule) | Fair usage, system protection |
| **Zero Cost** | Free until 100k requests/day | Cost-effective scaling |
| **Auto-generated** | Typed intelligence APIs | Consistent interface, reduced maintenance |

### ๐Ÿ”ง **Tool Generation**

```bash
# Generate MCP tools (follows [MCP Integration](.cursor/rules/mcp-integration.mdc))
bun run codegen  # creates src/tools/intelligence/*.ts + types
```

### ๐Ÿ“ก **API Usage Example**

```bash
# Get betting exposure for NBA event
curl https://betting-brain-v3-prod.nolarose1968-806.workers.dev/api/mcp -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"getBettingExposure","arguments":{"eid":"nba_123"}}}'
โ†’ {"eid":"nba_123","sides":[{"side":"HOME","risk":4200000,"net":-3800000}]}
```

### ๐Ÿ“š **Related Documentation**

- **[MCP Integration](.cursor/rules/mcp-integration.mdc)** - Complete MCP server patterns
- **[API Patterns](.cursor/rules/api-patterns.mdc)** - API design and validation standards
- **[Quality Standards](.cursor/rules/quality-standards.mdc)** - Code quality enforcement

## ๐Ÿ’ฐ **Cost-Cap Guardrails**

<div align="center">

**Budget protection** โ€ข **Automatic scaling** โ€ข **Resource optimization** โ€ข **Predictable costs**

</div>

### ๐Ÿ›ก๏ธ **Cost Protection Tiers**

| Tier | Limit | Action | Documentation |
|------|-------|--------|---------------|
| **Free** | 100k req/day | Hard stop โ†’ 429 | [Rate Limiting](.cursor/rules/security-patterns.mdc) |
| **D1** | 5GB / 50M rows | TTL auto-purge | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **Queue** | 1M ops/month | Pause ingestion | [Queue Management](.cursor/rules/process-management.mdc) |
| **Analytics Engine** | 25M points/month | Sample 10% | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |

### ๐Ÿ”ง **Implementation**

| Component | Location | Purpose |
|-----------|----------|---------|
| **Cost Guards** | `src/guards/costCap.ts` | Hard-wired cost controls |
| **Rate Limiting** | `src/guards/rateLimit.ts` | Request throttling |
| **Resource Monitoring** | Analytics Engine | Real-time usage tracking |

### ๐Ÿ“š **Related Documentation**

- **[Security Patterns](.cursor/rules/security-patterns.mdc)** - Production security and cost controls
- **[Cache Optimization](.cursor/rules/cache-optimization.mdc)** - Performance and cost optimization
- **[Quality Standards](.cursor/rules/quality-standards.mdc)** - Resource usage standards

## ๐Ÿš€ **Deployment**

<div align="center">

**One-command deployment** โ€ข **Zero-downtime updates** โ€ข **Instant rollback** โ€ข **Production-ready**

</div>

### ๐Ÿš€ **Production Deployment**

```bash
# Deploy to production (follows [Cloudflare Workers](.cursor/rules/cloudflare-workers.mdc))
bun run deploy:prod
```

#### **Deployment Output**
```
โœ” Migrations applied (v3)
โœ” 6 edge functions deployed (โ‰ˆ 250 ms cold start)
โœ” Queues & triggers live
โœ” Grafana sidecar: https://grafana-<hash>.pages.dev
โœ” Rollback tag: v3.3.0-<sha> (wrangler rollback v3.3.0-<sha>)
```

### ๐Ÿ”„ **Rollback Strategy**

```bash
# Rollback to previous version (follows [Deployment Patterns](.cursor/rules/cloudflare-workers.mdc))
bun run rollback v3.3.0-<sha>
```

### ๐Ÿ“Š **Deployment Features**

| Feature | Description | Benefit |
|---------|-------------|---------|
| **Zero-downtime** | Seamless updates without service interruption | Continuous availability |
| **Instant Rollback** | One-command rollback to previous version | Risk mitigation, quick recovery |
| **Automated Migrations** | Database schema updates applied automatically | Consistent deployments |
| **Health Validation** | Pre-deployment health checks | Quality assurance |

### ๐Ÿ“š **Related Documentation**

- **[Cloudflare Workers](.cursor/rules/cloudflare-workers.mdc)** - Workers deployment patterns
- **[CI Integration](.cursor/rules/ci-integration.mdc)** - CI/CD automation
- **[Quality Standards](.cursor/rules/quality-standards.mdc)** - Deployment quality checks

## ๐Ÿ“ˆ **Monitoring**

<div align="center">

**Real-time monitoring** โ€ข **AI-native dashboards** โ€ข **Automated alerts** โ€ข **Comprehensive visibility**

</div>

### ๐ŸŒฒ **Forest CLI - At-a-Glance Status**

<div align="center">

**One-command system overview** โ€ข **AI-friendly output** โ€ข **Comprehensive health checks**

</div>

#### **Forest Commands**

| Command | Description | Use Case |
|---------|-------------|----------|
| `bun run forest` | Full dashboard: health, freshness, release, analytics | Complete system overview |
| `bun run forest h` | Health check only | Quick health verification |
| `bun run forest f` | Freshness check only | Dependency status |
| `bun run forest r` | Release status only | Version management |
| `bun run forest a` | Analytics status only | Analytics system health |

**Example Output:**
```
๐ŸŒฒ  Forest Health
โœ…  worker   UP
โœ…  pages    UP
โŒ  grafana  DOWN

๐ŸŒฟ  Freshness
Current Bun: 1.2.23
Outdated packages: 0
โœจ All dependencies fresh

๐Ÿท๏ธ  Release Status
Current tag: v3.3.0
Commits ahead: 5
Run bun run release to ship.

๐Ÿ“Š  Analytics Testing
Test files: 30
Stub available: โœ…
Coverage: Run tests for coverage
```

### ๐Ÿค– **Floor - Autonomous Operations**

<div align="center">

**Self-documenting** โ€ข **Self-healing** โ€ข **Self-deploying** โ€ข **AI-native validation**

</div>

#### **Floor Commands**

| Command | Description | Use Case |
|---------|-------------|----------|
| `bun run floor:health` | Complete health check (lint, types, tests, coverage, security) | Pre-deployment validation |
| `bun run floor:test` | 60-second smoke test (validates entire system end-to-end) | Comprehensive system validation |
| `bun run floor:test:quick` | Quick smoke test (10 seconds, skips optional checks) | Fast validation |
| `bun run floor:deploy` | Deploy with health check (circuit breaker on failure) | Safe deployment |
| `bun run floor:status` | Live system status | Real-time monitoring |
| `bun run floor:fix` | Auto-fix issues | Automated maintenance |
| `bun run floor:voice` | List MCP tools | Tool discovery |
| `bun run floor:mcp` | Start MCP server | AI assistant integration |

**Example Output:**
```
โ•”โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•—
โ•‘  ๐Ÿค– Floor Health Check               โ•‘
โ•šโ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•

โœ… Lint Check          PASS (0 errors)
โš ๏ธ  Type Check         DEGRADED (154 known issues, non-blocking)
โœ… Test Suite          PASS (441/584, 75.5% pass rate)
โœ… Coverage            PASS (81%, target: 81%)
โœ… Security Audit      PASS (99 hints, 0 errors)

๐ŸŸข Overall Health: 95% (Ready to Deploy)
```

**Floor System Features:**
- โœ… One-command health validation (`bun run floor:health`)
- โœ… 60-second smoke test proves entire system works (`bun run floor:test`)
- โœ… Circuit breaker prevents bad deployments (auto-gates on failure)
- โœ… Live status endpoint (`GET /floor/status`)
- โœ… Auto-fix common issues (`bun run floor:fix`)
- โœ… MCP server for AI assistant integration (`bun run floor:mcp`)

๐Ÿ“– **[Floor System Documentation](docs/FLOOR_SYSTEM.md)** | **[Floor Smoke Test](docs/FLOOR_SMOKE_TEST.md)** | **[Command Reference](docs/COMMAND_REFERENCE.md)**

### Live Endpoints (Auto-Deployed)

- **Worker Health**: `GET https://betting-brain-v3-prod.nolarose1968-806.workers.dev/health`
- **Metrics**: `GET https://betting-brain-v3-prod.nolarose1968-806.workers.dev/metrics` (Prometheus format)
- **Dashboards**: [HTML Dashboards](dashboards/index.html) (local) or Cloudflare Pages (deployed)
- **Grafana**: Import JSON from `monitoring/grafana/dashboard.json`

### Automation Status

- โœ… **Dashboards deploy** on every release tag
- โœ… **Dependencies updated** weekly (PR created automatically)
- โœ… **Health checked** every 6 hours (Slack alert if down)
- โœ… **Analytics stub** enforced in CI (no test drift)
- โœ… **Release automation** (bump, changelog, deploy on tag push)

### Traditional Monitoring

- **Grafana Dashboard**: Auto-provisioned at deployment (17 panels)
- **Cost Alerts**: Built-in cost cap monitoring (D1, Queues, Analytics)
- **Performance Metrics**: Edge function performance tracking
- **Error Tracking**: Comprehensive error logging

## ๐Ÿ” **Security**

<div align="center">

**Production-ready security** โ€ข **Automated enforcement** โ€ข **Zero vulnerabilities** โ€ข **Comprehensive protection**

</div>

### ๐Ÿ›ก๏ธ **Security Features**

| Feature | Status | Details | Documentation |
|---------|--------|---------|---------------|
| **ast-grep Enforcement** | โœ… Active | 20 security rules enforced in CI | [Security Patterns](.cursor/rules/security-patterns.mdc) |
| **Zero Blocking Violations** | โœ… Clean | 0 blocking violations (99 hints for optimization) | [Code Quality](.cursor/rules/quality-standards.mdc) |
| **Pinned Versions** | โœ… Secure | Bun 1.2.23, ast-grep 0.39.5 | [Dependency Management](.cursor/rules/bun-runtime.mdc) |
| **Cached Builds** | โœ… Fast | ~8s warm runs | [CI Integration](.cursor/rules/ci-integration.mdc) |
| **Rate Limiting** | โœ… Active | 10 req/s per IP | [Rate Limiting](.cursor/rules/security-patterns.mdc) |
| **Input Validation** | โœ… Enforced | Zod schemas for all inputs | [API Patterns](.cursor/rules/api-patterns.mdc) |
| **Cost Guards** | โœ… Active | Hard limits on resource usage | [Cost Optimization](.cursor/rules/cache-optimization.mdc) |
| **Circuit Breakers** | โœ… Active | Graceful degradation on failures | [Quality Standards](.cursor/rules/quality-standards.mdc) |

### โš ๏ธ **Security Notes**

| Component | Note | Recommendation |
|-----------|------|----------------|
| **Rate Limiting** | Uses in-memory storage per worker instance | For multi-instance deployments, consider Cloudflare Durable Objects |
| **Current Implementation** | Suitable for most single-region deployments | Monitor and scale as needed |

### ๐Ÿ“š **Related Documentation**

- **[Security Patterns](.cursor/rules/security-patterns.mdc)** - Complete security implementation
- **[Production Security](.cursor/rules/production-security.mdc)** - Production security patterns
- **[Quality Standards](.cursor/rules/quality-standards.mdc)** - Code quality and security standards

## ๐Ÿ“ **Project Structure**

<div align="center">

**Organized architecture** โ€ข **Clear separation of concerns** โ€ข **Scalable design** โ€ข **Maintainable codebase**

</div>

### ๐Ÿ—๏ธ **Directory Structure**

```
betting-brain-v3/
โ”œโ”€โ”€ src/                         # Source code
โ”‚   โ”œโ”€โ”€ index.ts                 # Main entry point
โ”‚   โ”œโ”€โ”€ types/                   # TypeScript definitions
โ”‚   โ”œโ”€โ”€ guards/                  # Cost-cap and rate limiting
โ”‚   โ”œโ”€โ”€ queues/                  # Queue consumers
โ”‚   โ”œโ”€โ”€ triggers/                # D1 triggers
โ”‚   โ”œโ”€โ”€ schedules/               # Cron jobs
โ”‚   โ”œโ”€โ”€ tools/                   # MCP tools (auto-generated)
โ”‚   โ”œโ”€โ”€ interceptors/            # API interception (BetTicker Sniffer)
โ”‚   โ””โ”€โ”€ utils/                   # Shared utilities
โ”œโ”€โ”€ dashboards/                  # Betting intelligence dashboards
โ”‚   โ”œโ”€โ”€ dashboard.html           # Basic monitoring
โ”‚   โ”œโ”€โ”€ dashboard-enhanced.html  # Advanced analytics
โ”‚   โ”œโ”€โ”€ dashboard-pro.html       # AI intelligence hub
โ”‚   โ””โ”€โ”€ dashboard-positions.html # Position & risk tracker
โ”œโ”€โ”€ tools/                       # HTML tools and utilities
โ”‚   โ”œโ”€โ”€ capture-live-data.html   # Data capture tool
โ”‚   โ”œโ”€โ”€ diagnostic-suite.html    # System diagnostics
โ”‚   โ””โ”€โ”€ test-*.html             # Testing utilities
โ”œโ”€โ”€ tests/                       # Comprehensive test suite
โ”‚   โ”œโ”€โ”€ unit/                    # Unit tests
โ”‚   โ”œโ”€โ”€ integration/             # Integration tests
โ”‚   โ”œโ”€โ”€ e2e/                     # End-to-end tests
โ”‚   โ”œโ”€โ”€ setup/                   # Test setup and configuration
โ”‚   โ”œโ”€โ”€ mocks/                   # Shared mocks and test data
โ”‚   โ””โ”€โ”€ utils/                   # Test utilities
โ”œโ”€โ”€ docs/                        # Documentation
โ”‚   โ”œโ”€โ”€ guides/                  # User guides
โ”‚   โ”œโ”€โ”€ dashboards/              # Dashboard documentation
โ”‚   โ”œโ”€โ”€ testing/                 # Testing documentation
โ”‚   โ””โ”€โ”€ deployment/              # Deployment documentation
โ”œโ”€โ”€ browser-extension/           # Browser extension for auto-capture
โ”œโ”€โ”€ config/                      # Configuration files
โ”œโ”€โ”€ deployment/                  # Deployment scripts and configs
โ”œโ”€โ”€ monitoring/                  # Grafana and monitoring
โ”œโ”€โ”€ migrations/                  # D1 database migrations
โ”œโ”€โ”€ scripts/                     # Build and automation scripts
โ””โ”€โ”€ .github/                     # CI/CD workflows
```

### ๐Ÿ“š **Structure Documentation**

| Directory | Purpose | Documentation |
|-----------|---------|---------------|
| **src/** | Core application code | [API Patterns](.cursor/rules/api-patterns.mdc) |
| **dashboards/** | HTML dashboards | [Dashboard Documentation](docs/DASHBOARD_DOCUMENTATION.md) |
| **tools/** | HTML tools and utilities | [Tools & Utilities](tools/README.md) |
| **tests/** | Test suite | [Testing Patterns](.cursor/rules/testing-patterns.mdc) |
| **docs/** | Documentation | [Documentation](.cursor/rules/documentation.mdc) |
| **browser-extension/** | Browser extension | [Browser Extension](.cursor/rules/browser-extension.mdc) |
| **migrations/** | Database migrations | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **scripts/** | Build and automation | [CI Integration](.cursor/rules/ci-integration.mdc) |

## ๐Ÿงช Testing

### ๐ŸŒฒ **Forest Grove Testing System**

**Integrated testing with AI-friendly output and smart caching:**

```bash
# Basic Testing
bun test                    # Run all tests
bun run test:unit          # Unit tests only
bun run test:integration   # Integration tests only
bun run test:coverage      # With coverage
bun run test:ai            # AI-friendly output

# Environment-Specific Testing
bun run test:integration:dev   # Development environment
bun run test:integration:ci    # CI environment
bun run test:integration:ai    # AI environment
bun run test:integration:pre-commit  # Pre-commit environment

# Test Management
bun run test:scope:list   # List available test scopes
bun run test:scope:dev    # Run development scope
bun run test:scope:ci     # Run CI scope
bun run test:scope:ai     # Run AI scope
```

### ๐Ÿค– **AI-Friendly Testing**

**Optimized for AI coding assistants with quiet output:**

```bash
# Dedicated AI command (recommended)
bun run test:ai

# Environment variable approach
CLAUDECODE=1 bun test
CLAUDECODE=1 bun test tests/unit
CLAUDECODE=1 bun test --coverage

# Auto-detected in AI environments
bun run ci:local    # โœ… Auto-detects Claude Code
bun run ci:bun      # โœ… Auto-detects Replit AI
```

**Benefits:**
- โœ… Shows only test failures (not passing tests)
- โœ… 90% reduction in output verbosity for AI context windows
- โœ… Preserves failure details and summaries
- โœ… Improves readability in AI-assisted development

**Environment Variables:**
- `CLAUDECODE=1` - Claude Code sessions
- `REPL_ID=1` - Replit AI environments  
- `AGENT=1` - Generic AI agent flag

### ๐Ÿ“Š **Current Test Status**

**Test Health:** โœ… **PRODUCTION READY**
- โœ… **Test Files**: 26 total (unit, integration, performance)
- โœ… **Analytics Stub**: Available for testing
- โœ… **Performance Tests**: Passing
- โœ… **AI-Friendly Output**: Working
- โœ… **Smart Caching**: Implemented
- โœ… **Environment Detection**: Auto-detects AI environments
- โœ… **Test Organization**: Categorized by type and scope

**Documentation Health:** โœ… **Excellent**
- โœ… **Core Documentation**: 100% navigable
- โœ… **Testing System**: Complete Forest Grove integration
- โœ… **Rule Versioning**: 100% standardized frontmatter
- โœ… **Code Searchability**: 40% enhanced with ast-grep patterns
- โœ… **Quality Standards**: Comprehensive enforcement
- ๐Ÿ“Š **[Frontmatter & Searchability Enhancement](docs/FRONTMATTER_SEARCHABILITY_ENHANCEMENT.md)** - Complete enhancement guide
- **[Testing System](docs/testing/INTEGRATED_TESTING_SYSTEM.md)** - Forest Grove testing documentation
- **[Cursor Rules Versioning](docs/CURSOR_RULES_VERSIONING_SUMMARY.md)** - Rule versioning summary

## ๐ŸŽฏ **Fantasy402 Integration**

<div align="center">

**Complete Fantasy402.com API integration** โ€ข **Real-time data processing** โ€ข **Browser extension interception** โ€ข **Dashboard monitoring**

</div>

### ๐Ÿš€ **Supported Operations**

| Operation | Description | Status | Documentation |
|-----------|-------------|--------|---------------|
| **getInfoPlayer** | Player information and status | โœ… Active | [Player Info](.cursor/rules/mcp-integration.mdc) |
| **getPerformancePlayer** | Player performance metrics | โœ… Active | [Performance Analytics](.cursor/rules/analytics-testing.mdc) |
| **getTransactionList** | Transaction history and summaries | โœ… Active | [Transaction Management](.cursor/rules/database-patterns.mdc) |
| **getPending** | Pending wagers and risk exposure | โœ… Active | [Risk Management](.cursor/rules/security-patterns.mdc) |
| **getReportPlayerAnalysis** | Comprehensive player analysis | โœ… Active | [Player Analytics](.cursor/rules/analytics-testing.mdc) |
| **getTransactionHistory** | Historical transaction data | โœ… Active | [Data Processing](.cursor/rules/database-patterns.mdc) |

### โœจ **Integration Features**

| Feature | Description | Benefit | Documentation |
|---------|-------------|---------|---------------|
| **๐Ÿ”„ Real-time Interception** | Browser extension captures all API calls | Zero-latency data capture | [Browser Extension](.cursor/rules/browser-extension.mdc) |
| **๐Ÿ“Š Data Processing** | Parsed and normalized data storage | Consistent data format | [Data Processing](.cursor/rules/database-patterns.mdc) |
| **๐Ÿ’พ Database Storage** | D1 tables for all operation types | Persistent data storage | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **๐Ÿ“ˆ Dashboard Integration** | Floor Control dashboard cards | Real-time monitoring | [Dashboard Documentation](docs/DASHBOARD_DOCUMENTATION.md) |
| **๐Ÿ” Analytics Engine** | Metrics tracking and monitoring | Business intelligence | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |
| **โšก KV Caching** | Fast access to recent data | Performance optimization | [Cache Optimization](.cursor/rules/cache-optimization.mdc) |

### ๐Ÿš€ **API Endpoints**

#### **Core System Endpoints**
```bash
# Health & Status
GET  /health                    # Basic health check
GET  /floor/status             # Detailed system status
GET  /api/health/dns           # DNS health check
GET  /api/health/dns/batch     # Batch DNS health check
GET  /diagnostics              # System diagnostics
GET  /system-status            # Detailed system status
GET  /logs                     # System logs

# WebSocket
WS   /ws                       # Fantasy402 WebSocket connection
```

#### **MCP & Intelligence Tools**
```bash
# MCP Protocol
POST /mcp                      # JSON-RPC 2.0 MCP server

# Intelligence Tools (via MCP)
POST /mcp -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"getBettingExposure","arguments":{"eid":"nba_123"}}}'
POST /mcp -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"getSharpScore","arguments":{"agentID":"agent_123"}}}'
POST /mcp -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"getHoldPercentage","arguments":{"sport":"nba"}}}'
POST /mcp -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"getCLV","arguments":{"agentID":"agent_123"}}}'
```

#### **Sports & Live Data**
```bash
# Live Sports Data
GET  /api/live-odds?sport=nba&market=moneyline    # Live odds aggregation
GET  /api/live-scores?sport=nba                   # Live scores
GET  /api/sports/live                             # Live sports data
GET  /api/analytics/live                          # Live analytics
GET  /api/sessions/live                           # Live session data

# Data Ingestion
POST /ingest                                     # Data ingestion (JWT required)
```

#### **Fantasy402 Integration**
```bash
# Fantasy402 Performance API
GET  /api/fantasy402/performance                 # Agent performance
GET  /api/fantasy402/sport-performance           # Sport performance
GET  /api/fantasy402/summary                     # Performance summary
GET  /api/fantasy402/config                      # Fantasy402 configuration

# Fantasy402 Mission Control
GET  /api/f402/mission-control                   # Mission control dashboard
GET  /api/f402/bets/live                         # Live bets
GET  /api/f402/agents/performance                # Agent performance
GET  /api/f402/agents/list                       # Agent list
GET  /api/f402/agents/tree                       # Agent tree structure
GET  /api/f402/agents/{agentID}                  # Agent details
GET  /api/f402/cache/metrics                     # Cache metrics
POST /api/f402/cache/warm                        # Warm cache
GET  /api/f402/customers/active                  # Active customers
GET  /api/f402/customers/staked                  # Staked totals
GET  /api/f402/transactions/latest               # Latest transactions
GET  /api/f402/graph                             # Agent graph data
```

#### **BetTicker Sniffer**
```bash
# BetTicker Interception
POST /cloud/api/Manager/getBetTicker             # Transparent proxy + KV storage

# BetTicker Analysis
GET  /interceptor/history?limit=100              # Historical responses
GET  /interceptor/response?key=raw:getBetTicker:1234567890  # Specific response
GET  /interceptor/stats                          # Response statistics
```

#### **Analytics & Monitoring**
```bash
# Database & Analytics
GET  /api/database/metrics                       # Database record counts
GET  /api/analytics/metrics                      # Analytics metrics
GET  /api/activity                               # System activity
GET  /api/player-analysis                        # Player analysis
GET  /api/transaction-history                    # Transaction history
GET  /api/new-users                              # New user metrics

# Core Intelligence APIs
GET  /api/events                                 # Active events
GET  /api/exposure                               # Betting exposure
GET  /api/sharp-customers                        # Sharp customers
GET  /api/steam-moves                            # Steam moves
GET  /api/clv                                    # Closing line value
GET  /api/hold                                   # Hold percentage
GET  /api/markets                                # Market data
GET  /api/customers                              # Customer data
GET  /api/stats                                  # System statistics
```

### ๐Ÿ“Š **Dashboard Integration**

| Component | Description | Refresh Rate | Documentation |
|-----------|-------------|--------------|---------------|
| **Floor Control Dashboard** | Individual cards for each operation | 30 seconds | [Floor Control](dashboards/floor-control.html) |
| **Real-time Updates** | Live data synchronization | 30 seconds | [Real-time Processing](.cursor/rules/cloudflare-workers.mdc) |
| **Visual Analytics** | Charts and metrics display | Real-time | [Dashboard Documentation](docs/DASHBOARD_DOCUMENTATION.md) |
| **Error Handling** | Comprehensive error reporting | Real-time | [Error Handling](.cursor/rules/api-patterns.mdc) |

### ๐Ÿ“š **Related Documentation**

- **[Fantasy402 Integration Guide](docs/FANTASY402_INTEGRATION_COMPLETE.md)** - Complete integration documentation
- **[Floor Control Cards](docs/FLOOR_CONTROL_FANTASY402_CARDS.md)** - Dashboard card specifications
- **[MCP Integration](.cursor/rules/mcp-integration.mdc)** - MCP server patterns
- **[Browser Extension](.cursor/rules/browser-extension.mdc)** - Extension development patterns

## ๐ŸŽฏ **BetTicker Sniffer**

<div align="center">

**Transparent API interceptor** โ€ข **Zero client impact** โ€ข **Historical data analysis** โ€ข **Comprehensive metadata tracking**

</div>

### ๐Ÿš€ **Sniffer Features**

| Feature | Description | Benefit | Documentation |
|---------|-------------|---------|---------------|
| **๐Ÿ”„ API Interception** | Intercepts `POST /cloud/api/Manager/getBetTicker` | Complete data capture | [API Interception](.cursor/rules/api-patterns.mdc) |
| **๐Ÿ’พ KV Storage** | Stores raw responses in KV (7-day retention) | Persistent data archive | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **โšก Zero Impact** | Zero performance impact (async storage) | No client disruption | [Performance](.cursor/rules/cloudflare-workers.mdc) |
| **๐Ÿ“Š Analysis Endpoints** | Historical data analysis endpoints | Data exploration | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |
| **๐Ÿ” Metadata Tracking** | Comprehensive metadata tracking | Full audit trail | [Quality Standards](.cursor/rules/quality-standards.mdc) |

### ๐Ÿš€ **API Endpoints**

```bash
# BetTicker Interception (Transparent Proxy)
POST /cloud/api/Manager/getBetTicker             # Intercepts and stores responses

# Analysis & Debugging
GET  /interceptor/history?limit=100              # Historical responses
GET  /interceptor/response?key=raw:getBetTicker:1234567890  # Specific response
GET  /interceptor/stats                          # Response statistics
```

### ๐Ÿš€ **Quick Access Examples**

```bash
# View recent responses
curl https://betting-brain-v3-prod.nolarose1968-806.workers.dev/interceptor/history?limit=10

# Get specific response
curl "https://betting-brain-v3-prod.nolarose1968-806.workers.dev/interceptor/response?key=raw:getBetTicker:1728300000000"

# Get response statistics
curl https://betting-brain-v3-prod.nolarose1968-806.workers.dev/interceptor/stats

# Test interception (this will be proxied and stored)
curl -X POST https://betting-brain-v3-prod.nolarose1968-806.workers.dev/cloud/api/Manager/getBetTicker \
  -H "Content-Type: application/json" \
  -d '{"test": "data"}'
```

### ๐Ÿ“Š **Data Retention**

| Data Type | Retention Period | Storage Location | Documentation |
|-----------|------------------|------------------|---------------|
| **Raw Responses** | 7 days | KV Store | [KV Storage](.cursor/rules/cloudflare-workers.mdc) |
| **Metadata** | 30 days | D1 Database | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| **Analysis Data** | 90 days | Analytics Engine | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |

### ๐Ÿ“š **Related Documentation**

- **[BetTicker Sniffer Guide](docs/BET_TICKER_SNIFFER.md)** - Complete sniffer documentation
- **[API Interception](.cursor/rules/api-patterns.mdc)** - API interception patterns
- **[Database Patterns](.cursor/rules/database-patterns.mdc)** - Data storage patterns
- **[Analytics Testing](.cursor/rules/analytics-testing.mdc)** - Analytics integration

## ๐Ÿ“ก **Complete API Reference**

<div align="center">

**50+ Production Endpoints** โ€ข **Real-time Data** โ€ข **MCP Integration** โ€ข **Fantasy402 Complete**

</div>

### ๐Ÿš€ **System Health & Monitoring**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/health` | GET | Basic health check | [Health Monitoring](.cursor/rules/cloudflare-workers.mdc) |
| `/floor/status` | GET | Detailed system status | [Floor System](.cursor/rules/99-floor.mdc) |
| `/api/health/dns` | GET | DNS health check | [Health Monitoring](.cursor/rules/cloudflare-workers.mdc) |
| `/api/health/dns/batch` | GET | Batch DNS health check | [Health Monitoring](.cursor/rules/cloudflare-workers.mdc) |
| `/diagnostics` | GET | System diagnostics | [System Diagnostics](.cursor/rules/endpoint-routing.mdc) |
| `/system-status` | GET | Detailed system status | [System Status](.cursor/rules/endpoint-routing.mdc) |
| `/logs` | GET | System logs | [Logging](.cursor/rules/quality-standards.mdc) |

### ๐Ÿค– **MCP & Intelligence Tools**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/mcp` | POST | JSON-RPC 2.0 MCP server | [MCP Integration](.cursor/rules/mcp-integration.mdc) |
| `/api/events` | GET | Active events | [API Patterns](.cursor/rules/api-patterns.mdc) |
| `/api/exposure` | GET | Betting exposure | [Risk Management](.cursor/rules/security-patterns.mdc) |
| `/api/sharp-customers` | GET | Sharp customers | [Customer Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/steam-moves` | GET | Steam moves | [Live Betting](.cursor/rules/mcp-integration.mdc) |
| `/api/clv` | GET | Closing line value | [Customer Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/hold` | GET | Hold percentage | [Financial Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/markets` | GET | Market data | [Market Analysis](.cursor/rules/database-patterns.mdc) |
| `/api/customers` | GET | Customer data | [Customer Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/stats` | GET | System statistics | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |

### ๐Ÿˆ **Sports & Live Data**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/api/live-odds` | GET | Live odds aggregation | [Sports API](.cursor/rules/mcp-integration.mdc) |
| `/api/live-scores` | GET | Live scores | [Sports API](.cursor/rules/mcp-integration.mdc) |
| `/api/sports/live` | GET | Live sports data | [Live Data](.cursor/rules/cloudflare-workers.mdc) |
| `/api/analytics/live` | GET | Live analytics | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |
| `/api/sessions/live` | GET | Live session data | [Session Management](.cursor/rules/cloudflare-workers.mdc) |
| `/ingest` | POST | Data ingestion (JWT required) | [Data Ingestion](.cursor/rules/security-patterns.mdc) |

### ๐ŸŽฏ **Fantasy402 Integration (Complete)**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/api/fantasy402/performance` | GET | Agent performance | [Fantasy402 Integration](.cursor/rules/mcp-integration.mdc) |
| `/api/fantasy402/sport-performance` | GET | Sport performance | [Performance Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/fantasy402/summary` | GET | Performance summary | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |
| `/api/fantasy402/config` | GET | Fantasy402 configuration | [Configuration](.cursor/rules/cloudflare-workers.mdc) |
| `/api/f402/mission-control` | GET | Mission control dashboard | [Mission Control](.cursor/rules/mcp-integration.mdc) |
| `/api/f402/bets/live` | GET | Live bets | [Live Betting](.cursor/rules/mcp-integration.mdc) |
| `/api/f402/agents/performance` | GET | Agent performance | [Agent Management](.cursor/rules/mcp-integration.mdc) |
| `/api/f402/agents/list` | GET | Agent list | [Agent Management](.cursor/rules/mcp-integration.mdc) |
| `/api/f402/agents/tree` | GET | Agent tree structure | [Agent Management](.cursor/rules/mcp-integration.mdc) |
| `/api/f402/agents/{agentID}` | GET | Agent details | [Agent Management](.cursor/rules/mcp-integration.mdc) |
| `/api/f402/cache/metrics` | GET | Cache metrics | [Cache Optimization](.cursor/rules/cache-optimization.mdc) |
| `/api/f402/cache/warm` | POST | Warm cache | [Cache Optimization](.cursor/rules/cache-optimization.mdc) |
| `/api/f402/customers/active` | GET | Active customers | [Customer Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/f402/customers/staked` | GET | Staked totals | [Financial Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/f402/transactions/latest` | GET | Latest transactions | [Transaction Management](.cursor/rules/database-patterns.mdc) |
| `/api/f402/graph` | GET | Agent graph data | [Data Visualization](.cursor/rules/mcp-integration.mdc) |

### ๐ŸŽฏ **BetTicker Sniffer**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/cloud/api/Manager/getBetTicker` | POST | Transparent proxy + KV storage | [API Interception](.cursor/rules/api-patterns.mdc) |
| `/interceptor/history` | GET | Historical responses | [Data Analysis](.cursor/rules/analytics-testing.mdc) |
| `/interceptor/response` | GET | Specific response | [Data Analysis](.cursor/rules/analytics-testing.mdc) |
| `/interceptor/stats` | GET | Response statistics | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |

### ๐Ÿ“Š **Analytics & Monitoring**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/api/database/metrics` | GET | Database record counts | [Database Patterns](.cursor/rules/database-patterns.mdc) |
| `/api/analytics/metrics` | GET | Analytics metrics | [Analytics Testing](.cursor/rules/analytics-testing.mdc) |
| `/api/activity` | GET | System activity | [Activity Monitoring](.cursor/rules/cloudflare-workers.mdc) |
| `/api/player-analysis` | GET | Player analysis | [Player Analytics](.cursor/rules/analytics-testing.mdc) |
| `/api/transaction-history` | GET | Transaction history | [Transaction Management](.cursor/rules/database-patterns.mdc) |
| `/api/new-users` | GET | New user metrics | [User Analytics](.cursor/rules/analytics-testing.mdc) |

### ๐Ÿ”Œ **WebSocket & Real-time**

| Endpoint | Method | Description | Documentation |
|----------|--------|-------------|---------------|
| `/ws` | WS | Fantasy402 WebSocket connection | [WebSocket](.cursor/rules/cloudflare-workers.mdc) |

## ๐Ÿ“Š Dashboards & Tools

### **๐ŸŽฏ Quick Start**
- **[๐Ÿ“Š Dashboards Hub](dashboards/index.html)** - All betting intelligence dashboards in one place
- **[๐Ÿ› ๏ธ Testing Tools Hub](tools/index.html)** - Complete diagnostic and testing suite

### **Recommended Dashboards**
- **[๐ŸŒฒ Floor Control Dashboard](dashboards/floor-control.html)** โญ - Complete system monitoring with Floor health, Forest grove status, MCP tools, live odds, scores, database metrics, Fantasy402 integration, and real-time analytics (NEW RECOMMENDED)
- **[Enhanced Analytics](dashboards/dashboard-enhanced.html)** - Charts, alerts, and deep analytics
- **[AI Intelligence Hub](dashboards/dashboard-pro.html)** - AI-powered insights with Claude integration
- **[Position & Risk Tracker](dashboards/dashboard-positions.html)** - Real-time risk analysis
- **[Basic Monitoring](dashboards/dashboard.html)** - Simple, clean monitoring interface

### **Essential Tools**
- **[System Health Monitor](tools/system-health-monitor.html)** - Real-time system diagnostics
- **[Extension Test Suite](tools/extension-test-suite.html)** - Automated extension testing
- **[Flow Tester](tools/flow-tester.html)** - End-to-end data flow validation
- **[Troubleshooting Guide](tools/troubleshooting-guide.html)** - Intelligent problem diagnosis

### **Documentation**
- **[๐Ÿ“Š Dashboard Documentation](docs/DASHBOARD_DOCUMENTATION.md)** - Complete dashboard guide and specifications ๐Ÿ†•
- **[Dashboard Collection](README.md)** - Complete dashboard overview
- **[Tools & Utilities](README.md)** - HTML tools and utilities  
- **[Testing Guide](docs/guides/TESTING_GUIDE.md)** - Extension testing and deployment
- **[Agent Risk Guide](docs/guides/AGENT_RISK_GUIDE.md)** - Risk analysis guide
- **[Start Here Guide](docs/guides/START_HERE.md)** - Complete setup guide
- **[๐Ÿ”ง Debugging Data Capture](docs/guides/DEBUGGING_DATA_CAPTURE.md)** - Fix data capture issues

## ๐Ÿ“š Additional Documentation

### Core Documentation
- **[Quick Start Guide](docs/QUICKSTART.md)** - 15-second setup
- **[Implementation Summary](docs/IMPLEMENTATION_SUMMARY.md)** - Technical overview
- **[Automation Guide](docs/AUTOMATION_GUIDE.md)** - Testing workflows

### API Documentation โœจ NEW
- **[REST API Reference](docs/REST_API_REFERENCE.md)** - Complete REST API docs (15+ endpoints) ๐Ÿ†•
- **[API Enhancement Summary](docs/API_ENHANCEMENT_SUMMARY.md)** - API layer overview & features ๐Ÿ†•
- **[MCP Integration Status](docs/MCP_INTEGRATION_STATUS.md)** - MCP server status & overview
- **[MCP Endpoints Reference](docs/MCP_ENDPOINTS.md)** - Complete API docs for 24 tools
- **[MCP Testing Guide](docs/guides/TESTING_GUIDE.md)** - Comprehensive testing procedures

### System Integration
- **[Endpoint & Dashboard Integration](docs/ENDPOINT_DASHBOARD_INTEGRATION.md)** - Complete integration guide
- **[System Integration Map](docs/SYSTEM_INTEGRATION_MAP.md)** - Visual architecture diagrams
- **[Database & Cron Verification](docs/DATABASE_CRON_VERIFICATION.md)** - System verification

### Quality & Testing
- **[Quality Standards](docs/QUALITY_STANDARDS.md)** - Code quality standards & best practices (NEW!) ๐Ÿ“
- **[Test Audit Report](docs/TEST_AUDIT_REPORT.md)** - Quality score: 100/100
- **[Error Path Testing](docs/ERROR_PATH_TESTING.md)** - Comprehensive error path test suite (299 tests, 81% coverage) ๐Ÿ†•
- **[Code Quality Audit](docs/CODE_QUALITY_AUDIT.md)** - Comprehensive review
- **[AI-Friendly Testing Guide](docs/testing/AI_FRIENDLY_TESTING.md)** - AI-optimized test patterns ๐Ÿค–
- **[BetTicker Sniffer](docs/BET_TICKER_SNIFFER.md)** - API interception & archiving

### Developer Resources

#### AI Development
- **[Cursor Rules](.cursorrules)** - AI development standards and patterns ๐Ÿค–
- **[AI-Friendly Testing](.cursor/rules/ai-friendly-testing.mdc)** - AI-optimized test patterns ๐Ÿค–
- **[Style Guide](docs/STYLE_GUIDE.md)** - Human-readable coding standards with examples ๐Ÿ“š
- **[Cursor Rules Guide](docs/CURSOR_RULES.md)** - Complete rules documentation
- **[Code Searchability](docs/QUICKSTART.md)** - ast-grep patterns for code discovery
- **[Root Structure](docs/ROOT_STRUCTURE.md)** - Root directory reference
- **[Codebase Review](docs/CODEBASE_REVIEW.md)** - Complete codebase analysis
- **[Production Patterns](docs/PRODUCTION_PATTERNS.md)** - Scale & security guide (NEW!)
- **[Production Integration](docs/PRODUCTION_INTEGRATION.md)** - MCP integration guide (NEW!)
- **[Real-Time Modules](docs/REALTIME_MODULES.md)** - WebSocket + Positions + Agents (NEW!)

## ๐Ÿ“ž Support

- **Documentation**: [Cloudflare Workers Docs](https://developers.cloudflare.com/workers/)
- **Issues**: GitHub Issues
- **Discord**: [Cloudflare Discord](https://discord.cloudflare.com/)

## ๐Ÿ“„ License

MIT License - see [LICENSE](LICENSE) file for details

---

**Built with โค๏ธ on Cloudflare Edge**