# Data Model: Tag Browser No schema changes are required for this feature. All data needed to power the tag browser already exists. ## Derived Entity: Tag with Count The tag browser displays a **read-only, derived view** of existing data: | Field | Source | Notes | |-------|--------|-------| | `name` | `tags.name` | Lowercase, normalised string | | `image_count` | `COUNT(image_tags.image_id) WHERE image_tags.tag_id = tags.id` | Computed at query time | This is exactly the shape already returned by `GET /api/v1/tags` as `{"id", "name", "image_count"}`. ## What Changes The query in `TagRepository.list_tags()` gains two optional behaviours: 1. **Sort by count descending** — adds `ORDER BY image_count DESC, name ASC` (count-desc primary, alphabetical secondary) instead of the current `ORDER BY name ASC`. 2. **Exclude zero-count tags** — adds `HAVING image_count > 0` (or equivalent `WHERE` on the subquery) when `min_count=1` is requested. No new tables, columns, indexes, or migrations are needed.