baseball-engine / backend /docs /reference /coaching_workflow_decisions.md
github-actions[bot]
Automated Deploy: 3ea2037ab7d55d5b498f7e2ea0336818fc24f725
fe40b87
|
Raw History Blame
4.99 kB

Coaching workflow: implementation decisions (lead, 2026-10-30)

The contract source is coaching_workflow_spec.md (sections 4, 5 and 6). Where it leaves a question open (Q01-Q15), we use the decisions below. Reread them before writing code.

Already built (lead-owned, do not edit; report needed changes instead)

  • Tables: every new model is in app/modules/{settings,notifications,threads,goals,assignments,arm_care,academy}/models.py, and one migration migrations/versions/20261030_9c1e5a7b3d20_coaching_workflow_and_academy.py creates them all. Existing tables changed: uploads.kind also allows audio and drill_video, drill_logs.drill_id is now 40 chars with a new assignment_id, and reviews has new voice_upload_id and voice_seconds columns.
  • app/common/academy_access.py: CurrentStaff and CurrentAdmin dependencies, Staff (team_id, role, sees_all, permissions, require(perm)), visible_players_query/visible_player_ids/can_see_player/require_player, sessions_shared(player_id), coaches_of_player(player), normalize_permissions(role, requested).
  • app/common/notify.py: notify(db, push, recipient_id, kind=, title=, body=, target=, event_key=). It inserts the notification once per (recipient, event_key) and sends the push only if the recipient's preference allows it.
  • app/common/schemas.py: MediaRef (upload_id, url, expires_at, seconds?). ReviewOut.voice_note: MediaRef | None.
  • app/core/config.py: require_analysis_consent (default False) and consent_versions (default ["1.0"]).
  • Routers are already registered in app/main.py. Each new module has a placeholder controller.py that exposes router. Replace that file but keep the router name.

Tenancy and identity (Q01/Q02)

  • An academy is an existing team. The owner (teams.coach_id) is the implicit admin with every permission and has no membership row. Other staff have an academy_memberships row with role admin, coach or assistant.
  • Players belong to the team through accounts.team_id, as before.
  • The coach id used in routes such as /academy/coaches/{id} is the account (user) id. The owner appears in coach lists with role:"admin".
  • An applicant can be a player or a coach account (dual role). Approval creates or reactivates the membership. CurrentStaff accepts any account with an active membership, and also any role=coach account (whose team_id may be None). The existing CurrentCoach (role=coach) is unchanged. Endpoints that need academy scope use CurrentStaff.
  • Only one academy context applies: the team the account owns, or else its newest active membership.
  • Visibility: an admin or sees_all member sees every player on the team. Anyone else sees coach_players rows plus players in the groups they coach. A player who sets coach_can_see_sessions=false hides their sessions, media and review access from coaches. Goals, assignments, notes and threads stay visible.
  • An inaccessible player, thread or other resource returns 404 (no existence leak). A missing capability returns 403.

Conventions

  • Request-shape validation errors are 400 VALIDATION with fields, as in the rest of the repo. Where the spec names a domain code, raise Unprocessable(code=...) (422) or Conflict(code=...) (409).
  • Pagination uses Paging plus Page[T]. The cursor encodes (created_at or updated_at, id) through encode_cursor, ordered newest first with id as the tie-breaker.
  • Idempotency-Key uses run_idempotent on the POSTs listed in spec 4.1.
  • expected_version: when it is sent and does not match, return 409 STALE_VERSION. Bump version on every change.
  • Dates: date-only fields are YYYY-MM-DD and are the client's local day. Timezones (Q06) are not modelled yet. Labels such as due are computed from the date.
  • Media always reaches the client as a presigned GET through MediaRef, never as an object key. To attach an upload, check that it is owned by the caller, has the right kind, and that storage.head(key) finds the bytes (otherwise 409 UPLOAD_NOT_READY). Then set uploads.attached_at.
  • Notifications use these kinds: review (review, coach message), drill (assignment, goal set), armcare, result, report. Use the targets from N06: {thread_id} | {session_id} | {month}.
  • Never fabricate data. When a metric has no source, return null plus unavailable_reason, or an empty list.

Domain gates (Q07/Q08/Q10)

  • Goal outcomes: a replaced goal gets outcome superseded. Nothing is evaluated automatically yet, so met stays null unless the outcome is met or not_met. Milestones are derived from met goals only, so the list is empty today.
  • Arm care: rest_status is always unknown with rule_version: null and an unavailable_reason. No thresholds.
  • Earnings: there is no revenue ledger, so every money field is null with unavailable_reason. Activity counts that come from real tables (players, sessions, reviews) are computed.