Skip to main content

Mystical Card Generator

Route: /card-generator (src/app/card-generator/page.tsx, default export OgImageViewer).

What this is: a logged-in (or guest-quota) tooling flow that renders shareable OG-style SVG cards via GET /api/og-image?format=json, with wizard vs advanced UI modes, optional PNG download through client-side convertSvgToPng.

UI modes​

ModeUIState
WelcomeWelcomeInterfaceFirst-visit flow (useWelcomeFlow)
WizardWizardFormGuided fields
AdvancedGenerationForm + AdvancedControlsPro-tier positioning/watermark knobs

Mode persists via useGeneratorMode (UserPreferencesContext). Form fields use Jotai atoms (generatorFormStateAtom, src/app/card-generator/atoms/generatorAtoms.ts).

layout.tsx wraps children in Suspense + fullscreen MysticalLoader fallback.

Generation API​

Primary call: useImageGeneration → noCacheFetch('/api/og-image?…') with cache-buster query params.

Query (common)Purpose
format=jsonSVG string + metadata (required for UI)
seed, avatarSeedDeterministic avatar/pattern
quote, authorCustom copy
width, height, shapesDimensions / pattern density
ratioPreset aspect from form
glassBackgroundDefault true when advanced options absent
Pro knobsavatarX/Y, watermark*, borderColor, etc. (stripped server-side for free tier — see OGImageService)

Load saved generation: useGenerationLoader → GET /api/og-image/[id]?format=json.

Quota probe (no generation): useQuotaTracking → GET /api/og-image?format=json&dry-run=true (backend EnhancedQuotaService / guest quotas — see OGImageService dry-run).

Co-located API docs: OG Image index, OGImageService. Handler: src/app/api/og-image/route.tsx (withRateLimit, withPermissions).

Supporting data​

SourceUsed for
getAspectRatios server actionsrc/app/actions/form-options.ts (cached; reads DB form options)
GET /api/form-optionsAdmin CRUD for option rows (Zod + requireAdminApiAccess) — not the default wizard fetch path
useSubscriptionStatusPro feature gates in UI
QuotaDisplayRemaining generations from API responses

Download path​

fileUtils.ts: optional POST /api/svg-to-png or client conversion for PNG export; filenames like og-image-${seed}-${ratio}.png.

Upload (ancillary)​

Avatar or custom assets may use POST /api/upload/image (multipart, auth required) — see upload image route and OpenAPI Upload tag (co-located route.md may still be bootstrap).

Operator troubleshooting​

SymptomCheck
Quota stuck at 0dry-run=true response; guest vs user quota tables (useQuotaTracking clears localStorage quota keys on auth change)
429 / quota errorsOGImageService + subscription tier; admin quota routes
Advanced controls ignoredSession Pro status; server strips Pro-only params for free users
Empty aspect ratiosPostgres form_options category + getAspectRatios server action
Regenerate dialog loopuseImageGeneration compares FormSnapshot via showRegenerationDialog

Sources: src/app/card-generator/page.tsx, src/app/card-generator/hooks/useImageGeneration.ts, src/app/card-generator/hooks/useQuotaTracking.ts, src/app/card-generator/hooks/useFormOptions.ts, src/app/api/og-image/route.tsx, src/app/api/og-image/services/OGImageService.ts, src/app/actions/form-options.ts