## Player Model Migration - Migrate Player model from Discord app following Model/Service Architecture pattern - Extract all business logic from Player model to PlayerService - Create pure data model with PostgreSQL relationships (Cardset, PositionRating) - Implement comprehensive PlayerFactory with specialized methods for test data ## PlayerService Implementation - Extract 5 business logic methods from original Player model: - get_batter_card_url() - batting card URL retrieval - get_pitcher_card_url() - pitching card URL retrieval - generate_name_card_link() - markdown link generation - get_formatted_name_with_description() - name formatting - get_player_description() - description from object or dict - Follow BaseService pattern with dependency injection and logging ## Comprehensive Testing - 35 passing Player tests (14 model + 21 service tests) - PlayerFactory with specialized methods (batting/pitching cards, positions) - Test isolation following factory pattern and db_session guidelines - Fix PostgreSQL integer overflow in test ID generation ## Integration Test Infrastructure - Create integration test framework for improving service coverage - Design AIService integration tests targeting uncovered branches - Demonstrate real database query testing with proper isolation - Establish patterns for testing complex game scenarios ## Service Coverage Analysis - Current service coverage: 61% overall - PlayerService: 100% coverage (excellent migration example) - AIService: 60% coverage (improvement opportunities identified) - Integration test strategy designed to achieve 90%+ coverage ## Database Integration - Update Cardset model to include players relationship - Update PositionRating model with proper Player foreign key - Maintain all existing relationships and constraints - Demonstrate data isolation and automatic cleanup in tests ## Test Suite Status - 137 tests passing, 0 failures (maintained 100% pass rate) - Added 35 new tests while preserving all existing functionality - Integration test infrastructure ready for coverage improvements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| config | ||
| engine | ||
| models | ||
| repositories | ||
| routers | ||
| services | ||
| templates | ||
| __init__.py | ||
| main.py | ||
| README.md | ||
App Directory
This directory contains the main application code for the Paper Dynasty web app, following the Model/Service Architecture pattern.
Architecture Overview
The app follows a clean separation of concerns:
- Models (
models/) - Pure data models using SQLModel - Services (
services/) - Business logic layer with dependency injection - Controllers (
routers/) - Thin FastAPI route handlers - Engine (
engine/) - Stateless game simulation functions - Configuration (
config/) - Application settings and constants
Key Files
main.py- FastAPI application setup and configuration- Entry point for the web application
Directory Structure
app/
├── main.py # FastAPI application setup
├── config/ # Configuration and constants
├── models/ # SQLModel data models
├── services/ # Business logic layer (⭐ Core of architecture)
├── repositories/ # Optional data access layer
├── routers/ # FastAPI route handlers
├── engine/ # Stateless game simulation
├── static/ # Static web assets
└── templates/ # Jinja2 HTML templates
Service-First Development
When adding new features:
- Start with services - implement business logic in the service layer
- Test services independently - unit test with mocked dependencies
- Create thin routes - delegate to services via dependency injection
- Keep engine stateless - pure functions for game calculations
Migration Context
This application is migrated from a Discord bot (../discord-app/) with the goal of extracting Discord-specific business logic into clean, testable services that can support multiple interfaces (web, API, mobile, etc.).
Current Migration Status
Phase 1: Foundation Data Models - ✅ COMPLETE
- ✅
ManagerAi- AI configuration (→ AIService with 9 methods) - ✅
Cardset- Card set metadata (pure data, no extraction needed)
Phase 2: Player and Card Data - 🚧 NEXT
- 📋
Team- Team identity data (→ UIService for embed property) - 📋
Player- Player metadata (→ UIService for Discord markdown)
Testing Infrastructure - ✅ COMPLETE
- ✅ Transaction rollback pattern for test isolation
- ✅ Factory pattern for unique test data generation
- ✅ Comprehensive test coverage (23 tests passing)
See .claude/model-migration-plan.md for detailed migration tracking.