docs: Add subdirectory CLAUDE.md files for routers, stratplay, and services

Provide targeted context for each app subdirectory so Claude Code
understands local patterns without relying on the root CLAUDE.md.
Also simplifies root CLAUDE.md dev/prod environment sections.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2026-02-17 15:22:33 -06:00
parent 2eab484ffb
commit bcdde572e8
3 changed files with 67 additions and 0 deletions

26
app/routers_v3/CLAUDE.md Normal file
View File

@ -0,0 +1,26 @@
# Routers (v3)
Domain-based FastAPI routers under `/api/v3/` prefix. Each file = one resource.
## Patterns
- Every endpoint uses `@handle_db_errors` decorator (from `dependencies.py`)
- GET endpoints use `@cache_result(ttl=N, key_prefix="name")` for Redis caching
- Auth: `token: str = Depends(oauth2_scheme)` + `valid_token(token)` check on mutating endpoints
- Pydantic models for POST/PATCH bodies are defined inline in router files (not db_engine)
- POST models: `id` fields must be `Optional[int] = None` (DB auto-generates)
## Two Styles Coexist
- **Refactored** (players, teams): Thin HTTP layer → delegates to `services/` layer
- **Legacy** (most others): Business logic directly in router, imports models from `db_engine`
## Adding a New Router
1. Create `app/routers_v3/newrouter.py` with `router = APIRouter(prefix="/api/v3/name", tags=["name"])`
2. Import and register in `app/main.py`: `from .routers_v3 import newrouter` + `app.include_router(newrouter.router)`
## IMPORTANT
- PATCH endpoints: build update dict explicitly from parameters. Never use `locals()`.
- `stratplay/` is a sub-package with its own `__init__.py` and sub-routers (batting, pitching, fielding, plays, crud)

View File

@ -0,0 +1,24 @@
# Stratplay Router (sub-package)
Play-by-play data for Strat-o-Matic games. Mounted at `/api/v3/plays`.
## Structure
| File | Purpose |
|------|---------|
| `__init__.py` | Assembles sub-routers into parent `router` |
| `common.py` | Shared `build_season_games()` filter builder |
| `models.py` | Pydantic models (`PlayModel`, `POS_LIST` literal) |
| `plays.py` | General play queries |
| `batting.py` | Batting stats aggregated from plays |
| `pitching.py` | Pitching stats aggregated from plays |
| `fielding.py` | Fielding stats aggregated from plays |
| `crud.py` | POST/PATCH/DELETE operations (auth required) |
## Key Patterns
- All stat endpoints use `build_season_games()` from `common.py` for consistent filtering
- Filter params: `season`, `week`, `s_type` (regular/post), `week_start`/`week_end`, `manager_id`
- `week` and `s_type` are mutually exclusive; `week` and `week_start`/`week_end` are mutually exclusive
- Stats aggregate from `StratPlay` joined to `StratGame` via `game_id`
- CRUD writes trigger `update_season_batting_stats()` / `update_season_pitching_stats()` from `dependencies.py`

17
app/services/CLAUDE.md Normal file
View File

@ -0,0 +1,17 @@
# Services Layer
Business logic extracted from routers for testability. Uses dependency injection.
## Architecture
- `interfaces.py` — Protocol classes (`AbstractPlayerRepository`, `AbstractTeamRepository`, `AbstractCacheService`)
- `base.py``BaseService` with lazy-loaded default repos (imports from `db_engine` on first access)
- `mocks.py` — Mock implementations for testing without DB/Redis
- `player_service.py`, `team_service.py` — Domain services (class methods, no instance needed for reads)
## Key Patterns
- Services use `@staticmethod`/`@classmethod` for read operations (no instantiation needed)
- Default repos are created lazily inside `@property` methods to avoid circular imports with `db_engine`
- For testing: pass mock repos via `ServiceConfig` or constructor kwargs
- Only `players` and `teams` routers currently use the service layer; others call `db_engine` directly