This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
## Project Overview
Brackt.com is a fantasy sports drafting platform built with React Router 7, featuring real-time draft functionality with Socket.IO, PostgreSQL database with DrizzleORM, and Clerk authentication.
npm start # Start production server (requires build)
npm run start:production # Run migrations + start server
```
## Architecture Overview
### Server Architecture
The application uses a dual-server architecture:
1.**server.ts** - Main entry point that creates the HTTP server and initializes Socket.IO
2.**server/app.ts** - Express app with React Router request handler and database context
3.**server/socket.ts** - Socket.IO server for real-time draft updates
4.**server/timer.ts** - Draft timer system that runs every second to update active draft timers
**Important**: The timer system (`server/timer.ts`) must be started for draft functionality. It uses a dedicated database connection and setInterval to manage all active draft timers.
### Database Layer
- **Schema**: `database/schema.ts` - All Drizzle table definitions
- **Context**: Database connection provided via AsyncLocalStorage context (`database/context.ts`)
- **Models**: `app/models/` - Business logic and database queries organized by domain
- Each model exports typed functions for CRUD operations
-`.` separator for nested routes (e.g., `leagues/$leagueId.settings.tsx`)
- **Loaders/Actions**: Use React Router's loader/action pattern for data fetching and mutations
- **Components**: Organized in `app/components/` with UI components in `app/components/ui/`
### Real-time Features
Socket.IO is used for live draft updates:
1.**Join Draft**: Clients join a room for their season (`join-draft` event)
2.**Timer Updates**: Server broadcasts `timer-update` every second during active drafts
3.**Pick Made**: Broadcasts `pick-made` when a participant is drafted
4.**Autodraft**: Broadcasts `autodraft-updated` when teams enable/disable autodraft
5.**Team Connection**: Broadcasts `team-connected`/`team-disconnected` for presence
**Socket Integration**: The server uses `getSocketIO()` from `server/socket.ts` to emit events. Clients use `useSocket()` hook (if implemented) to listen for events.
## Key Domain Models
### Fantasy Draft System
1.**League** - Container for multiple seasons, has commissioners
2.**Season** - Single year/iteration of a league with specific settings