Instructions for AI coding agents (and humans) working in this repository.
PRUNplanner frontend: the web app behind prunplanner.org,
a base, empire and market planner for the game Prosperous Universe. Vue 3
(<script setup>), Vite, TypeScript, Pinia, Tailwind v4, Zod, Vitest. The
backend is a separate service; the app calls https://api.prunplanner.org
unless VITE_API_BASE_URL is set (other env vars: README.md).
Node per .nvmrc, pnpm per packageManager in package.json.
| Task | Command |
|---|---|
| Install / dev server / build | pnpm install / pnpm dev / pnpm build |
| Unit tests | pnpm test (one file: pnpm vitest run <path>) |
| Component and view tests | pnpm test:components |
| Merged coverage report | pnpm test:coverage (slow, writes coverage/lcov.info) |
| Benchmarks | pnpm vitest bench --run |
| Type check | pnpm tsc |
| Lint and format | pnpm lint / pnpm lint:fix |
| Unused exports, files, deps | pnpm knip (pnpm knip:prod: exports only tests use) |
PR CI (.github/workflows/) runs both test suites, tsc, lint and knip (also in production mode).
Run them before calling a change finished:
pnpm test && pnpm tsc && pnpm lint && pnpm knip && pnpm knip:prod
- Run
pnpm test:componentstoo when you touch a component, a view or their tests. - Run
pnpm buildwhen you touch Vite config, static asset imports, the prerender or anything else that only fails at build time (CI builds onmainonly). - Coverage:
coverage.ymlmerges both suites into one report for Codacy; the thresholds invitest.config.tsapply to that merged report. Every file insrc/andpackages/engine/src/counts. Don't exclude files to raise the number; raise the thresholds when coverage grows. .eslintrc.jsonexists only for Codacy (ESLint 8). Keep it in step witheslint.config.js.
- Import explicitly (nothing is auto-imported) and use the
@/alias forsrc/. - Use the UI kit
@/ui(src/ui/):PButton,PSelect,PDataTable, and for overlaysPModal,PDrawer,PPopover,PDropdown,useConfirm,useToast. No component libraries. The app shell and public pages (App.vue,AppProvider.vue, landing page,/market, header) import kit files by path (@/ui/components/PButton.vue) so a first visit doesn't load the whole kit. New or changed views follow Layout & hierarchy. - No hard-coded user-facing strings. Add keys only to
src/locales/en_US/<namespace>.json; help pages live insrc/assets/help/en_US/. Crowdin syncs every other locale and would overwrite edits there, so keep them out of PRs. Debug tooling (/debug,/dev/kit,features/planning/components/debug/,lib/debugMode.ts) stays English only. - Backend calls follow one chain:
call*()insrc/features/api/*.api.ts→ Zod schema insrc/features/api/schemas/(or@prunplanner/engine/schemas) → nameddefineQuery()/defineMutation()insrc/lib/query_cache/queries/*.queries.ts. Components and composables useuseQuery("Name", params).execute(), not axios orcall*(), so caching and invalidation keep working. Wrap loops of planning mutations inbatchChanges(). See data-layer.md. - Game data (materials, buildings, recipes, exchanges, planets) comes
from
src/database/services/use*Data, cached in IndexedDB and loaded by thefeatures/wrappergates. Don't fetch it again. - The plan engine is the single source of truth for production, cost
and profit numbers:
usePlanCalculationin the editor,calculatePlanwithusePlanContextin batch views. Don't duplicate the math. The engine, price book and their four wire schemas are the workspace packagepackages/engine(@prunplanner/engine,@prunplanner/engine/schemas): import only those two entries; inside the package lint allows only its own files andzod. Lint keepsproduction_chain/engine/free of Vue, Pinia,@/stores(except*.types) and@/database. See planning-engine.md. - Keep knip green: delete dead code rather than leaving it exported.
- Don't mutate shared module state (
preferenceDefaults, JSON fixtures, objects fromplanningStore.getCXor a plan query). Clone withdeepClone/inertClone(src/util/data.ts) and save through a query. - Test new logic in
src/tests/, mirroring thesrc/path; engine package logic inpackages/engine/tests/, mirroring itssrc/. See testing.md.
- Layout. Features live in
src/features/<snake_case>/: composables flat asuseX.ts(types inuseX.types.ts), Vue files incomponents/, other files as*.constants.ts,*.util.ts,*.schemas.ts. Pages are thinsrc/views/*View.vuethat gate data throughfeatures/wrapperloaders. Global stores insrc/stores/are setup-styledefineStore("prunplanner_x", () => {...}). Generic helpers insrc/util/. - Naming. Components are PascalCase with a feature prefix:
Plan*,Empire*,CX*for the commodity exchange (CX), orFIO*for the community game-data API (FIO). Frontend-only interfaces start withI; schema-derived types don't. - Composables are synchronous. Register watchers and lifecycle hooks
before any
await(Vue binds them only during synchronous setup). Put async work in returned functions or afeatures/wrapperloader. Outside setup (loops, handlers) run a composable insideeffectScope()and stop it, or call the engine directly (seeuseROIOverview). - SFCs.
<script setup lang="ts">first; imports grouped under comment headers (// Composables,// Components,// Types & Interfaces,// UI); heavy children viadefineAsyncComponent. - Formatting is Prettier (tabs, double quotes, 80 columns), checked by
pnpm lint. Prefix unused variables with_. - Comments. JSDoc with
@author, matching the density around you.
Every shape has exactly one definition.
- Boundary data (API, the market's server-sent events, FIO,
localStorage): the Zod schema is
the source of truth.
export const ThingSchema = z.object({...})withexport type Thing = z.infer<typeof ThingSchema>next to it, insrc/features/api/schemas/<domain>.schemas.ts(game, planning, empire and CX data:packages/engine/src/schemas/) or the feature's*.schemas.ts. Derive variants with.extend/.pick/.omit/.partial; usez.inputfor payloads callers build; enums arez.enum([...]). Don't annotatez.ZodType<…>: it widens the inferred type (recursive schemas are the exception, with a comment). - Frontend-only shapes are plain TypeScript in
*.types.ts, no Zod. typefor schema-derived types and unions,interfacefor object shapes,import typefor type-only imports. Keep schemas and frontend-only types in separate files, so the file says which is validated. Only the ambient files are.d.ts(skipLibCheckskips them).- Lint enforces the
ZodTypeban,interfaceandimport type. - Details: data-layer.md.
- Branch from
mainasfix/…,feat/…,chore/…,test/…ordocs/…; PRs targetmainand land as merge commits. - Conventional commits:
fix(fio): …,feat(planning): ….
Read the doc for the area you touch. Code wins when a doc disagrees; fix the doc in the same PR whenever your change moves, renames or changes something it describes.
| Doc | Read it when you… |
|---|---|
| architecture.md | need to orient: src/ layout, bootstrap, router, views |
| data-layer.md | touch the API, query cache, IndexedDB or stores |
| planning-engine.md | touch plan, empire, price or profit math |
| domain-glossary.md | meet a game term (COGC, HQ, CX, POPR, XIT, …) |
| ui-and-i18n.md | build UI or add text |
| testing.md | write or fix tests |
| analytics.md | add or change a tracked event or person property |
| seo.md | touch titles, index.html, the landing prerender or server config |
| security.md | touch help rendering, redirects, inline scripts or response headers |
| features/ | work inside a src/features/* folder |
| mcp.md | touch src/mcp/ (the Model Context Protocol server for AI assistants) or code it imports (engine, price book, planet search) |