From 4e612d9a7835225581ab34750cb34339da0c6e54 Mon Sep 17 00:00:00 2001 From: Ian Mancini Date: Sun, 21 Jun 2026 16:17:28 -0300 Subject: [PATCH 01/19] fix: chmod 600 -> 644 for exported files --- backend/handler/filesystem/base_handler.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/handler/filesystem/base_handler.py b/backend/handler/filesystem/base_handler.py index 7f3fc21ee..527d7d852 100644 --- a/backend/handler/filesystem/base_handler.py +++ b/backend/handler/filesystem/base_handler.py @@ -244,6 +244,11 @@ class FSHandler: try: yield temp_path + # mkstemp creates files with 0600; normalise to 0644 so that + # exported files (metadata.pegasus.txt, gamelist.xml, …) are + # readable by other users on a shared/mounted volume — matching + # the permissions applied to uploaded ROM files. + os.chmod(temp_path, 0o644) os.replace(str(temp_path), str(target_path)) except Exception: From 8e97a7f0643c179def503f479a1ce0c38ecec8ae Mon Sep 17 00:00:00 2001 From: Ian Mancini Date: Sun, 21 Jun 2026 16:17:56 -0300 Subject: [PATCH 02/19] fix: add shortname dictionary for pegasus export --- backend/tests/utils/test_pegasus_exporter.py | 61 ++++++- backend/utils/pegasus_exporter.py | 157 ++++++++++++++++++- 2 files changed, 213 insertions(+), 5 deletions(-) diff --git a/backend/tests/utils/test_pegasus_exporter.py b/backend/tests/utils/test_pegasus_exporter.py index 6f507628d..bf82e5b7a 100644 --- a/backend/tests/utils/test_pegasus_exporter.py +++ b/backend/tests/utils/test_pegasus_exporter.py @@ -138,7 +138,10 @@ class TestExportMetadata: exporter.export_platform_to_pegasus(platform.id, request=None) ) - assert parsed["collection"] == {"name": "SNES", "shortname": "snes"} + assert parsed["collection"] == { + "name": "Super Nintendo Entertainment System", + "shortname": "snes", + } assert len(parsed["games"]) == 1 game = parsed["games"][0] @@ -215,6 +218,62 @@ class TestExportMetadata: 99999, request=None ) + def test_collection_name_mapped_slug(self, admin_user: User): + """Known slug → canonical Pegasus name overrides RomM custom_name.""" + platform = Platform( + name="Game Boy Advance", slug="gba", fs_slug="gba", custom_name="GBA" + ) + platform = db_platform_handler.add_platform(platform) + + parsed = _parse_pegasus( + PegasusExporter(local_export=True).export_platform_to_pegasus( + platform.id, request=None + ) + ) + assert parsed["collection"] == { + "name": "Game Boy Advance", + "shortname": "gba", + } + + def test_collection_name_unmapped_slug_uses_custom_name(self, admin_user: User): + """Unknown slug → falls back to custom_name (or name) and raw slug.""" + platform = Platform( + name="My Homebrew Console", + slug="my-homebrew", + fs_slug="my-homebrew", + custom_name="Homebrew", + ) + platform = db_platform_handler.add_platform(platform) + + parsed = _parse_pegasus( + PegasusExporter(local_export=True).export_platform_to_pegasus( + platform.id, request=None + ) + ) + assert parsed["collection"] == { + "name": "Homebrew", + "shortname": "my-homebrew", + } + + def test_collection_name_unmapped_slug_no_custom_name(self, admin_user: User): + """Unknown slug, no custom_name → falls back to platform.name and raw slug.""" + platform = Platform( + name="Obscure Platform", + slug="obscure-plat", + fs_slug="obscure-plat", + ) + platform = db_platform_handler.add_platform(platform) + + parsed = _parse_pegasus( + PegasusExporter(local_export=True).export_platform_to_pegasus( + platform.id, request=None + ) + ) + assert parsed["collection"] == { + "name": "Obscure Platform", + "shortname": "obscure-plat", + } + def test_multiline_description(self, admin_user: User): platform = Platform(name="GBA", slug="gba", fs_slug="gba") platform = db_platform_handler.add_platform(platform) diff --git a/backend/utils/pegasus_exporter.py b/backend/utils/pegasus_exporter.py index 5dedc9e60..4d44dce78 100644 --- a/backend/utils/pegasus_exporter.py +++ b/backend/utils/pegasus_exporter.py @@ -9,6 +9,138 @@ from logger.logger import log from models.rom import Rom from utils.filesystem import link_or_copy_file +# Map RomM platform slugs (UPS values) to canonical Pegasus (collection name, shortname) pairs. +# Source: https://www.pegasus-frontend.org/docs/user-guide/meta-files/ +# Only platforms present in the official Pegasus "Common platform names" table are listed. +# When a platform is not in this dict the exporter falls back to the RomM platform name and slug. +SLUG_TO_PEGASUS: dict[str, tuple[str, str]] = { + # ------------------------------------------------------------------ # + # Atari + # ------------------------------------------------------------------ # + "atari2600": ("Atari 2600", "atari2600"), + "atari5200": ("Atari 5200", "atari5200"), + "atari7800": ("Atari 7800", "atari7800"), + "atari800": ("Atari 800", "atari800"), + "atari-jaguar-cd": ("Atari Jaguar CD", "atarijaguarcd"), + "jaguar": ("Atari Jaguar", "atarijaguar"), + "lynx": ("Atari Lynx", "atarilynx"), + "atari-st": ("Atari ST", "atarist"), + "atari-xegs": ("Atari XE", "atarixe"), + # ------------------------------------------------------------------ # + # Nintendo handhelds + # ------------------------------------------------------------------ # + "gb": ("Game Boy", "gb"), + "gbc": ("Game Boy Color", "gbc"), + "gba": ("Game Boy Advance", "gba"), + "nds": ("Nintendo DS", "nds"), + "3ds": ("Nintendo 3DS", "3ds"), + "g-and-w": ("Nintendo Game-and-Watch", "gameandwatch"), + "virtualboy": ("Nintendo VirtualBoy", "virtualboy"), + # ------------------------------------------------------------------ # + # Nintendo home consoles + # ------------------------------------------------------------------ # + "nes": ("Nintendo Entertainment System", "nes"), + "famicom": ("Nintendo Entertainment System", "nes"), + "fds": ("Famicom Disk System", "fds"), + "snes": ("Super Nintendo Entertainment System", "snes"), + "sfam": ("Super Nintendo Entertainment System", "snes"), + "n64": ("Nintendo 64", "n64"), + "ngc": ("Nintendo GameCube", "gc"), + "wii": ("Nintendo Wii", "wii"), + "wiiu": ("Nintendo WiiU", "wiiu"), + "switch": ("Nintendo Switch", "switch"), + # ------------------------------------------------------------------ # + # Sega + # ------------------------------------------------------------------ # + "sg1000": ("SEGA SG-1000", "sg1000"), + "sms": ("Sega Master System", "mastersystem"), + "genesis": ("Sega Genesis", "genesis"), + "segacd": ("SEGA CD", "segacd"), + "sega32": ("SEGA 32X", "sega32x"), + "segacd32": ("SEGA CD 32X", "sega32x"), + "saturn": ("Sega Saturn", "saturn"), + "dc": ("Sega Dreamcast", "dreamcast"), + "gamegear": ("SEGA GameGear", "gamegear"), + # ------------------------------------------------------------------ # + # Sony + # ------------------------------------------------------------------ # + "psx": ("PlayStation", "psx"), + "ps2": ("PlayStation 2", "ps2"), + "ps3": ("PlayStation 3", "ps3"), + "psp": ("PlayStation Portable", "psp"), + "psvita": ("PlayStation Vita", "psvita"), + # ------------------------------------------------------------------ # + # Microsoft + # ------------------------------------------------------------------ # + "xbox": ("Xbox", "xbox"), + "xbox360": ("Xbox 360", "xbox360"), + # ------------------------------------------------------------------ # + # NEC / PC Engine + # ------------------------------------------------------------------ # + "tg16": ("TurboGrafx 16", "turbografx16"), + "turbografx-cd": ("PC Engine CD", "pcengine"), + "pc-fx": ("PC-FX", "pcfx"), + # ------------------------------------------------------------------ # + # SNK Neo Geo + # ------------------------------------------------------------------ # + "neogeoaes": ("Neo Geo", "neogeo"), + "neogeomvs": ("Neo Geo", "neogeo"), + "neo-geo-cd": ("Neo Geo CD", "neogeocd"), + "neo-geo-pocket": ("Neo Geo Pocket", "ngp"), + "neo-geo-pocket-color": ("Neo Geo Pocket Color", "ngpc"), + # ------------------------------------------------------------------ # + # Commodore / Amiga + # ------------------------------------------------------------------ # + "amiga": ("Amiga", "amiga"), + "amiga-cd32": ("Amiga CD32", "amigacd32"), + "commodore-cdtv": ("Amiga CDTV", "amigacdtv"), + "c64": ("Commodore 64", "c64"), + # ------------------------------------------------------------------ # + # Amstrad / Sharp / other home computers + # ------------------------------------------------------------------ # + "acpc": ("Amstrad CPC", "amstradcpc"), + "sharp-x68000": ("Sharp X6800", "x68000"), + "msx": ("MSX", "msx"), + "dos": ("DOS", "dos"), + "pc-booter": ("PC", "pc"), + "linux": ("Linux", "linux"), + "mac": ("Macintosh", "macintosh"), + "android": ("Android", "android"), + "windows": ("Windows", "windows"), + # ------------------------------------------------------------------ # + # Arcade + # ------------------------------------------------------------------ # + "arcade": ("Arcade", "arcade"), + "naomi": ("Naomi", "naomi"), + # ------------------------------------------------------------------ # + # Other consoles / platforms + # ------------------------------------------------------------------ # + "3do": ("3DO", "3do"), + "appleii": ("Apple II", "apple2"), + "colecovision": ("ColecoVision", "colecovision"), + "intellivision": ("Intellivision", "intellivision"), + "odyssey-2": ("Odyssey 2", "odyssey2"), + "vectrex": ("Vectrex", "vectrex"), + "supergrafx": ("SuperGrafx", "supergrafx"), + "sam-coupe": ("SAM coupe", "samcoupe"), + "scummvm": ("Scumm VM", "scummvm"), + "tic-80": ("TIC80", "tic80"), + "dragon-32-slash-64": ("Dragon 32", "dragon32"), + # PC-88 / PC-98 + "pc-8800-series": ("PC 88", "pc88"), + "pc-9800-series": ("PC 98", "pc98"), + # WonderSwan + "wonderswan": ("WonderSwan", "wonderswan"), + "swancrystal": ("WonderSwan/Color", "wonderswancolor"), + # Sega Naomi / CHIP-8 + "chip-8": ("CHIP-8", "chip8"), + # ZX Spectrum / ZX81 + "zxspectrum": ("ZX Spectrum", "zxspectrum"), + "zx81": ("ZX81", "zx81"), + # Steam / GOG (non-console) + "steam": ("Steam", "steam"), +} + # Map Pegasus asset keys to subdirectory names inside assets/ ASSET_DIRS: dict[str, str] = { "box_front": "covers", @@ -31,6 +163,21 @@ class PegasusExporter: def __init__(self, local_export: bool = False): self.local_export = local_export + @staticmethod + def _resolve_collection(platform) -> tuple[str, str]: + """Return (collection_name, shortname) for a platform. + + Resolution order: + 1. SLUG_TO_PEGASUS lookup by platform.slug — gives the canonical + Pegasus name and shortname so themes can load console logos. + 2. Fall back to platform.custom_name (or platform.name) + platform.slug + for platforms not in the Pegasus reference list. + """ + mapped = SLUG_TO_PEGASUS.get(platform.slug) + if mapped: + return mapped + return (platform.custom_name or platform.name, platform.slug) + def _format_release_date(self, timestamp: int) -> str: """Format release date to YYYY-MM-DD format""" return datetime.fromtimestamp(timestamp / 1000, tz=UTC).strftime("%Y-%m-%d") @@ -211,8 +358,9 @@ class PegasusExporter: lines: list[str] = [] # Collection header - lines.append(f"collection: {platform.custom_name or platform.name}") - lines.append(f"shortname: {platform.slug}") + collection_name, shortname = self._resolve_collection(platform) + lines.append(f"collection: {collection_name}") + lines.append(f"shortname: {shortname}") lines.append("") # Game entries @@ -258,8 +406,9 @@ class PegasusExporter: lines: list[str] = [] # Collection header - lines.append(f"collection: {platform.custom_name or platform.name}") - lines.append(f"shortname: {platform.slug}") + collection_name, shortname = self._resolve_collection(platform) + lines.append(f"collection: {collection_name}") + lines.append(f"shortname: {shortname}") lines.append("") game_count = 0 From 5a9eda9eeb9b1d01a9603bda111eaf1636ed0b92 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 23 Jun 2026 01:49:08 +0000 Subject: [PATCH 03/19] docs: split v2 constitution into skills, make CLAUDE.md holistic Reorient the repo for agentic development by outside contributors. - Rewrite CLAUDE.md from a frontend-v2-only constitution into a lean, holistic guide covering both stacks, the v1/v2 split, repo-wide rules (English, AI disclosure, branch/PR flow, Trunk, verification), a skills index, and a quick command reference. - Extract the v2 constitution and add backend guidance as seven focused skills under .claude/skills/: - frontend-v2-components (tiers, file/SFC conventions, anti-patterns) - frontend-v2-theming (tokens, dual theme, zero-hex-literal policy) - frontend-v2-input (universal input + responsive viewport) - frontend-v2-patterns (errors, loading, sockets, persistence, forms, permissions, confirmations) - frontend-i18n (locale parity rule + check script) - backend-development (FastAPI/SQLAlchemy layering, scopes, migrations, OpenAPI -> frontend type pipeline, uv/pytest/trunk workflow) - pre-pr-verification (per-stack pre-PR gate mirroring CI) - Track shared skills in git while keeping personal/local Claude config ignored. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_012EigwEL43km8mskHjT6sjr --- .claude/skills/backend-development/SKILL.md | 93 ++++ .claude/skills/frontend-i18n/SKILL.md | 32 ++ .../skills/frontend-v2-components/SKILL.md | 124 +++++ .claude/skills/frontend-v2-input/SKILL.md | 60 ++ .claude/skills/frontend-v2-patterns/SKILL.md | 89 +++ .claude/skills/frontend-v2-theming/SKILL.md | 79 +++ .claude/skills/pre-pr-verification/SKILL.md | 65 +++ .gitignore | 4 +- CLAUDE.md | 518 +++--------------- 9 files changed, 610 insertions(+), 454 deletions(-) create mode 100644 .claude/skills/backend-development/SKILL.md create mode 100644 .claude/skills/frontend-i18n/SKILL.md create mode 100644 .claude/skills/frontend-v2-components/SKILL.md create mode 100644 .claude/skills/frontend-v2-input/SKILL.md create mode 100644 .claude/skills/frontend-v2-patterns/SKILL.md create mode 100644 .claude/skills/frontend-v2-theming/SKILL.md create mode 100644 .claude/skills/pre-pr-verification/SKILL.md diff --git a/.claude/skills/backend-development/SKILL.md b/.claude/skills/backend-development/SKILL.md new file mode 100644 index 000000000..decaa1945 --- /dev/null +++ b/.claude/skills/backend-development/SKILL.md @@ -0,0 +1,93 @@ +--- +name: backend-development +description: Working on the RomM Python backend (backend/) — a FastAPI app with SQLAlchemy 2.0, Alembic, RQ/Redis, and Socket.IO. Use when adding or changing API endpoints, handlers, ORM models, response schemas, metadata-provider adapters, background tasks, database migrations, or backend tests. Covers the layered architecture, conventions, auth/scopes, the OpenAPI→frontend type pipeline, and the uv/pytest/alembic/trunk workflow. Trigger on any work under backend/. +--- + +# RomM Backend — FastAPI / SQLAlchemy + +Python 3.13+, FastAPI, SQLAlchemy 2.0 (MariaDB default; MySQL/PostgreSQL supported), Alembic, Redis + RQ for jobs/cache/sessions, Socket.IO for real-time. Managed with **uv**. + +Full reference: **`docs/BACKEND_ARCHITECTURE.md`** (directory map, ER diagram, every endpoint, auth flows). Read it before non-trivial changes. + +--- + +## Layered architecture — where code goes + +``` +endpoints/ FastAPI routers: request validation, response schemas, @protected_route scopes +endpoints/responses/ Pydantic response schemas (these shape the OpenAPI → frontend types) +endpoints/sockets/ Socket.IO event handlers +handler/ Business logic, decoupled from HTTP + ├ auth/ HybridAuthBackend (session/basic/bearer/OIDC/client-token), scopes, CSRF/session middleware + ├ database/ Per-entity CRUD handlers (db_rom_handler, db_user_handler, …), engine/session factory + ├ metadata/ One handler per provider; normalizes + ranks by priority + └ filesystem/ ROM/asset/firmware file I/O, hashing, archive extraction +adapters/services/ Typed external API clients (igdb.py + igdb_types.py, screenscraper.py, …) +models/ SQLAlchemy ORM models (BaseModel adds created_at/updated_at) +tasks/ RQ jobs — scheduled/ (cron) and manual/ (on-demand); base classes in tasks.py +config/ Env-var loading (__init__.py) + YAML config manager (singleton) +decorators/ @begin_session (DB session), @protected_route (auth + scopes) +exceptions/ Custom exception hierarchy +utils/ logger/ Shared helpers, structured logging +alembic/ Migrations (env.py + versions/) +``` + +**Endpoint → handler → (database | metadata | filesystem) → models/adapters.** Endpoints stay thin: validate, enforce scopes, call handlers, serialize via a response schema. Don't put business logic or raw queries in endpoints. + +## Conventions + +- **Naming:** Classes `PascalCase`; functions/vars `snake_case`; constants `UPPER_SNAKE_CASE`; private `_prefixed`. +- **DB sessions:** decorate handler methods with `@begin_session`; it injects and manages the SQLAlchemy session/transaction. Don't open sessions ad hoc. +- **Async:** I/O-bound endpoints and tasks use `async/await`. Per-request `httpx`/`aiohttp` clients come from context vars (`utils/context.py`), not new clients per call. +- **Imports:** stdlib → third-party → local; explicit (no wildcards); `TYPE_CHECKING` blocks to break circular imports. +- **Errors:** raise the custom exceptions in `exceptions/` (e.g. `RomNotFoundInDatabaseException`), not bare `HTTPException`, where a typed one exists. +- **Validation/SSRF:** sanitize filenames/paths before filesystem use (`utils/`); paths are rooted at `LIBRARY_BASE_PATH`/`RESOURCES_BASE_PATH`/`ASSETS_BASE_PATH` from config. + +## Auth & scopes + +- Roles: `VIEWER` (read), `EDITOR` (+write roms/platforms/assets), `ADMIN` (+users/tasks/logs). Defined on `models/user.py`; scope tiers in `handler/auth/constants.py`. +- Granular scopes: `me.read/write`, `roms.read/write`, `platforms.*`, `assets.*`, `devices.*`, `firmware.*`, `collections.*`, `users.*`, `tasks.run`, `logs.read`. +- Protect routes with `@protected_route(router., "", [Scope.X])`. The frontend mirrors these scopes — keep them aligned. + +## Adding things + +- **Endpoint:** add the route in the right `endpoints/*` router, a response schema in `endpoints/responses/`, enforce scopes, delegate to a handler. If the response shape changes, the frontend must regenerate types (below). +- **Model / schema change:** edit `models/`, then create a migration (below). Update the matching response schema so OpenAPI stays accurate. +- **Metadata provider:** add a typed client in `adapters/services/.py` (+ `_types.py`) and a `handler/metadata/_handler.py` that normalizes into the common shape and slots into the priority order. +- **Background job:** subclass `Task`/`PeriodicTask` in `tasks/scheduled/` or `tasks/manual/`; register scheduled jobs in `startup.py`. + +## Database migrations (Alembic) + +Migrations must work on **MariaDB, MySQL, and PostgreSQL** (CI runs `alembic upgrade head` on Postgres and MariaDB — `.github/workflows/migrations.yml`). Use batch mode / DB-specific SQL where needed; mirror existing migrations in `alembic/versions/`. + +```bash +cd backend +uv run alembic revision --autogenerate -m "short description" # generate, then HAND-REVIEW the file +uv run alembic upgrade head # apply +uv run alembic downgrade -1 # verify the downgrade works +``` + +Always review autogenerated migrations — they miss server-default/enum/index nuances and cross-dialect differences. The `virtual_collections` DB view is excluded from migrations. + +## OpenAPI → frontend types + +FastAPI serves the schema at `GET /openapi.json`. The frontend regenerates its TypeScript types from it: + +```bash +# backend running on :3000, then in frontend/ +npm run generate # writes src/__generated__/ via openapi-typescript-codegen +``` + +**Any change to a response schema or route signature should be followed by `npm run generate` + a frontend typecheck.** + +## Run, test, lint + +```bash +cd backend +uv run python3 main.py # run (migrations auto-apply on startup) +uv run pytest [path/file] # tests (subset by path); uv run pytest -vv for all +``` + +- Tests: pytest + pytest-asyncio, isolated per `pytest-xdist` worker (per-worker DBs); `fakeredis`; `pytest-recording` VCR cassettes mock external APIs; Hypothesis for property tests. Mirror the `backend//` layout under `backend/tests/`. First-time test DB setup: `docker exec -i romm-db-dev mariadb -uroot -p < backend/romm_test/setup.sql`. +- **Lint / format / type-check run through Trunk** (ruff, black, isort, mypy, bandit): `trunk fmt && trunk check`. CI enforces Trunk on every PR. Never bypass with `--no-verify`. +- New/changed logic needs a test; new endpoints need endpoint tests. diff --git a/.claude/skills/frontend-i18n/SKILL.md b/.claude/skills/frontend-i18n/SKILL.md new file mode 100644 index 000000000..e04bbec8c --- /dev/null +++ b/.claude/skills/frontend-i18n/SKILL.md @@ -0,0 +1,32 @@ +--- +name: frontend-i18n +description: Internationalization for the RomM frontend (both v1 and v2). Use whenever adding, renaming, or removing any user-visible string / translation key under frontend/src/locales/. Covers the en_US-is-source rule, the requirement to add every new key to ALL locale directories in the same change, namespace layout, and the check_i18n_locales.py validator enforced in CI. Trigger on any change to frontend/src/locales/**. +--- + +# RomM Frontend — i18n / Localization + +User-visible strings are **never hard-coded** in components — they come from locale files via `vue-i18n` (`$t(...)` in templates/composites; utils may call `i18n.global.t(...)`; **v2 lib primitives must not call `$t` at all** — text passes via props/slots). + +## Structure + +- Locales live in `frontend/src/locales//.json`, loaded by dynamic glob import in `src/locales/index.ts`. +- **18 locales**: `en_US` (default + fallback), `en_GB`, `bg_BG`, `cs_CZ`, `de_DE`, `es_ES`, `fr_FR`, `hu_HU`, `it_IT`, `ja_JP`, `ko_KR`, `pl_PL`, `pt_BR`, `ro_RO`, `ru_RU`, `zh_CN`, `zh_TW`. +- Namespaces are per-feature files (e.g. `collection`, `common`, `console`, `detail`, `emulator`, `gallery`, `home`, `library`, `login`, `navigation`, `patcher`, `platform`, `scan`, `settings`, `task`). + +## The rule (enforced in CI) + +- **`en_US` is the source of truth**, but **every key added to `en_US` must be added to all other locale directories in the same change.** Never leave a key English-only. +- Translate where you can; otherwise copy the English value as a placeholder so the key exists. +- Removing or renaming a key means doing it across **every** locale. + +## Verify before handoff + +```bash +python3 frontend/src/locales/check_i18n_locales.py +``` + +It compares every non-English locale against `en_US` and **fails on any missing file, missing key, or extra key**. CI runs the same script (`.github/workflows/i18n.yml`) on any change under `frontend/src/locales/**`. It must pass with zero missing/extra keys. + +## Adding a new language + +Create a new folder under `frontend/src/locales/` mirroring `en_US/`'s files, then translate. Open the PR against `master` (see the docs/Contributing flow). This is the one i18n change where a new locale directory is expected. diff --git a/.claude/skills/frontend-v2-components/SKILL.md b/.claude/skills/frontend-v2-components/SKILL.md new file mode 100644 index 000000000..0f4a570b9 --- /dev/null +++ b/.claude/skills/frontend-v2-components/SKILL.md @@ -0,0 +1,124 @@ +--- +name: frontend-v2-components +description: Building or modifying components in the RomM v2 frontend (frontend/src/v2/). Use when creating/editing v2 primitives (R* components in src/v2/lib/), shared composites, or feature composites — covers the three-tier model, file/folder conventions, SFC structure, import order, barrels, Storybook requirements, and v2 anti-patterns. Trigger on any work under frontend/src/v2/. +--- + +# RomM Frontend v2 — Component Constitution + +This governs work inside `frontend/src/v2/`. **v1 is frozen** (`src/views/`, `src/components/`, `src/console/`, `src/layouts/`) — never refactor it; it will be deleted wholesale in a final wave. v2 is gated by `user.ui_settings.uiVersion`. + +> Official language for all code, comments, identifiers, `.md`, and commit/PR messages: **English**. + +Related skills: `frontend-v2-theming` (tokens/colors), `frontend-v2-input` (focus/gamepad/responsive), `frontend-v2-patterns` (errors/loading/forms/permissions/confirmations), `frontend-i18n`, `pre-pr-verification`. + +--- + +## Premises (stable) + +1. **v1 is frozen.** Don't touch `src/views/`, `src/components/`, `src/console/`, `src/layouts/`. When coexistence forces a v2 fork of a store/composable/util, annotate the v1 export with `@deprecated` pointing at the v2 replacement. +2. **Three component tiers** (below). +3. **Shared resources are canonical.** Pinia stores, API services, OpenAPI types (`src/__generated__/`), locales, utils — v2 *imports* them, never forks them. Additive changes to shared resources are allowed; changing a shared store API to work around a v2 call-site issue is not. +4. **TypeScript strict.** Zero `any` (justify with a comment if unavoidable). No `as unknown as ...`; fix the source or define an intermediate type. +5. **Universal substitution.** When an `R*` primitive exists, use it. If it doesn't, create or extend it. Never drop to raw HTML or raw Vuetify when a primitive applies. +6. **Wrapper contract.** Wrappers around Vuetify use `defineOptions({ inheritAttrs: false })` + `v-bind="$attrs"` + slot passthrough, and accept every prop/slot of the wrapped component. +7. **Layout via Vuetify utility classes + our wrappers, not plain CSS.** Use `d-flex`, `pa-4`, `align-center` directly. Vuetify layout components (`v-row`, `v-col`, `v-container`, `v-spacer`, `v-app`, `v-main`) get wrapped as `R*` on first use (lazy). +8. **Accessibility & performance** are requirements: semantic HTML, focus management, contrast, ARIA on icon-only controls; lazy-load heavy views, virtualize large lists, stable `:key` on every `v-for`. + +--- + +## The three tiers + +| Tier | Path | Prefix | Stores/services/router/emitter/i18n | Story | Domain knowledge | +| --------------------- | ------------------------------ | -------------- | ----------------------------------- | --------- | --------------------------------- | +| **Primitive** | `src/v2/lib/` | `R*` mandatory | **No** | Mandatory | None | +| **Shared composite** | `src/v2/components/shared/` | no prefix | Yes | Optional | Cross-feature, no specific domain | +| **Feature composite** | `src/v2/components//` | no prefix | Yes | Optional | Feature-specific | + +### A component is a primitive only if all three hold + +1. Does not depend on stores, services, router, or emitter. +2. No knowledge of a product domain (ROM, Platform, Collection, User…). `RAvatar` yes, `UserAvatar` no. +3. Its API can be described without naming features — generic props/slots/events. + +If any fails: **shared composite** if generic across features, **feature composite** if owned by one feature. Edge cases get raised to the user, not auto-decided. Consumer count never demotes a primitive. + +### Primitive boundaries + +- **Can use**: tokens, other primitives, Vue/Vuetify, generic composables (`useInput*`, `useFocus*`). +- **Cannot use**: Pinia stores, API services, `emitter`, `router` (a `RouterLink` may be accepted as a prop), `i18n` directly. **No `$t()` in primitives** — text comes via props or slots. + +--- + +## File & folder conventions + +- **Primitive**: one per folder — `RFoo/RFoo.vue`, `RFoo/RFoo.stories.ts`, `RFoo/index.ts`, optional `RFoo/types.ts`. +- **Composite**: flat `.vue` if one file suffices; a folder with the same internal structure (no story required) if it has sub-pieces. +- **Barrel**: `src/v2/lib/index.ts` re-exports every primitive — update it when a new primitive ships. Composites are imported directly by path; no barrel. No single-file `index.ts` that just re-exports to shorten a path. + +### SFC structure + +- `