strat-gameplay-webapp/backend
Cal Corum d1619b4a1f CLAUDE: Phase 3 - Substitution System Core Logic
Implemented comprehensive substitution system with DB-first pattern:

## Core Components (1,027 lines)

1. SubstitutionRules (345 lines)
   - Validates pinch hitter, defensive replacement, pitching change
   - Enforces no re-entry, roster eligibility, active status
   - Comprehensive error messages with error codes

2. SubstitutionManager (552 lines)
   - Orchestrates DB-first pattern: validate → DB → state
   - Handles pinch_hit, defensive_replace, change_pitcher
   - Automatic state sync and lineup cache updates

3. Database Operations (+115 lines)
   - create_substitution(): Creates sub with full metadata
   - get_eligible_substitutes(): Lists inactive players

4. Model Enhancements (+15 lines)
   - Added get_player_by_card_id() to TeamLineupState

## Key Features

-  DB-first pattern (database is source of truth)
-  Immutable lineup history (audit trail)
-  Comprehensive validation (8+ rule checks)
-  State + DB sync guaranteed
-  Error handling at every step
-  Detailed logging for debugging

## Architecture Decisions

- Position flexibility (MVP - no eligibility check)
- Batting order inheritance (pinch hitter takes spot)
- No re-entry (matches real baseball rules)
- Validation uses in-memory state (fast)

## Remaining Work

- WebSocket event handlers (2-3 hours)
- Comprehensive testing (2-3 hours)
- API documentation (1 hour)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 23:50:33 -06:00
..
.claude CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00
app CLAUDE: Phase 3 - Substitution System Core Logic 2025-11-03 23:50:33 -06:00
scripts CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00
terminal_client CLAUDE: Implement Week 7 Task 7 - WebSocket manual outcome handlers 2025-10-30 22:51:31 -05:00
tests CLAUDE: Phase 3E-Final - Redis Caching & X-Check WebSocket Integration 2025-11-03 22:46:59 -06:00
.dockerignore CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
.env.example CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
CLAUDE.md CLAUDE: Update documentation for Phase 3E-Main completion 2025-11-03 21:40:09 -06:00
clean_test_data.py CLAUDE: Refactor game models and modularize terminal client 2025-10-28 14:16:38 -05:00
docker-compose.yml CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
Dockerfile CLAUDE: Initial project setup - documentation and infrastructure 2025-10-21 16:21:13 -05:00
mypy.ini CLAUDE: Refactor GameEngine to forward-looking play tracking pattern 2025-10-25 22:18:15 -05:00
pyrightconfig.json Clean up false positive Pylance errors 2025-10-23 09:10:41 -05:00
pytest.ini CLAUDE: Complete Week 4 - State Management & Persistence 2025-10-22 12:01:03 -05:00
requirements-dev.txt CLAUDE: Complete Phase 1 backend infrastructure setup 2025-10-21 19:46:16 -05:00
requirements.txt CLAUDE: Add interactive terminal client for game engine testing 2025-10-26 12:51:01 -05:00
test_db_playground.py Add scripts to test models in dev database 2025-10-23 09:10:55 -05:00
test_pd_api_live.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
test_pd_api_mock.py CLAUDE: Phase 3E-Main - Position Ratings Integration for X-Check Resolution 2025-11-03 21:00:37 -06:00
test_redis_cache.py CLAUDE: Phase 3E-Final - Redis Caching & X-Check WebSocket Integration 2025-11-03 22:46:59 -06:00