Document badge data layer and widget usage
epic-achievement-badges-foundation-task-014 — Write developer documentation covering: the database schema for all four badge tables including column descriptions and the criteria JSON format, how to add a new badge definition with threshold criteria without code changes, how to use BadgeCardWidget with all supported props and accessibility requirements, how BadgeIconAssetManager resolves asset paths and how to add new badge icons, and the RLS policy design rationale for multi-tenant isolation. Documentation should be added as a markdown file in the project docs directory.
Acceptance Criteria
Technical Requirements
Execution Context
Tier 5 - 253 tasks
Can start after Tier 4 completes
Implementation Notes
Read the implemented source files for all dependent tasks before writing documentation to ensure accuracy. Use the exact column names from the database migration SQL. For the criteria JSON format, document both the property names and value types, and show a threshold example (e.g., {"type": "assignment_count", "threshold": 15}) and a streak example. For the RLS section, explain the multi-tenant design decision: each row is scoped to an org_id and users can only read/write their own org's badges, which is critical for the multi-organization deployment model (NHF, Blindeforbundet, HLF share infrastructure).
Keep the document concise — use tables and code blocks rather than long prose paragraphs.
Testing Requirements
Documentation quality review: (1) have a second developer follow the 'add new badge definition' guide end-to-end and verify a badge appears in the app without any code changes; (2) copy-paste the BadgeCardWidget Dart example into the project and verify it compiles; (3) follow the 'add new icon' guide and verify the icon resolves correctly at runtime. These are manual verification steps, not automated tests.
Badge criteria are stored as structured JSON in badge_definitions. If the JSON schema for criteria (threshold counts, streak lengths, training completion flags) is not well-defined upfront, the evaluation service will be built against a moving target, requiring costly migrations and refactors.
Mitigation & Contingency
Mitigation: Define and document the criteria JSON schema in a shared type file before any repository code is written. Review the schema with all three organisations' badge requirements — especially Blindeforbundet's honorar thresholds — and version the JSON schema using a 'criteria_version' field from day one.
Contingency: If the criteria schema must change after services are built, write a Supabase migration to backfill existing rows and add a migration version column. Keep the evaluation service criteria parser isolated behind an interface so only one function needs updating.
Badge icon assets may not yet exist or may fail WCAG 2.2 AA contrast validation (minimum 3:1 for graphical objects) when rendered over design-token backgrounds. Missing or non-compliant icons could block UI epic delivery for Blindeforbundet, for whom screen reader and visual accessibility is non-negotiable.
Mitigation & Contingency
Mitigation: During this epic, implement the contrast-ratio validator in badge-icon-asset-manager and run it as a Flutter test against all candidate icon assets early. Coordinate with the design team to provide WCAG-compliant SVG icons in both locked and unlocked variants before the UI epic begins.
Contingency: If assets are late or fail contrast checks, ship placeholder icons that are guaranteed compliant (solid design-token colour fills with text labels) and swap in final assets post-QA without requiring a code change.