Files
h2h-prototype/README.md
William D. Jones 93fb46f19b Fix critical errors: infinite loop, database schema, and add comprehensive E2E tests
## Critical Fixes:

1. **Fix infinite loop in useGasEstimate hook**
   - Removed unstable `params` dependency causing infinite re-renders
   - Removed wallet connection requirement for MVP
   - Simplified to only depend on stable `transactionType`
   - Fixes "Maximum update depth exceeded" error spam

2. **Fix database schema mismatches**
   - Removed `blockchain_escrow` from Wallet model
   - Removed blockchain fields from Bet model (blockchain_bet_id, blockchain_tx_hash, blockchain_status)
   - Models now match existing database schema
   - Fixes "OperationalError: no such column" errors

3. **Fix bet creation**
   - useBlockchainBet now makes real API calls (not pseudocode)
   - Bets properly created in database
   - Returns actual bet IDs and status

## Testing:

- Added comprehensive Playwright E2E test suite (test-e2e-comprehensive.js)
- Tests all critical flows: login, marketplace, wallet, create bet, my bets, navigation
- Captures all console errors and warnings
- Result:  0 errors (was 500+)

## Development:

- Added docker-compose.dev.yml for local development with hot-reload
- Added dev.sh quick-start script
- Added LOCAL_DEVELOPMENT.md comprehensive guide
- Updated vite.config.ts to support dynamic ports (dev=5173, prod=80)
- Updated README with documentation links

## Files Changed:

Backend:
- backend/app/models/wallet.py - Remove blockchain_escrow field
- backend/app/models/bet.py - Remove blockchain fields

Frontend:
- frontend/src/blockchain/hooks/useGasEstimate.ts - Fix infinite loop
- frontend/src/blockchain/hooks/useBlockchainBet.ts - Add real API calls
- frontend/vite.config.ts - Dynamic port support

Docs/Scripts:
- FIXES_APPLIED.md - Detailed fix documentation
- LOCAL_DEVELOPMENT.md - Local dev guide
- docker-compose.dev.yml - Dev environment config
- dev.sh - Quick start script
- test-e2e-comprehensive.js - E2E test suite

🚀 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-02 15:22:57 -06:00

208 lines
5.0 KiB
Markdown

# H2H - Peer-to-Peer Betting Platform MVP
A functional prototype of a peer-to-peer betting platform where users can create, accept, and settle wagers directly with other users.
## Tech Stack
- **Backend**: FastAPI (Python 3.11+) with async SQLAlchemy ORM
- **Database**: SQLite (via aiosqlite) - designed for easy migration to PostgreSQL
- **Frontend**: React 18+ with Vite, TypeScript, TailwindCSS
- **Authentication**: JWT tokens with refresh mechanism
- **Real-time**: WebSockets for live updates
- **State Management**: Zustand for client state, React Query for server state
## Features
- User registration and JWT-based authentication
- Virtual wallet with simulated deposits
- Create custom bets with categories, odds, and stakes
- Browse bet marketplace with filtering
- Accept bets with automatic escrow
- Settle bets with winner/loser confirmation
- Transaction history
- Real-time WebSocket updates
- Responsive UI
## Quick Start
### Local Development
```bash
# One-command start (recommended)
./dev.sh
# Or manually:
docker compose -f docker-compose.dev.yml up --build
# The application will be available at:
# - Frontend: http://localhost:5173
# - Backend API: http://localhost:8000
# - API Docs: http://localhost:8000/docs
```
## Manual Setup
### Backend
```bash
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Create .env file
cp .env.example .env
# Initialize database and seed data
python seed_data.py
# Run development server
uvicorn app.main:app --reload
```
### Frontend
```bash
cd frontend
# Install dependencies
npm install
# Create .env file
cp .env.example .env
# Run development server
npm run dev
```
## Test Users
After running `seed_data.py`, you can login with:
- **Email**: alice@example.com | **Password**: password123
- **Email**: bob@example.com | **Password**: password123
- **Email**: charlie@example.com | **Password**: password123
Each user starts with $1000 balance.
## Documentation
- **[Local Development Guide](LOCAL_DEVELOPMENT.md)** - Detailed guide for local development, debugging, and troubleshooting
- **[Coolify Deployment Guide](COOLIFY_DEPLOYMENT.md)** - Production deployment instructions
- **[Docker Testing Guide](DOCKER_TESTING_GUIDE.md)** - Testing Docker deployments
## API Documentation
Once the backend is running, visit:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
## Project Structure
```
h2h-prototype/
├── backend/
│ ├── app/
│ │ ├── models/ # SQLAlchemy models
│ │ ├── schemas/ # Pydantic schemas
│ │ ├── routers/ # API endpoints
│ │ ├── services/ # Business logic
│ │ ├── crud/ # Database operations
│ │ ├── utils/ # Security, exceptions
│ │ ├── config.py # Configuration
│ │ ├── database.py # Database setup
│ │ └── main.py # FastAPI app
│ ├── data/ # SQLite database
│ ├── seed_data.py # Test data script
│ └── requirements.txt
├── frontend/
│ ├── src/
│ │ ├── api/ # API client
│ │ ├── components/ # React components
│ │ ├── pages/ # Page components
│ │ ├── store/ # Zustand store
│ │ ├── types/ # TypeScript types
│ │ ├── utils/ # Utilities
│ │ ├── App.tsx # Main app
│ │ └── main.tsx # Entry point
│ ├── package.json
│ └── vite.config.ts
└── docker-compose.yml
```
## Core Workflows
### 1. Create a Bet
- User creates bet with stake, odds, and positions
- No funds are locked until bet is accepted
- Bet appears in marketplace
### 2. Accept a Bet
- Opponent accepts bet
- Funds from both parties locked in escrow
- Bet status changes to "matched"
### 3. Settle a Bet
- Either participant can declare winner
- Winner receives both stakes
- Funds released from escrow
- User stats updated
## Migration to PostgreSQL
To migrate from SQLite to PostgreSQL:
1. Update `DATABASE_URL` in backend `.env`:
```
DATABASE_URL=postgresql+asyncpg://user:pass@host:5432/h2h
```
2. Update `requirements.txt`:
- Remove: `aiosqlite`
- Add: `asyncpg`
3. Run migrations (SQLAlchemy handles the rest)
## Development
### Backend Testing
```bash
cd backend
pytest
```
### Frontend Build
```bash
cd frontend
npm run build
```
## MVP Scope
**In Scope**:
- User auth with JWT
- Virtual wallet with simulated deposits
- Bet creation, acceptance, and settlement
- Basic escrow mechanism
- WebSocket real-time updates
- Responsive UI
**Out of Scope** (Future Enhancements):
- Real payment processing
- KYC/AML verification
- Blockchain integration
- Automated odds feeds
- Admin panel
- Email notifications
- Social features
## License
MIT