shipwide_api. It reads
every account’s data and every support thread, so serve it separately from the app and put
it behind a network gate (Cloudflare Access, IP allowlist). Single-app: no product registry or
multi-app machinery — the surface is what a single-app operator needs (accounts, sessions,
support tickets, uploads, push, audit, ops).
Screens
Twelve screens, all in the side navigation or one click from it:Design & i18n
- Design system is the Shipwide site’s — same tokens/buttons/badges/
<dialog>/header/footer, plus anAdminmark beside the brand so it’s never mistaken for the public site. - Multilingual (en + ru to start). Language + theme switch from the header and sign-in screen, both remembered; dates and relative times follow the chosen language.
- The language picker scales to dozens of languages — endonyms, a filter box once there are more than eight, and a list that scrolls.
- Add a language by dropping
<code>.jsonintosrc/i18n/locales/+ one line insrc/i18n/locales.ts(rtl: truefor RTL). The i18n machinery carries no product text, so a new language is just JSON. - Bundles load on demand — only English (the fallback) is in the main chunk; every other
language loads as a separate chunk (
import.meta.glob+setLocaleMessage). - RTL wired — a
rtlflag drivesdir; CSS uses flexbox + logical flow.
Quick start
VITE_* at build time → switch to prod before building. The API must allow
this origin: ADMIN_URL in the API env is added to CORS, so ADMIN_URL and the port here must
agree.
Scripts: switch_to_dev|prod · serve (Vite :5176, strictPort) · fix (Prettier +
eslint --fix) · build (the quality gate: Prettier check + ESLint + vue-tsc + tests → dist/) ·
setup-https (HTTPS in dev) · license-check (production-dependency
licences) · re-install-deps (clean reinstall).
Tests: *.test.ts next to the code — unit tests for the API client, token refresh, encrypted
storage, i18n and stores, and component tests that mount every screen with the network mocked
(Vitest + @vue/test-utils in happy-dom; shared helpers in src/test/). build measures coverage
and fails below 80% overall, 90% for config, core, i18n, modules, router and stores, or 80%
for any single file.
One file on its own: npx vitest run <file> --coverage.enabled=false.
Signing in
The sign-in screen offers only whatGET /v1/admin/auth/methods reports:
- Root credentials —
ADMIN_LOGIN+ADMIN_PASSWORD(API env). Independent of mail — works when everything else is broken. The password can be plaintext or ascrypt$…hash (npm run admin:password -- 'pw'in the API prints one). Per-login lockout plus a per-IP rate limit; leave both vars empty to switch this route off. - Emailed one-time code — staff-only passwordless route at
/v1/admin/auth/code. The first admin comes fromADMIN_EMAILS: a listed address is made admin (or created) when it signs in.
Security model (API side)
- Short-lived sessions — both routes land on an admin session (
client_id: admin): 15-minute access and 12-hour refresh by default (ADMIN_ACCESS_LIFETIME_MINUTES/ADMIN_REFRESH_LIFETIME_HOURSin the API env). - TOTP is offered, never forced — standard RFC 6238 codes, implemented on
node:crypto. Once enrolled on an account (on Your account), every sign-in demands it. The secret is encrypted at rest (AES-256-GCM underDATA_ENCRYPTION_KEY) and bound to its own account row, so it can’t be moved to another one. Recovery codes are stored hashed, so they still work if that key is ever lost — a TOTP check without the key answers503 mfa_key_unavailable. - Roles are
userandadmin.requireRolereads the role fresh from the database on every request, so a demotion takes effect on the next call. - Every change is audited — each mutating admin action is written to the
admin_audittable, shown on the Audit screen. Reads aren’t recorded.
Architecture
core/ never names the product — it keeps the reusable half free of assumptions about which
API it administers or what the product is called, so you rebrand by editing .env, not code.
Anything that would be a hardcoded string lives in src/config/.Pieces that are easy to get wrong
- One axios instance, not a factory. Refresh goes through
core/auth/refreshCoordinator.ts: one rotation at a time per tab and across tabs (a Web Lock), a pair another tab already rotated is adopted instead of spending a stale token, and only a refusal (400/401/403) signs the operator out — once, with one “session expired” notice, however many requests were waiting. A refusal signs out that tab only (auth.dropRefusedSession(), memory only): the stored session may be a newer one another tab signed in with, so only an explicit sign-out wipes storage. The API revokes the whole session when one refresh token is presented twice (outside its 2-minute grace window for lost responses). - Sessions are DPoP-bound (
core/auth/dpop.ts): every request, sign-in included, carries a proof signed by a non-exportable key in the browser, shared by its tabs; sign-out forgets the key its session was bound to, never one another tab has signed in with since. Token expiry is judged by the server’s clock (core/auth/serverClock.ts, from theDateheader). - Refresh happens before expiry, not only on a 401 — admin sessions are short and the panel sits open between bursts.
- Tokens in an encrypted IndexedDB store (non-exportable
CryptoKey+ canary), loaded into memory before the app mounts. Keeps credentials out of plaintext at rest; not an XSS defence. - The router gate is not a security boundary — the API authorises every request and re-reads the role each time. The gate only stops a dashboard that will never load.
- Every
VITE_*is declared insrc/vite-env.d.ts— a typo arrives asundefined, not a type error. - TypeScript pinned to 6.x, not 7.x — TS 7 drops the JS
tscthatvue-tsc3 patches, sobuildthrows under TS 7. - i18n in composition mode —
errors.*keys mirror the API’s error codes;en/ruare kept at exact key parity.
Environment
Vite inlines these at build time → a change means a rebuild (and for Docker, the right
--build-arg).
Deployment
index.html, caches hashed assets forever / index.html
never, sends noindex + DENY. Outside the image: (1) point ADMIN_URL in the API env at this
origin or CORS refuses it; (2) put a network gate in front — nothing here needs to be
publicly reachable.