一键导入
conventions
Quick reference for all Librariarr project conventions and patterns. Consult when writing or reviewing code to verify correct patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Quick reference for all Librariarr project conventions and patterns. Consult when writing or reviewing code to verify correct patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Launch, build, run, start, screenshot, or smoke-test the Librariarr Next.js webapp end-to-end. Use when asked to run librariarr, bring up the dev stack, take a screenshot of the dashboard or any UI page, verify a change in the running app, or check that the app boots cleanly.
Generate a new Next.js API route with project boilerplate (auth, validation, sanitize, Prisma). Use when creating new API endpoints.
Generate an integration test for an API route with all required mocks and boilerplate. Use when creating tests for API endpoints.
Create a Prisma migration file for schema changes. Required for production — db push only works in dev. Use after modifying schema.prisma.
Scaffold a complete new feature end-to-end (Prisma model, migration, schemas, API routes, tests). Use for new CRUD resources or features that span multiple layers.
Add a new Zod validation schema to src/lib/validation.ts. All schemas MUST live in this file using zod/v4. Use when creating validation for new API endpoints.
| name | conventions |
| description | Quick reference for all Librariarr project conventions and patterns. Consult when writing or reviewing code to verify correct patterns. |
| Module | Correct Import | WRONG |
|---|---|---|
| Prisma client | import { prisma } from "@/lib/db" | @/lib/prisma |
| Validation | import { validateRequest, schema } from "@/lib/validation" | Inline schemas |
| Zod | import { z } from "zod/v4" | from "zod" |
| Sanitize | import { sanitize, sanitizeErrorDetail } from "@/lib/api/sanitize" | — |
| Session | import { getSession } from "@/lib/auth/session" | — |
| Prisma types | import type { X } from "@/generated/prisma/client" | — |
Every route handler must:
getSession() + session.isLoggedInvalidateRequest(request, schema) — schema from @/lib/validationuserId: session.userId! in all queriessanitize() from @/lib/api/sanitizesanitizeErrorDetail() for error messages from external services[id]/test-connection endpointssanitize() (strips accessToken, apiKey, plexToken, passwordHash)library: { mediaServer: { userId: session.userId } } ownership checkauthRateLimiter — 10 attempts / 15 min, return 429 with Retry-AfterfindFirst with userId filter, NOT bare findUnique({ where: { id } })fileSize: stored as BigInt, serialize to string in API responsesLibraryType: "MOVIE" | "SERIES" | "MUSIC"{ params }: { params: Promise<{ id: string }> } — params is a Promise, must awaittake: limit + 1, pop last if over), response: { items, pagination: { page, limit, hasMore } }?resolution=4K|1080P)function() keyword, NOT arrow functions (Vitest 4 requirement)vi.hoisted(): required when mock variables are referenced inside vi.mock() factory functionsvi.mock() calls@/lib/db → test DB, @/lib/logger → all 3 loggers suppressed (logger, apiLogger, dbLogger)setMockSession({ userId, plexToken: "tok", isLoggedIn: true })cleanDatabase() + clearMockSession() in beforeEach, disconnectTestDb() in afterAllcallRoute(), callRouteWithParams(), expectJson<T>(response, status)className="dark" on <html>--primary, --ring, --sidebar-primarytype(scope): descriptionfeat, fix, refactor, test, docs, chore, style, perfpnpm exec eslint --quiet@commitlint/config-conventional)prisma migrate deploy only reads migration files)pnpm docker:dev:db:push (no migration files needed)0001_init, 0002_description, etc.pnpm exec prisma generate to regenerate client| Purpose | Path |
|---|---|
| Prisma singleton | src/lib/db.ts |
| All Zod schemas | src/lib/validation.ts |
| Response sanitization | src/lib/api/sanitize.ts |
| Session/auth | src/lib/auth/session.ts |
| Multi-server dedup | src/lib/dedup/server-filter.ts |
| Filter utilities | src/lib/filters/build-where.ts |
| Memory cache | src/lib/cache/memory-cache.ts |
| Rate limiter | src/lib/rate-limit/rate-limiter.ts |
| Test DB setup | tests/setup/test-db.ts |
| Test helpers/factories | tests/setup/test-helpers.ts |
| Session mocking | tests/setup/mock-session.ts |