# EventheOdds Demo Prep Briefing
**Date:** January 30, 2026
**Demo:** Tomorrow (January 31, 2026) - 5 Testers
**System:** AI Sports Guru Chat + Sports Analytics Platform

---

## SYSTEM OVERVIEW

EventheOdds.ai is a sports prediction/analytics platform with:
- **AI Sports Guru**: Chat interface powered by Grok (x.ai) that answers sports questions
- **SportsDB**: PostgreSQL database with 121 tables, ~8.5M rows of sports data
- **BallDontLie API**: External API for live NBA/NFL/NHL/MLB data
- **Next.js 15**: Frontend + API routes
- **PM2**: Process manager running `eventheodds-web`

---

## CURRENT STATUS

### What's Working
- Homepage, Login, Dashboard pages load
- Health check: `/api/health` returns healthy
- Analytics APIs: `/api/analytics/*` working
- Player data is current (recent trades reflected)
- 25 NBA games in database for today
- Injury data with severity scores
- Chat token limit increased to 2000

### What Was Fixed Today
1. **Stale player data** - Players showing wrong teams (Randle was Knicks, now MIN)
2. **Hardcoded years** - Changed "2025-26" to dynamic `getCurrentSeason()`
3. **Cache durations** - Reduced from days to hours
4. **Missing team data** - Backfilled 112 NBA, 134 NFL, 73 NHL injuries
5. **Chat token limit** - Increased from 900 to 2000

---

## REMAINING ISSUES TO FIX

### Priority 1: Critical for Demo

1. **Chat API requires authentication**
   - File: `/src/app/api/chat/route.ts`
   - Issue: Returns "No authentication token provided"
   - Need: Either add test user accounts OR allow unauthenticated demo mode

2. **Server Action errors in browser console**
   - Cause: Browsers have cached old JavaScript after rebuild
   - Fix: Testers must hard-refresh (Ctrl+Shift+R)
   - Or: Add cache-busting headers

3. **Duplicate game records**
   - 96 NHL games, 64 NBA games stored twice
   - Same game with "ATL" and "Atlanta Hawks"
   - Causes duplicate entries in standings/analytics

### Priority 2: Data Quality

4. **148 NFL injuries still missing team assignments**
   - These players aren't in CanonicalPlayer table
   - Need to either add them or pull team from injury source

5. **55 MLB injuries missing teams**
   - Same issue as NFL

6. **NHL canonical player coverage only 21%**
   - Most NHL players don't have team assignments in CanonicalPlayer

---

## KEY FILES

| File | Purpose |
|------|---------|
| `/src/lib/chat.ts` | Core AI chat logic (~6500 lines) |
| `/src/lib/sportsDb.ts` | Sports database access layer |
| `/src/services/BallDontLieService.ts` | External API client with caching |
| `/src/lib/seasons.ts` | Season calculation utilities |
| `/prisma_sports/schema.prisma` | Sports database schema |
| `/config/crontab.txt` | Automated sync schedules |
| `/scripts/cron-clear-stale-cache.sh` | Cache cleanup script |

---

## DATABASE SCHEMA (Key Tables)

```
Player (45,955 rows)
  - id, league, name, team, position, externalPlayerId

CanonicalPlayer (21,531 rows)
  - id, league, fullName, teamId, sgoId, bdlId, espnId

CanonicalTeam (124 rows)
  - id, league, abbr, fullName, city

SportsGame (182,831 rows)
  - homeTeam, awayTeam, gameDate, league, homeScore, awayScore

PlayerInjury (2,528 rows)
  - playerName, team, league, status, injuryType, description

PlayerPropLine (199,705 rows)
  - playerExternalId, market, lineValue, overOdds, underOdds
```

---

## COMMANDS FOR TESTING

```bash
# Check health
curl http://localhost:3000/api/health

# Check NBA games today
curl "http://localhost:3000/api/analytics/nba-teams"

# Check injuries
curl "http://localhost:3000/api/analytics/injury-severity?league=nba"

# Restart app
cd /var/www/html/eventheodds && pm2 restart eventheodds-web

# Rebuild app
cd /var/www/html/eventheodds && npm run build

# Check logs
pm2 logs eventheodds-web --lines 50
```

---

## WHAT WE NEED HELP WITH

1. **Fix chat API for demo** - Either:
   - Create test user accounts for testers
   - Add a demo mode that bypasses auth
   - Add an internal API key for testing

2. **Deduplicate games** - Write a script to:
   - Find games with same date + teams (one with abbr, one with full name)
   - Keep the one with more data, delete the duplicate
   - Update any foreign key references

3. **Backfill remaining injury teams** - For NFL/MLB:
   - Try fuzzy matching player names
   - Or fetch team from injury source data

4. **Add cache-control headers** - Prevent stale JS issues:
   - Add `Cache-Control: no-cache` to HTML responses
   - Or add version query param to JS bundles

---

## ENVIRONMENT

- **Server**: Linux (Ubuntu)
- **Node**: v20.19.6
- **Database**: PostgreSQL (remote)
- **Framework**: Next.js 15 with Turbopack
- **Process Manager**: PM2
- **Working Dir**: `/var/www/html/eventheodds`

---

## TESTER WORKFLOW (What They'll Do)

1. Go to https://eventheodds.ai
2. Log in (need accounts)
3. Open AI Sports Guru chat
4. Ask questions like:
   - "What NBA games are on tonight?"
   - "Is LeBron James playing today?"
   - "What are the injury reports for the Lakers?"
   - "Who is Julius Randle playing for?" (should say MIN)
   - "Show me the standings for NBA"

---

## SUCCESS CRITERIA

- Chat responds accurately to sports questions
- Player teams are correct (no stale data)
- Current season is detected dynamically
- No "2025-26" hardcoded - uses current season
- Responses are detailed (up to 2000 tokens)
- No visible errors in UI

---

*Generated: 2026-01-30 07:30 UTC*
