--- phase: 01-tournament-engine plan: 05 subsystem: api, database, template tags: [go, crud, blind-structure, chip-set, payout, buyin, wizard, tournament-template, chi, libsql] # Dependency graph requires: - phase: 01-tournament-engine (Plan A) provides: Project scaffold, chi router, middleware, store layer - phase: 01-tournament-engine (Plan B) provides: Database schema with all building block tables provides: - ChipSet CRUD service with denomination management - BlindStructure CRUD service with level validation - PayoutStructure CRUD service with bracket/tier nesting and 100% sum validation - BuyinConfig CRUD service with rake split validation - TournamentTemplate CRUD service with FK validation and expanded view - Structure wizard algorithm (geometric progression, denomination snapping, break insertion) - 4 built-in blind structures (Turbo, Standard, Deep Stack, WSOP-style) - Built-in payout structure with 4 entry-count brackets - 4 built-in buy-in configs with rake splits - 4 built-in tournament templates composing all above - Full REST API for all building blocks and templates affects: [tournament-lifecycle, frontend-templates, clock-engine] # Tech tracking tech-stack: added: [] patterns: - Service-per-entity CRUD pattern with *sql.DB injection - Transaction-based create/update with nested entity replacement - FK reference validation before template creation - Expanded view pattern (GetTemplate vs GetTemplateExpanded) - Seed migration with INSERT OR IGNORE for idempotent built-in data key-files: created: - internal/template/chipset.go - internal/template/payout.go - internal/template/buyin.go - internal/template/tournament.go - internal/blind/structure.go - internal/blind/wizard.go - internal/blind/templates.go - internal/server/routes/templates.go - internal/store/migrations/005_builtin_templates.sql - internal/blind/wizard_test.go - internal/template/tournament_test.go modified: - internal/server/server.go key-decisions: - "Seed data uses INSERT OR IGNORE with explicit IDs for idempotent re-runs" - "Wizard generates preview-only levels (not auto-saved) for TD review" - "BB ante used in WSOP-style template (separate from standard ante field)" - "Payout brackets must be contiguous ranges (no gaps between min/max entries)" patterns-established: - "Service CRUD pattern: NewXService(db) with Create/Get/List/Update/Delete/Duplicate" - "Nested entity pattern: replace-all on update (delete children, re-insert)" - "Route registration: Register(chi.Router) method for modular route mounting" requirements-completed: [BLIND-01, BLIND-02, BLIND-03, BLIND-04, BLIND-05, BLIND-06, CHIP-01, CHIP-02, CHIP-03, CHIP-04, FIN-01, FIN-02, FIN-05, FIN-06, FIN-10] # Metrics duration: 10min completed: 2026-03-01 --- # Plan 05: Blind Structure + Chip Sets + Templates Summary **Full CRUD for all building blocks (chip sets, blind structures, payouts, buy-ins) with 4 built-in tournament templates, structure wizard algorithm, and REST API endpoints** ## Performance - **Duration:** 10 min - **Started:** 2026-03-01T02:48:52Z - **Completed:** 2026-03-01T02:58:52Z - **Tasks:** 2 - **Files modified:** 12 ## Accomplishments - Complete CRUD services for all 5 building block types with validation, duplication, and builtin protection - Structure wizard generates blind structures from high-level inputs (player count, chips, duration, denominations) using geometric progression with denomination snapping - 4 built-in tournament templates (Turbo, Standard, Deep Stack, WSOP-style) with matching blind structures, buy-in configs, and shared payout structure - Full REST API with admin-gated mutations and floor-accessible reads - Comprehensive test suites for wizard (6 tests) and templates (7 tests), all passing ## Task Commits Each task was committed atomically: 1. **Task E1: Building block CRUD and API routes** - `99545bd` (feat) 2. **Task E2: Built-in templates, seed data, wizard tests, template tests** - `7dbb4ca` (feat) ## Files Created/Modified - `internal/template/chipset.go` - ChipSet CRUD service with denomination management - `internal/template/payout.go` - PayoutStructure CRUD with bracket/tier nesting and 100% sum validation - `internal/template/buyin.go` - BuyinConfig CRUD with rake split validation - `internal/template/tournament.go` - TournamentTemplate CRUD with FK validation, expanded view, SaveAsTemplate - `internal/blind/structure.go` - BlindStructure CRUD with level validation (contiguous positions, SB < BB) - `internal/blind/wizard.go` - Structure wizard: geometric progression, denomination snapping, break insertion, chip-up markers - `internal/blind/templates.go` - Built-in level definitions (Turbo, Standard, Deep Stack, WSOP-style) - `internal/server/routes/templates.go` - REST API handlers for all building blocks and templates - `internal/store/migrations/005_builtin_templates.sql` - Seed data for 4 blind structures, 1 payout structure, 4 buy-in configs, 4 tournament templates - `internal/blind/wizard_test.go` - Wizard tests: standard, player counts, denomination alignment, short/long, invalid inputs - `internal/template/tournament_test.go` - Template tests: create, invalid FK, expanded, save-as, duplicate, delete-builtin, list - `internal/server/server.go` - Wired template routes into protected API group ## Decisions Made - Seed data uses INSERT OR IGNORE with explicit integer IDs for idempotent migration re-runs - Wizard generates preview-only levels (not auto-saved) so the TD can review and adjust before saving - WSOP-style blind structure uses BB ante (separate field from standard ante) starting at level 4 - Payout bracket validation enforces contiguous entry count ranges with no gaps - All built-in entities use is_builtin=1 flag -- cannot be deleted but can be duplicated ## Deviations from Plan None - plan executed exactly as written. ## Issues Encountered - Pre-existing test failure in `cmd/leaf/main_test.go` (missing `clockRegistry` parameter from Plan D) -- out of scope, not caused by this plan ## User Setup Required None - no external service configuration required. ## Next Phase Readiness - All building blocks have full CRUD with API endpoints -- ready for frontend template management UI - Tournament templates compose building blocks by reference -- ready for tournament creation flow - Structure wizard is functional -- ready for frontend wizard UI - Built-in templates exist on first boot -- ready for template-first tournament creation ## Self-Check: PASSED All 11 created files verified on disk. Both task commits (99545bd, 7dbb4ca) found in git log. --- *Phase: 01-tournament-engine* *Completed: 2026-03-01*