Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.
Admin console (v0.16 A1 · v0.16.2 A2 · v0.16.3 A3 · v0.16.4 A4)
TL;DR — set
CANVIX_ADMIN_USERS="your-username", restart, sign in: the shield icon on the dashboard opens/admin. Everything below is operable from those four pages; this document is the operator guide and the decision record.
The admin console is the operator surface for a Canvix instance:
| Page | What it shows / does |
|---|---|
Overview (/admin) |
totals (users, designs, media, sessions, comments), 14-day traffic / daily-active / signup / AI-call charts, top routes, AI usage by feature, newest accounts, DB latency, provider status |
Users (/admin/users) |
searchable directory with per-user design counts, active sessions, last activity; grant/revoke admin rights; force sign-out |
AI & models (/admin/ai) |
provider override (base URL + write-only API key), model ids (text / vision / image), per-feature kill switches, live connection test |
Settings (/admin/settings) |
allow new sign-ups, anonymous editing, instance facts, privacy posture |
1. Turning it on — the first administrator
Admin access is fail-closed. Two paths, no others:
Env bootstrap —
CANVIX_ADMIN_USERSis a comma-separated username list that is admin on every request:CANVIX_ADMIN_USERS="alice,bob" # lowercase; case-insensitive matchNo DB write needed — set it, restart, sign in as one of those users. This is also the recovery path if console-managed admins are ever locked out.
DB role —
User.role = 'admin', granted by another administrator from the Users page. This is what the console itself manages.
There is deliberately no "first registered user is admin" rule: on a
public instance that would silently hand the keys to whoever happens to
register first. No config-table flag, no secret URL — if neither path
grants admin, /admin and every /api/admin/* route refuse everyone.
The Users page shows where each admin's rights come from (admin,
admin · env) — an env-blessed username stays admin even if its DB role
is changed; the env always wins, and the badge says so.
2. The pages in detail
Overview
- API requests counts every request through the
withLoggingwrapper all API routes already use — per UTC day, so "24h" means "today (UTC) so far". See §3 for what is and isn't recorded. - Daily active users = distinct actors (userIds for accounts, the hashed anonymous cookie key for anonymous browsers) that opened the dashboard or the editor that day.
- AI calls are split teal (succeeded) / red (failed) from the
AIUsageaccounting that has existed since v0.5. - Top routes / usage by feature cover the last 7 days.
- Own API keys (v0.23) is the BYOK adoption stat: distinct accounts
with at least one row in
UserAIProvider, how many keys they stored, and how many of the five capability slots those keys cover. Keys are never shown — this is the same aggregate-only posture as the rest of the page (no usernames ride along).
Users
- Search is a case-insensitive username substring. (Registration lowercases usernames, but rows seeded or imported by other means may carry mixed case — the search matches those too.)
- make admin / revoke uses a two-step inline confirm. The route
refuses self-modification (
SELF_ROLE_CHANGE) — an admin can never lock themselves out of the only page that undoes role changes. - sign out revokes every session of that user (a single bounded
DELETEonSession; designs and uploads are untouched). Works on your own rows too — it just signs you out.
AI & models
Providers (the multi-provider table, v0.16.2 A2). Add up to 8 providers — any OpenAI-compatible endpoint works (NVIDIA NIM, OpenRouter, Z.ai, Groq, OpenAI…): a label, a base URL and a write-only API key each. Every capability slot can then be pinned to a different provider + model:
| Slot | What answers through it |
|---|---|
text |
Magic Write · Translate · Assistant · AI design plan · speaker notes · AI theme (chat completions) |
vision |
Magic Layers · alt-text generation (image understanding) |
image |
text-to-image |
imageEdit |
Magic Eraser / Enhance |
video |
AI video generation — Sora-style async (videos/generations), v0.19 Wave 4 |
Photo search is not a slot anymore (v0.16.4 A4). It rode the AI
table as imageSearch — an images/search endpoint almost no
OpenAI-compatible vendor serves, the standing 404 behind the A3
incident. It now runs on the free stock-media keys — the same keys
as the Videos rail (see docs/STOCK-PHOTO.md). Stored tables that
still carry an imageSearch slot are read fine — unknown slot keys
are dropped on read and disappear on the next save. No migration.
Stock media — the Pexels & Pixabay card (v0.16.5 A5). Those
two keys are managed on this page, "like the others": a fixed
two-provider card below Model slots with write-only key fields
(stored keys echo as masks only, sk-1…wxyz), a per-provider
Test button and a per-provider Clear. The same two keys
power the Photos and Videos search rails — they are library
catalogs, not AI providers, which is exactly why they don't ride
the provider table. Precedence mirrors every other credential
here: a stored console key wins over PEXELS_API_KEY /
PIXABAY_API_KEY; clearing the stored key restores the env
fallback. Saving takes effect immediately — no redeploy — because
the key store rides AppConfig behind the config module's 10 s
in-process cache (the same cost profile as the feature switches,
which already sit on every AI route). The Test button runs one
minimal one-result search through the provider's real search
endpoint with the effective key — the same call the Photos rail
makes, so a pass there is a pass in the panel — rate-limited to
one probe per 10 s, and its verdict never echoes the key, the
request URL (Pixabay's key rides the query string) or the
provider's body.
A slot left on “— fall back —” ignores the table and walks the legacy
chain below. /api/ai/capabilities now probes per slot, so wiring
text to NVIDIA and images to Z.ai reports exactly those features as
available. Editing a provider (label/URL) never demands the key again:
an empty key field keeps the stored credential (matched by id);
deleting the row and re-adding needs it. One click imports the old
single-provider override into the table and clears the legacy row.
Fallback chain for unpinned slots (highest wins):
- the console override stored in
AppConfig(ai.provider), ZAI_BASE_URL+ZAI_API_KEYenvironment variables,- the
.z-ai-configfile (local development convenience), - unconfigured — local-only features keep working (the F2b pattern).
The override needs both fields; sending provider: null clears it
and restores the env/file fallback. The page always shows which layer is
currently answering per slot (providers table / legacy override / environment / config file) and the effective base URLs — but never a
key: keys are stored once and echoed back only as masks
(sk-1…wxyz). Same posture as the env vars they override.
Models — per-slot model ids in the providers table; the fallback
chain still reads the legacy text / vision / image ids (vision
defaults to glm-4.5v). Empty = the provider's default, exactly the
pre-console behaviour. Ids are validated ([A-Za-z0-9._:+/@-]{1,120} — /
for NVIDIA NIM namespaces, @ for OpenRouter prefixes)
before they can reach a provider.
Feature switches — seven kill switches (Magic Write, image generation, image editing, Magic Layers, translation, Assistant, photo search). A switched-off feature:
- reports
falsein the public/api/ai/capabilities(panels grey out), - answers
503 FEATURE_DISABLEDfrom its route — before rate limiting or any provider work, - local features (background removal, colour palette, layout suggestions) are never affected.
Test connection — one minimal chat completion (thinking disabled,
one-word reply, 15 s circuit breaker), rate-limited to one probe per
10 s. It is one of the only console actions that spends provider quota.
Each provider row has its own Test button; the fallback card tests the
resolved text slot. The probe goes through the SDK constructor with the
resolved { baseUrl, apiKey } — never ZAI.create(), whose file-only
lookup ignored env vars and broke every test since A1 (see D3). The
stock-media card's Test buttons spend stock-provider quota the same
way (one one-result search each).
Logs
/admin/logs (v0.16.3 A3) answers "why isn't the AI feature working"
without an SSH session. Two surfaces:
- AI slot status — what each of the five capability slots (
text,vision,image,imageEdit,video) resolves to right now (v0.16.4 A4:imageSearchis retired — photo search runs on the stock keys, not on an AI slot; v0.19 Wave 4 addedvideo): provider label, base URL, model id and which config layer answered (providers table / legacy override / env / file). Never the key. A slot wired to a chat-only provider is the classic silent breakage — text features work, image generation 404s on the same key — and the strip makes the wiring visible before anything is even tried. - AI request log — one row per AI request (the AIUsage table, see §3): feature, provider · model, outcome chip (200-299 green; 403 rejected · 429 rate-limited · 503 unconfigured · provider HTTP code red), round-trip duration and the scrubbed failure reason — the same string the client's 502 body carries (one truth, two audiences). Live tail (5 s poll, pauses when the tab is hidden), window (15 m … 7 d), feature and outcome filters, per-feature call/error counters.
The per-slot Test buttons on the AI & models page probe the real endpoint each slot uses (chat completion for text/vision, a real minimal generation for image, a deliberately image-less probe for imageEdit — a 400-class rejection proves the endpoint exists). A 404 verdict states the fix: chat-only providers cannot run image slots; pin them to a provider that serves image endpoints.
Settings
- Allow new sign-ups — off means
POST /api/auth/registeranswers503 SIGNUPS_CLOSED. The check runs before the 5/hour rate limiter, so a closed instance burns none of an honest visitor's attempt budget. Existing accounts sign in as usual. - Anonymous editing — off means only signed-in accounts can create or save designs. Reading, sharing and exporting existing designs (including the anonymous commons) is untouched — the switch gates writes, not reads.
3. Traffic & activity recording — the model
Durable (the charts):
- One
TrafficStatrow per (UTC day, route template, method, status), incremented fire-and-forget by thewithLoggingwrapper. Counts only — no ids, no IPs, no query strings (the same stance as/api/health?v=2). Cardinality is bounded by the route table × days × status codes. - One
DailyActiverow per (UTC day, actor) — actor = userId or the sha256 anonymous-cookie hash (already a hash when it arrives). - Retention: rows older than 90 days are swept lazily (~1 % of writes trigger the bounded delete).
- Opt-out:
CANVIX_TRAFFIC=0disables recording entirely (the console then shows zeros). - Cloudflare caveat — counters are written fire-and-forget after the
response; on workerd a cancelled evicted request can drop the write,
so counts may under-report there. Self-hosted Node (the primary
target) is exact. Improving this needs
waitUntilplumbing through every route — deliberately out of scope for A1.
Config reads (feature switches, settings, provider table) are cached
in-process for 10 s and invalidated on write — one tiny indexed
findMany per window per instance. A failed config read falls back to
defaults (= pre-A1 behaviour): these toggles are additive restrictions
and a flapping read must not brick design autosave.
Live (v0.16.2 A2, the “Live traffic” panel): an in-memory rolling
window recorded by the same withLogging wrapper — per-second
request/error buckets (last 60 s shown), per-route per-minute hits,
hashed visitor keys and a latency ring, all capped and swept (see
src/lib/admin/realtime.ts). Semantics worth knowing:
- process-local — counters reset on restart; TrafficStat/AIUsage remain the durable record,
- single process — each Node process counts its own requests (the self-hosted standalone deploy is one process),
- the panel polls
GET /api/admin/realtimeevery 2 s and that poll is excluded from the live counters (the dashboard must not become its own top route); it is still counted in the durable tables, - visitors are counted through a per-boot salted hash of the client IP — a count key, not an identity; raw IPs are never stored anywhere,
CANVIX_TRAFFIC=0disables live recording together with the durable counters.
4. API surface (for scripts)
All /api/admin/* routes re-check the session independently of the UI
(401 unsigned, 403 non-admin) and mutations enforce same-origin:
GET /api/admin/overview — everything the Overview page shows
GET /api/admin/realtime — live counters (polled every 2 s)
GET /api/admin/users?q=&page= — directory + per-user aggregates
POST /api/admin/users/<id>/role — { role: "admin" | "user" }
POST /api/admin/users/<id>/sessions — revoke all sessions of one user
GET /api/admin/config — sanitized config (masked keys)
PUT /api/admin/config — { provider? | providers? | models? | features? | settings? | importLegacyProvider? }
POST /api/admin/config/ai-test — live provider probe (1 / 10 s)
PUT accepts any subset of the sections; features and settings
merge over current values, models replaces, provider follows §2,
providers full-replaces the table:
{
"providers": {
"list": [
{ "id": "pnvidia", "label": "NVIDIA NIM", "baseUrl": "https://integrate.api.nvidia.com/v1" },
{ "label": "Z.ai", "baseUrl": "https://api.z.ai/v1", "apiKey": "sk-…" }
],
"slots": { "text": { "providerId": "pnvidia", "model": "meta/llama-3.1-70b-instruct" }, "image": null }
}
}
Ids are optional on input (generated server-side); an omitted apiKey
keeps the stored key for that id; providers: null clears the table.
importLegacyProvider: true folds the A1 single override into the table.
ai-test body: {} probes the resolved text slot; { providerId }
probes that provider; model overrides the model for the probe.
5. Dependency & design decisions — on record
D1 — zero new dependencies. Prisma models for storage (
AppConfig,TrafficStat,DailyActive+User.role), hand-rolled SVG charts (the same discipline as the GIF LZW encoder and the WebM muxer), the existingpgdriver only inside the e2e seed. No analytics SDK, no charting library, no admin framework.D2 — admin resolution is DB role OR env list. Fail-closed both ways; no implicit first-user admin; the env list doubles as the lockout recovery path.
D3 — provider clients are constructed directly (A2 correction). A1 injected console providers into
process.env.ZAI_*beforeZAI.create(), believing the SDK resolved env vars. It does not —loadConfig()only reads.z-ai-configfiles, so every console/env-configured provider failed instantiation with "Configuration file not found or invalid" (the root cause behind every failed Test connection on canvix.app). The SDK class constructor takes exactly{ baseUrl, apiKey };makeClient()(src/lib/ai/provider.ts) now constructs it directly with the resolved config. The env-injection path is gone.D4 — API keys are write-only. Stored in
AppConfig, returned only asmaskApiKey()output; GET responses never contain a full key (unit-tested).D5 — traffic is aggregate-only and opt-out-able. Counts, never identities;
CANVIX_TRAFFIC=0for instances that want none of it; 90-day retention; the workerd under-count caveat documented above.D6 — config reads are cached, failures fall back to defaults. Availability trumps restriction-consistency here; the DB being truly down breaks the app elsewhere anyway.
D7 — the sign-ups gate runs before the rate limiter. A closed instance consumes none of a visitor's registration budget.
D8 — the migration is purely additive.
User.roledefaults to'user'; no config rows exist until an admin writes them; an instance that never opens/adminbehaves exactly as before.D9 — the e2e suite spends zero registrations. Fixture users and sessions are seeded straight into the database (the app's own Postgres via the
pgdriver), keeping the suite inside the 5/h/IP budget the other specs honor.D10 — self-role-change is refused (
SELF_ROLE_CHANGE), so the console cannot be used to lock out its only operator.D11 — per-slot provider resolution (A2). The multi-provider table lives in the existing
AppConfigJSON store (ai.providers) — no schema change, no new migration. Slots that reference a deleted provider fall through to the legacy chain instead of failing the feature (fail-open, the same stance as D6).D12 — real-time counters are a zero-import in-memory module (A2).
src/lib/admin/realtime.tsimports nothing — so linking it statically into the stdlib-only observability module cannot repeat the v0.16.1 edge-bundle regression — and every structure is hard-capped and swept (bounded memory by construction).D13 — the live panel's own poll is not counted live (A2). The 2-second
/api/admin/realtimepoll is excluded from the in-memory counters so the dashboard's refresh never dominates the “top routes” view; it is still recorded in the durable tables.D14 (A3) — the AI request log lives IN AIUsage, not a new table. One row per AI request was already being written; the Logs view only needed the columns (model/status/durationMs/error, all nullable, migration
0010_ai_request_log). No second write path, no join, no new retention policy — 90 days, swept lazily like TrafficStat.D15 (A3) — provider error text is scrubbed, capped and shared.
describeProviderError()extracts the HTTP status, masks credential-shaped tokens (nvapi-/sk-/Bearer…), collapses whitespace and caps at 240 chars. The same string flows to AIUsage (error), the client 502 body (detail) and the console — no place shows a raw provider body, and no place shows different truths.D18 (Sound wave) — Freesound is the fourth stock connector, and the SFX pack is original CC0 synthesis. Sound search rides the A4/R6 stock-connector architecture (
src/lib/stock-sound.ts, one free Freesound key, console-manageable in the Stock media card,FREESOUND_API_KEYenv fallback, 24 h response cache, status-only errors) — never an AI slot; thesoundSearchfeature switch gates it with the photoSearch semantics. Results are CC0-filtered by default (the wider licence filter is an explicit request), and every insert stores a durable credit block onAudioElement.credit. The 16-sound offline pack (public/sfx/, generated byscripts/gen-sfx-pack.mjs) is pure code synthesis — no samples — released CC0 (manifest: docs/SOUND.md). Animation/transitionsfxIdfields are additive and validated against the catalogue on sanitize. No migration.D17 (A4) — photo search LEFT the AI provider table. The
imageSearchslot called animages/searchroute that almost no OpenAI-compatible vendor serves — a category error: stock photo retrieval is a library query with licensing, not a generative capability. It now rides the R6 stock-connector architecture (src/lib/stock-photo.ts, Pexels + Pixabay, the same two env keys as the Videos rail), with the same durable-credit acceptance and the same F2b gating. The admin table shrinks to four slots; stale storedimageSearchslot entries are dropped by validation on read (no migration); thephotoSearchfeature switch keeps its semantics against the new route; historicalsearchAIUsage rows keep rendering in the Logs view. Recorded in docs/STOCK-PHOTO.md.D16 (A3) — slot tests probe real endpoints, classified by verdict. A chat-only provider passing the old test while image generation 404'd was the diagnostic gap; now a 404/405 verdict says "not served — pin image slots to a provider that serves image endpoints", a 401/403 says "check the key", and a 400-class answer to the deliberately-empty imageEdit probe says "reachable". The image slot does a REAL minimal generation — the only full proof; on providers without the endpoint it 404s instantly and costs nothing.
6. Database changes (migration 0009_admin_console, extended by 0010_ai_request_log)
ALTER TABLE "User" ADD COLUMN "role" TEXT NOT NULL DEFAULT 'user';
CREATE TABLE "AppConfig" (key TEXT PRIMARY KEY, value JSONB NOT NULL, …);
CREATE TABLE "TrafficStat" (… UNIQUE(day, route, method, status));
CREATE TABLE "DailyActive" (… UNIQUE(day, actor));
npm run db:setup applies it; nothing else changes. A2 adds no
migration — the multi-provider table is one more AppConfig row
(ai.providers), and live traffic keeps no database state at all.
A4 adds no migration either — retiring the imageSearch slot is
pure code (stored slot entries are dropped by read-side validation).
0010_ai_request_log (v0.16.3 A3)
Four nullable columns on AIUsage — model, status, durationMs,
error — written by withProvider for every outcome. Existing rows
stay valid (nulls read as "not recorded"); rows are swept after 90
days. Instances that never open /admin/logs accumulate exactly what
they always did.