Strat Gameplay WebApp - Web interface for Strat-o-Matic gameplay
Go to file
Cal Corum 1c32787195 CLAUDE: Refactor game models and modularize terminal client
This commit includes cleanup from model refactoring and terminal client
modularization for better code organization and maintainability.

## Game Models Refactor

**Removed RunnerState class:**
- Eliminated separate RunnerState model (was redundant)
- Replaced runners: List[RunnerState] with direct base references:
  - on_first: Optional[LineupPlayerState]
  - on_second: Optional[LineupPlayerState]
  - on_third: Optional[LineupPlayerState]
- Updated helper methods:
  - get_runner_at_base() now returns LineupPlayerState directly
  - get_all_runners() returns List[Tuple[int, LineupPlayerState]]
  - is_runner_on_X() simplified to direct None checks

**Benefits:**
- Matches database structure (plays table has on_first_id, etc.)
- Simpler state management (direct references vs list management)
- Better type safety (LineupPlayerState vs generic runner)
- Easier to work with in game engine logic

**Updated files:**
- app/models/game_models.py - Removed RunnerState, updated GameState
- app/core/play_resolver.py - Use get_all_runners() instead of state.runners
- app/core/validators.py - Updated runner access patterns
- tests/unit/models/test_game_models.py - Updated test assertions
- tests/unit/core/test_play_resolver.py - Updated test data
- tests/unit/core/test_validators.py - Updated test data

## Terminal Client Refactor

**Modularization (DRY principle):**
Created separate modules for better code organization:

1. **terminal_client/commands.py** (10,243 bytes)
   - Shared command functions for game operations
   - Used by both CLI (main.py) and REPL (repl.py)
   - Functions: submit_defensive_decision, submit_offensive_decision,
     resolve_play, quick_play_sequence
   - Single source of truth for command logic

2. **terminal_client/arg_parser.py** (7,280 bytes)
   - Centralized argument parsing and validation
   - Handles defensive/offensive decision arguments
   - Validates formats (alignment, depths, hold runners, steal attempts)

3. **terminal_client/completions.py** (10,357 bytes)
   - TAB completion support for REPL mode
   - Command completions, option completions, dynamic completions
   - Game ID completions, defensive/offensive option suggestions

4. **terminal_client/help_text.py** (10,839 bytes)
   - Centralized help text and command documentation
   - Detailed command descriptions
   - Usage examples for all commands

**Updated main modules:**
- terminal_client/main.py - Simplified by using shared commands module
- terminal_client/repl.py - Cleaner with shared functions and completions

**Benefits:**
- DRY: Behavior consistent between CLI and REPL modes
- Maintainability: Changes in one place affect both interfaces
- Testability: Can test commands module independently
- Organization: Clear separation of concerns

## Documentation

**New files:**
- app/models/visual_model_relationships.md
  - Visual documentation of model relationships
  - Helps understand data flow between models
- terminal_client/update_docs/ (6 phase documentation files)
  - Phased documentation for terminal client evolution
  - Historical context for implementation decisions

## Tests

**New test files:**
- tests/unit/terminal_client/__init__.py
- tests/unit/terminal_client/test_arg_parser.py
- tests/unit/terminal_client/test_commands.py
- tests/unit/terminal_client/test_completions.py
- tests/unit/terminal_client/test_help_text.py

**Updated tests:**
- Integration tests updated for new runner model
- Unit tests updated for model changes
- All tests passing with new structure

## Summary

-  Simplified game state model (removed RunnerState)
-  Better alignment with database structure
-  Modularized terminal client (DRY principle)
-  Shared command logic between CLI and REPL
-  Comprehensive test coverage
-  Improved documentation

Total changes: 26 files modified/created

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-28 14:16:38 -05:00
.claude CLAUDE: Implement player models and optimize database queries 2025-10-28 14:08:56 -05:00
backend CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
frontend-pd CLAUDE: Complete Phase 1 - Frontend Infrastructure Setup 2025-10-22 00:24:00 -05:00
frontend-sba SBa name update 2025-10-22 11:22:15 -05:00
.dockerignore CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
.env.example CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
.gitattributes Initial commit 2025-10-21 15:15:33 -05:00
.gitignore CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
CLAUDE.md CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
docker-compose.yml SBa name update 2025-10-22 11:22:15 -05:00
prd-web-scorecard-1.1.md CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
QUICKSTART.md CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
README.md CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00

Paper Dynasty Real-Time Game Engine

Web-based real-time multiplayer baseball simulation platform replacing the legacy Google Sheets system.

Project Structure

strat-gameplay-webapp/
├── backend/              # FastAPI game engine
├── frontend-sba/         # SBA League Nuxt frontend
├── frontend-pd/          # PD League Nuxt frontend
├── .claude/              # Claude AI implementation guides
├── docker-compose.yml    # Full stack orchestration
└── README.md            # This file

Two Development Workflows

Best for: Fast hot-reload, quick iteration, debugging

Services:

  • Backend runs locally (Python hot-reload)
  • Frontends run locally (Nuxt hot-reload)
  • Redis in Docker (lightweight)
  • PostgreSQL on your existing server

Setup:

  1. Environment Setup

    # Copy environment template
    cp .env.example .env
    # Edit .env with your database credentials and API keys
    
  2. Start Redis (in one terminal)

    cd backend
    docker-compose up
    
  3. Start Backend (in another terminal)

    cd backend
    source venv/bin/activate  # or 'venv\Scripts\activate' on Windows
    python -m app.main
    

    Backend will be available at http://localhost:8000

  4. Start SBA Frontend (in another terminal)

    cd frontend-sba
    npm run dev
    

    SBA frontend will be available at http://localhost:3000

  5. Start PD Frontend (in another terminal)

    cd frontend-pd
    npm run dev
    

    PD frontend will be available at http://localhost:3001

Advantages:

  • Instant hot-reload on code changes
  • 🐛 Easy debugging (native debuggers work)
  • 💨 Fast startup times
  • 🔧 Simple to restart individual services

Option 2: Full Docker Orchestration

Best for: Integration testing, demos, production-like environment

Services:

  • Everything runs in containers
  • Consistent environment
  • One command to start everything

Setup:

  1. Environment Setup

    # Copy environment template
    cp .env.example .env
    # Edit .env with your database credentials and API keys
    
  2. Start Everything

    # From project root
    docker-compose up
    

    Or run in background:

    docker-compose up -d
    
  3. View Logs

    # All services
    docker-compose logs -f
    
    # Specific service
    docker-compose logs -f backend
    docker-compose logs -f frontend-sba
    
  4. Stop Everything

    docker-compose down
    

Advantages:

  • 🎯 Production-like environment
  • 🚀 One-command startup
  • 🔄 Easy to share with team
  • CI/CD ready

Development Commands

Backend

cd backend

# Activate virtual environment
source venv/bin/activate

# Install dependencies
pip install -r requirements-dev.txt

# Run server
python -m app.main

# Run tests
pytest tests/ -v

# Code formatting
black app/ tests/

# Linting
flake8 app/ tests/

# Type checking
mypy app/

Frontend

cd frontend-sba  # or frontend-pd

# Install dependencies
npm install

# Run dev server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

# Lint
npm run lint

# Type check
npm run type-check

Database Setup

This project uses an existing PostgreSQL server. You need to manually create the database:

-- On your PostgreSQL server
CREATE DATABASE paperdynasty_dev;
CREATE USER paperdynasty WITH PASSWORD 'your-secure-password';
GRANT ALL PRIVILEGES ON DATABASE paperdynasty_dev TO paperdynasty;

Then update DATABASE_URL in .env:

DATABASE_URL=postgresql+asyncpg://paperdynasty:your-password@your-db-server:5432/paperdynasty_dev

Environment Variables

Copy .env.example to .env and configure:

Required

  • DATABASE_URL - PostgreSQL connection string
  • SECRET_KEY - Application secret key (at least 32 characters)
  • DISCORD_CLIENT_ID - Discord OAuth client ID
  • DISCORD_CLIENT_SECRET - Discord OAuth secret
  • SBA_API_URL / SBA_API_KEY - SBA League API credentials
  • PD_API_URL / PD_API_KEY - PD League API credentials

Optional

  • REDIS_URL - Redis connection (auto-configured in Docker)
  • CORS_ORIGINS - Allowed origins (defaults to localhost:3000,3001)

Available Services

When running, the following services are available:

Service URL Description
Backend API http://localhost:8000 FastAPI REST API
Backend Docs http://localhost:8000/docs Interactive API documentation
SBA Frontend http://localhost:3000 SBA League web app
PD Frontend http://localhost:3001 PD League web app
Redis localhost:6379 Cache (not exposed via HTTP)

Health Checks

# Backend health
curl http://localhost:8000/api/health

# Or visit in browser
open http://localhost:8000/api/health

Troubleshooting

Backend won't start

  • Check DATABASE_URL is correct in .env
  • Verify PostgreSQL database exists
  • Ensure Redis is running (docker-compose up in backend/)
  • Check logs for specific errors

Frontend won't connect to backend

  • Verify backend is running at http://localhost:8000
  • Check CORS settings in backend .env
  • Clear browser cache and cookies
  • Check browser console for errors

Docker containers won't start

  • Ensure .env file exists with all required variables
  • Run docker-compose down then docker-compose up again
  • Check docker-compose logs for specific errors
  • Verify no port conflicts (8000, 3000, 3001, 6379)

Database connection fails

  • Verify PostgreSQL server is accessible
  • Check firewall rules allow connection
  • Confirm database and user exist
  • Test connection with psql directly

Documentation

  • Full PRD: See /prd-web-scorecard-1.1.md
  • Implementation Guide: See .claude/implementation/00-index.md
  • Architecture Docs: See .claude/implementation/ directory

Tech Stack

Backend

  • Framework: FastAPI (Python 3.11+)
  • WebSocket: Socket.io
  • Database: PostgreSQL 14+ with SQLAlchemy
  • Cache: Redis 7
  • Auth: Discord OAuth with JWT

Frontend

  • Framework: Vue 3 + Nuxt 3
  • Language: TypeScript
  • Styling: Tailwind CSS
  • State: Pinia
  • WebSocket: Socket.io-client

Contributing

See .claude/implementation/ for detailed implementation guides and architecture documentation.

License

Proprietary - Paper Dynasty League System