Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,19 @@ v41 Iris turns the current design, the Interactive Tour, or the Before / After c
- **Ownership** is stateless: the key is `base64url(HMAC-SHA256(SHARE_SIGNING_SECRET, 'own:' + id))`. The editor keeps it in `glint_shares` ("Your links"), and a manage link (`/s/<id>#key=...`) lets the viewer page delete the share.
- **Viewer.** `s/index.html` (Vite input `share`, entry `src/share/viewer.js`, also a knip entry) is the page. On Vercel, `vercel.json` rewrites `/s/<id>` to `api/share.js?op=page` (`api/_share-page.js`), which fills `<!--SHARE_META-->` (Open Graph tags, poster) and `<!--SHARE_DATA-->` (the manifest as inline JSON) and sends a strict content security policy. Under `vite`, a dev middleware serves the static page and the viewer fetches `/api/share-manifest` itself. `?embed=1` hides the chrome. The service worker's navigation fallback skips `/s/` and `/api/` (`navigateFallbackDenylist`), or a returning visitor would get the cached homepage.
- **Players are shared with the exports.** The Tour player (`src/share/tour-player.js`) and the Before / After slider (`src/share/compare-player.js`) have no imports; the viewer imports them, and `tour-export.js` / `compare-export.js` inline their raw text (`?raw`) into the downloaded .html files. Edit the player modules, never the export templates. A test checks they stay import-free.
- **One function for all share routes.** The Vercel Hobby plan allows 12 serverless functions per deployment and every non-underscore file in `api/` is one (10 today). So `api/share.js` is the only deployed share function: `vercel.json` rewrites `/api/share-<op>` and `/s/<id>` to it with `?op=`, and it dispatches to the route modules `api/_share-<op>.js` (underscore files are not deployed on their own). **Add new server routes the same way, not as new `api/` files**, or the deployment fails with `exceeded_serverless_functions_per_deployment`.
- **One function for all share routes.** The Vercel Hobby plan allows 12 serverless functions per deployment and every non-underscore file in `api/` is one (11 today, with `api/account.js`). So `api/share.js` is the only deployed share function: `vercel.json` rewrites `/api/share-<op>` and `/s/<id>` to it with `?op=`, and it dispatches to the route modules `api/_share-<op>.js` (underscore files are not deployed on their own). **Add new server routes the same way, not as new `api/` files**, or the deployment fails with `exceeded_serverless_functions_per_deployment`.
- **Tests and local runs.** `SHARE_STORE=memory` swaps Blob for an in-process store (still minting real client tokens), so `scripts/regression-tests.mjs` runs every route. Under plain `npm run dev` there is no `/api`, so `shareStatus()` is false and the Share panel says links are not set up; downloads still work.

### Glint Pro waitlist and usage analytics
Not a versioned release; groundwork for a paid plan (Glint Pro: hosted AI, lasting share links, sync). The studio itself stays free, and site copy must keep saying so.
### Glint Pro groundwork: waitlist, analytics, accounts and AI credits
Not a versioned release; groundwork for a paid plan (Glint Pro: hosted AI, lasting share links, sync). The studio itself stays free, and site copy must keep saying so. Glint Pro itself will be a later numbered release (v42 Junction shipped separately).

- **Accounts and hosted AI credits (Clerk + Neon; Supabase is gone).** Supabase was removed entirely, and cloud project and template sync, the community gallery (`gallery.js`) and live collaboration (`collab.js`) went with it; projects now live only in the browser. Sign-in is Clerk: `src/features/auth.js` loads Clerk's two browser bundles from the Clerk instance's own Frontend API (host decoded from the publishable key), so there is no Clerk package in the build; without a key no sign-in UI shows and nothing loads. It exports `getToken()`, `getUser()`, `onAuthChange()`, `openSignIn()`, `isConfigured()`; the header pill is a Sign in button or Clerk's own user button. The key is read at build time from `VITE_CLERK_PUBLISHABLE_KEY` or `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` (the name Clerk's Vercel Marketplace install adds; `vite.config.js` `envPrefix` lets it through). Server side, `api/_account.js` verifies the Clerk session token with `@clerk/backend` `verifyToken` (`CLERK_SECRET_KEY`, or `CLERK_JWT_KEY` for a networkless check) and keeps plans and credit counts in Neon Postgres through `@neondatabase/serverless` (`DATABASE_URL` or `POSTGRES_URL`). The schema is `api/_account-schema.js` (`subscriptions`, `ai_usage`, and the atomic `glint_use_credits(user, cost, free_limit, pro_limit)` function, keyed by Clerk's text user id); **the server installs it itself** the first time a query fails with a missing function or table, so there is no SQL to run by hand. `metered(kind, handler)` wraps the six hosted AI routes, spends credits before the model call (`CREDIT_COSTS`: 1 for text / vision / enhance / agent, 5 for an image) and refunds them when the route answers with an error. It answers `401 { code: 'sign_in' }` or `402 { code: 'no_credits' }`; a Clerk or database failure answers 503 (closed, not free). **Metering is on only when the deployment has a Clerk key and a database URL**; without them the routes behave as before. Limits default to 20 free and 500 Pro credits a month (`AI_FREE_CREDITS`, `AI_PRO_CREDITS`). `api/account.js` is one function for every account route (`?op=me` today; checkout, portal and the payment webhook go here, not in new files). In the editor, `src/features/account.js` `hostedFetch(path, body)` is the only way to call a hosted AI route: it adds the token, turns a sign-in or out-of-credits answer into a 501 (which every caller already treats as "use the person's own key") and shows why in a toast unless the person has their own key; the `#ai-credits` header chip shows credits left. **A new hosted AI route must be wrapped in `metered()` and called through `hostedFetch()`.** Tests use `ACCOUNT_STORE=memory` and sign throwaway Clerk-shaped tokens. Still to build: checkout + webhook (a merchant of record such as Lemon Squeezy), an account panel, share link perks, real prices.

- **Waitlist.** The pricing page's Pro card (`pricing/index.html`, `#pro`) has a `form[data-waitlist]` that `public/site.js` (0a) posts to `/api/waitlist`. `api/_waitlist.js` holds both routes as ops of the one share function (`vercel.json` rewrites `/api/waitlist` and `/api/waitlist-export` to `api/share.js`). The Blob store is public, so entries are stored unreadable: the file name is an HMAC of the email (which also de-duplicates) and the body is AES-256-GCM encrypted, both keyed from `SHARE_SIGNING_SECRET`. Changing that secret orphans the list. The join route answers the same whether or not the email was already there. Read the list with `curl -H "Authorization: Bearer $CRON_SECRET" https://<site>/api/waitlist-export?format=csv`.
- **Analytics.** Vercel Web Analytics, no cookies. Marketing pages load it from `public/site.js` (0) (skipped on localhost) and send `open_studio` and `waitlist_join`. The editor uses `src/features/analytics.js` (`bindAnalytics()`, `track(name, data)`): `section_used` once per sidebar section per visit (a capture listener, so new sections are covered for free), `export`, `share_link`, `roll_develop`. **Events carry feature names and choices only, never images, file names, colors or typed text;** if you add an event, list it on the privacy page.
- **Analytics.** Vercel Web Analytics, no cookies. Marketing pages load it from `public/site.js` (0) (skipped on localhost) and send `open_studio` and `waitlist_join`. The editor uses `src/features/analytics.js` (`bindAnalytics()`, `track(name, data)`): `section_used` once per sidebar section per visit (a capture listener, so new sections are covered for free), `export`, `share_link`, `roll_develop`, `ai_blocked` (sign-in needed or out of credits). **Events carry feature names and choices only, never images, file names, colors or typed text;** if you add an event, list it on the privacy page.

### Persistence
User data (templates, brand kits, projects, onboarding flags) is stored in `localStorage` under `glint_*` keys, each feature managing its own. `src/state/serialize.js` handles project save/load (`SERIALIZED_FIELDS` for the lean payload, `PROJECT_FIELDS` for heavier fields like dataURLs). Cloud sync (optional) goes through Supabase. The Campaign folder lives in its own `glint_campaigns_v1` localStorage store (optional Supabase mirror ships but is unwired) and is never snapshotted. Projects (`glint_projects_v12`) are stored in IndexedDB (`src/state/project-db.js`, db `glint`, store `kv`) with a localStorage fallback (used when IndexedDB is unavailable or does not load within 8s); any project store found in localStorage is merged into IndexedDB on every healthy load (not one-time) and then removed, and the `glint_projects_idb` flag records that IndexedDB was used before, so a later load failure retries once and warns the user. The projects status line shows "Saved" only after the IndexedDB write commits. Share links (v41) keep each link's record and owner key in `glint_shares` (newest first, max 50, thumbnails dropped first on quota errors); the shares themselves live in Vercel Blob, not in the project. Since v40 the Projects panel's "History" button (whole-project versions) is labeled "Project timeline", so it is not confused with the History panel.
User data (templates, brand kits, projects, onboarding flags) is stored in `localStorage` under `glint_*` keys, each feature managing its own. `src/state/serialize.js` handles project save/load (`SERIALIZED_FIELDS` for the lean payload, `PROJECT_FIELDS` for heavier fields like dataURLs). There is no cloud sync (it left with Supabase). The Campaign folder lives in its own `glint_campaigns_v1` localStorage store and is never snapshotted. Projects (`glint_projects_v12`) are stored in IndexedDB (`src/state/project-db.js`, db `glint`, store `kv`) with a localStorage fallback (used when IndexedDB is unavailable or does not load within 8s); any project store found in localStorage is merged into IndexedDB on every healthy load (not one-time) and then removed, and the `glint_projects_idb` flag records that IndexedDB was used before, so a later load failure retries once and warns the user. The projects status line shows "Saved" only after the IndexedDB write commits. Share links (v41) keep each link's record and owner key in `glint_shares` (newest first, max 50, thumbnails dropped first on quota errors); the shares themselves live in Vercel Blob, not in the project. Since v40 the Projects panel's "History" button (whole-project versions) is labeled "Project timeline", so it is not confused with the History panel.

### Brand & identifiers (v36 Glint rename)
The app was called SnapShotPro through v35. Since v36 every identifier uses the Glint name: localStorage keys use the `glint_` prefix, the IndexedDB db is `glint` (store `kv`, project store key `glint_projects_v12`), the projects BroadcastChannel is `glint-projects`, and the extension handoff messages are `glint-capture` / `glint-capture-ack` (`ext-receiver.js` still accepts `snapshotpro-capture` and acks it as `snapshotpro-capture-ack`, so extension builds already installed keep working). **New storage keys use the `glint_` prefix.**
Expand Down Expand Up @@ -218,15 +220,15 @@ Current `SCHEMA_VERSION` is 26 (v42 Junction: tour hotspot targets, Bokeh tilt-s
## Backlog (unbuilt)

- **From v42:** CMYK conversion and real TrimBox / BleedBox entries for the print PDF; a true high-resolution re-render for print (today it is the design's own pixels plus a smooth upscale); tour links in the board's PNG export; an on-canvas handle for the tilt-shift band; Design Agent tools for tours.
- **From v41:** view counts; a hosted "Your links" that follows the person across browsers (today the owner keys live in one browser's `glint_shares`). Retiring Supabase entirely (sign-in, cloud project and template sync, the community gallery, live collaboration) was proposed for v41.1 and needs a decision first.
- **From v41:** view counts; a hosted "Your links" that follows the person across browsers (today the owner keys live in one browser's `glint_shares`). Supabase was retired (see the Glint Pro groundwork section); cloud project sync, a community gallery or live collaboration would have to be rebuilt on Neon.
- **Still open from the v39 options list:** the extension's element picker. From v39 itself: per-frame flips on video. (Raised cards in dark mode shipped in v41.0.1: `flipLightness` folds the top of the range so a white card lands above a light-gray page; the light direction still saturates everything below the surface to white.)
- **From v40:** nothing left; Look chip previews with temperature / tint and scaled blur, the shared Light / Dark scene record, clearing history on page switch and normalizing Roll grade overrides on load all shipped in v41.0.1.
- **New creative outputs:** AI Storyboard / multi-panel generator. (Tour branching shipped in v42.)
- **New mockup classes:** billboard/large-format and more apparel bases (deferred v27 stretches). (Print PDF with bleed and crop marks shipped in v42; CMYK is still open.)
- **Automation & scale:** public REST API + CLI (headless generation).
- **More capture surfaces:** element-pick + Firefox/Edge port for the extension (deferred v26 stretch); mobile camera capture.
- **Collab & platform:** async review / approvals (pinned threaded comments, sign-off; distinct from live cursors); template marketplace + creator monetization; plugin / extension SDK.
- **Deferred from shipped releases:** a `look` kind in the community gallery (v38); Roll per-shot focal point and a Roll-aware Merge Studio (v37); Motion Studio full per-property keyframing + bottom-dock timeline (v29); Supabase campaign mirror wiring, in-place multi-language re-render, open-ended Producer autonomy (v30).
- **Deferred from shipped releases:** Roll per-shot focal point and a Roll-aware Merge Studio (v37); Motion Studio full per-property keyframing + bottom-dock timeline (v29); in-place multi-language re-render, open-ended Producer autonomy (v30).

## Things that look like project rules but aren't

Expand Down
53 changes: 15 additions & 38 deletions DEPLOY.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ In the Vercel project dashboard → Settings → Domains → add your domain. Ve

The app still works without these values for offline editing, local analysis,
PWA install, and bring-your-own-key AI. Add them when you want hosted AI,
accounts, cloud sync, or share links.
accounts, or share links.

### Hosted AI backend

Expand All @@ -85,45 +85,22 @@ This enables the serverless routes in `api/` so visitors can use AI features
without pasting their own key. If `OPENAI_API_KEY` is missing, those routes
return `501` and the editor falls back to the existing browser-key flow.

### Supabase (for accounts + cloud project sync)
### Accounts and hosted AI credits (Clerk + Neon)

Create a free Supabase project at https://supabase.com/, then in the Vercel project → Settings → Environment Variables, add:
Sign-in is Clerk and the credit counts live in a Neon Postgres database. Add
both from the Vercel project's **Storage / Marketplace** tab; each one adds its
own environment variables, so there is nothing to copy by hand:

| Name | Value |
|------|-------|
| `VITE_SUPABASE_URL` | from Supabase project Settings → API |
| `VITE_SUPABASE_ANON_KEY` | from Supabase project Settings → API (the **anon public** key, safe to ship to browsers) |

Both must start with `VITE_` so Vite exposes them to the client bundle.

Then in your Supabase project, create the schema (SQL Editor → New Query):

```sql
create table if not exists public.templates (
user_id uuid not null references auth.users(id) on delete cascade,
name text not null,
payload jsonb not null,
updated_at timestamptz default now(),
primary key (user_id, name)
);
alter table public.templates enable row level security;
create policy "users own templates" on public.templates
for all using (auth.uid() = user_id) with check (auth.uid() = user_id);

create table if not exists public.projects (
id uuid primary key default gen_random_uuid(),
user_id uuid not null references auth.users(id) on delete cascade,
name text not null,
payload jsonb not null,
updated_at timestamptz default now(),
unique (user_id, name)
);
alter table public.projects enable row level security;
create policy "users own projects" on public.projects
for all using (auth.uid() = user_id) with check (auth.uid() = user_id);
```
| Added by | Name | Used for |
|------|-------|-------|
| Clerk | `NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY` | The browser's sign-in (the build reads this name; `VITE_CLERK_PUBLISHABLE_KEY` also works) |
| Clerk | `CLERK_SECRET_KEY` | The server checks session tokens with it |
| Neon | `DATABASE_URL` | Plans and monthly credit counts |

In Supabase → Authentication → Providers, enable Email (default) and optionally Google/GitHub. For Google/GitHub, set the redirect URL to your Vercel domain.
Redeploy after adding them. The server creates its two tables and one function
in the database the first time it is used. Once both are present, hosted AI
needs a signed-in account and spends credits (20 a month by default; see
`docs/BACKEND.md`). Without them, hosted AI works for everyone as before.

### AI cloud features

Expand All @@ -137,7 +114,7 @@ See `docs/BACKEND.md` for the route list and what the backend adds.

### Bundle size & lazy loading

v5 dependencies (Supabase SDK, OpenAI/Anthropic SDKs, Tesseract.js, @imgly/background-removal) are split into separate chunks via Vite's `manualChunks` and dynamically `import()`-ed only when the related feature is first used. Initial JS payload stays roughly the same as v4 (~30KB gzipped main bundle + small chunks).
v5 dependencies (OpenAI/Anthropic SDKs, Tesseract.js, @imgly/background-removal) are split into separate chunks via Vite's `manualChunks` and dynamically `import()`-ed only when the related feature is first used. Initial JS payload stays roughly the same as v4 (~30KB gzipped main bundle + small chunks).

The 23 MB `ort.wasm` (background-removal model) in `dist/` is **not loaded by default** — it's only fetched when the user clicks "Remove Background." Vercel serves it as a static asset like any other.

Expand Down
20 changes: 6 additions & 14 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,10 @@ npm run build

Should produce a `dist/` folder with `index.html` plus hashed JS and CSS bundles. That's what Vercel deploys.

## Supabase schema (cloud features)
## Accounts database

The copyable SQL lives in `src/features/auth.js` (the setup modal's "Copy SQL"
button) — paste it into the Supabase SQL Editor. Tables and their RLS:

- `templates` — per-user named template payloads. PK `(user_id, name)`. RLS:
owner-only (`auth.uid() = user_id`).
- `projects` — per-user named full-project snapshots. RLS: owner-only.
- `gallery` (v11.3) — public community gallery of templates + brand kits.
Columns: `id, author_id, kind('template'|'brandkit'), name, payload jsonb,
preview_url, likes, created_at`. RLS: **public read** (`select using (true)`),
insert/delete restricted to the author (`auth.uid() = author_id`).

Storage buckets (created on demand by the client, public):
- `shares` (share links), `gallery` (v11.3 thumbnails).
Supabase is gone (cloud project and template sync, the community gallery and
live collaboration went with it). Sign-in is Clerk, and a Neon Postgres database
holds two tables, `subscriptions` and `ai_usage`, plus the `glint_use_credits`
function. The schema lives in `api/_account-schema.js` and the server installs
it on first use.
Loading
Loading