Skip to content

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.

feat(v0.9.4): Netlify joins the deploy matrix + 70% smaller bundles

Ashiq Hussain Mir8c47a8a65773
diff --git a/.gitignore b/.gitignore
index b6747a9..c78b735 100644
--- a/.gitignore
+++ b/.gitignore
@@ -43,6 +43,9 @@ yarn-error.log*
cloudflare-env.d.ts
.wrangler
+# netlify (v0.9.4)
+.netlify
+
# prisma generated client (v0.9.3 — regenerated by `prisma generate` / postinstall)
src/generated/
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e533d46..7c7f086 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,53 @@
All notable changes to Canvix will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
+## [0.9.4] — 2026-10-29
+
+The "third platform + leaner artifact" release: **Netlify** joins Vercel
+and Cloudflare Workers as a first-class deploy target, and every platform's
+bundle gets ~70 % smaller.
+
+### Netlify, zero-config
+- `netlify.toml` + pinned `@netlify/plugin-nextjs` 5.16.5 (Netlify's
+ OpenNext-based Next.js runtime — officially supports Next.js 16).
+ Connect the repo in the Netlify UI, set `DATABASE_URL`, done.
+- Functions run on AWS Lambda: full Node API surface, so scrypt auth,
+ `pg` sockets and `sharp` PNG export are all native — no runtime
+ guards ever trip.
+- The exact Netlify build pipeline runs locally without an account:
+ `npx netlify-cli build --offline`.
+
+### The 70 MB → 20.8 MB function bundle (why it was 70 MB)
+- Netlify's 50-MB-zipped function limit exposed that the traced
+ `@prisma/client` shipped **~90 MB of wasm the patched client provably
+ never loads** — in BOTH copies Next traces (nft's `node_modules/…` and
+ Turbopack's hashed `.next/node_modules/…`):
+ `*wasm-base64*` compilers for all five dialects, the old
+ `query_engine_bg*` library-engine wasm (dead with `engineType="client"`),
+ and the other dialects' `query_compiler_bg.{mysql,sqlite,…}` wrappers.
+- New `outputFileTracingExcludes` in `next.config.ts` remove exactly
+ those (+ sharp's darwin/win32 binaries), keeping the live files
+ (postgresql wrappers, `raw.wasm`, `wasm-module.mjs`) — verified by
+ booting the rebuilt standalone against the real database: health,
+ designs and templates all green.
+- Netlify function zip: **70.4 → 20.8 MB zipped** (52 MB unzipped, limit
+ 250). Cloudflare worker: unchanged **2.13 MB gzipped** (limit 3).
+ Node standalone: proportionally smaller for every self-hoster.
+
+### Deployment verification (all against the live database)
+- `scripts/verify-deploy-readiness.ts` — one command proving migrations
+ applied, schema complete (tables/columns/indexes), data present
+ (110 templates), and parameterized queries through the transaction
+ pooler. Reusable before any deploy, on any host.
+- Production Node standalone: `/api/health` `{"ok":true}`, landing,
+ templates, designs, auth register/login, anonymous `/api/auth/me`,
+ SSE stream sample, MCP 503 (no AI provider configured), cross-origin
+ CSRF rejection — all verified live; probe rows cleaned up.
+- Cloudflare: OpenNext build + `wrangler deploy --dry-run` +
+ workerd preview (landing 200, auth/me works, health degrades to the
+ documented structured 503 — no crashes).
+- Full gate: **232/232 vitest**, `tsc --noEmit` clean, eslint clean.
+
## [0.9.3] — 2026-10-29
The "run it anywhere" release: Canvix now deploys to **Cloudflare
diff --git a/README.md b/README.md
index 24021a6..a18809d 100644
--- a/README.md
+++ b/README.md
@@ -438,10 +438,11 @@ npm run build
npm run start
```
-## ☁️ Deploy — Vercel, Cloudflare Workers, or your own box
+## ☁️ Deploy — Vercel, Netlify, Cloudflare Workers, or your own box
Canvix runs on **any Node host** and — since v0.9.3 — on **Cloudflare
-Workers** too. Same codebase, same database, zero config divergence.
+Workers** too, and — since v0.9.4 — on **Netlify**. Same codebase, same
+database, zero config divergence.
### Vercel (or any Node host)
@@ -470,6 +471,29 @@ npm run deploy # → https://canvix.<you>.workers.d
> `research/CLOUDFLARE-WORKERS-PORTABILITY.md`). The real deployment is
> the source of truth: deploy (free), hit `/api/health`.
+### Netlify (free tier works)
+
+Zero-config via Netlify's OpenNext-based Next.js runtime — the repo ships
+`netlify.toml` + a pinned `@netlify/plugin-nextjs`, so connecting the repo
+in the Netlify UI is all it takes:
+
+1. Push the repo to GitHub, then **Add new site → Import an existing
+ project** in the Netlify UI (build settings are read from
+ `netlify.toml`).
+2. Set `DATABASE_URL` (the **transaction pooler** URL) under
+ *Site settings → Environment variables* — optionally `ZAI_BASE_URL` /
+ `ZAI_API_KEY`.
+3. Deploy. Open `/api/health` — `{"ok":true}` = full stack green.
+
+Functions run on AWS Lambda (full Node API surface — scrypt auth, `pg`
+sockets, `sharp` PNG export all native). To simulate the exact build
+locally: `npx netlify-cli build --offline` (no account needed) — the
+function bundle lands in `.netlify/functions/` (**20.8 MB zipped**, well
+under the 50 MB limit; v0.9.4's trace diet cut it from 70 MB).
+
+Honest free-tier notes: 100 GB bandwidth/month, 125 K function
+invocations/month, 300 build minutes — comfortable for personal use.
+
What makes it work (all already wired):
| Concern | How |
diff --git a/netlify.toml b/netlify.toml
new file mode 100644
index 0000000..cd7d0e5
--- /dev/null
+++ b/netlify.toml
@@ -0,0 +1,33 @@
+# Canvix on Netlify — via Netlify's OpenNext-based Next.js Runtime.
+# Docs: https://docs.netlify.com/build/frameworks/framework-setup-guides/nextjs/overview/
+#
+# The runtime auto-installs for Next.js sites connected via the Netlify UI,
+# but we pin it in package.json + this file so builds are reproducible
+# (same adapter version locally, in CI, and on Netlify).
+#
+# One secret to set (Netlify UI → Site settings → Environment variables):
+# DATABASE_URL = your Supabase *transaction pooler* URL (port 6543)
+# Optional (activates AI features):
+# ZAI_BASE_URL / ZAI_API_KEY
+#
+# Free-tier notes: 100 GB bandwidth/month, 125 K function invocations/month,
+# 300 build minutes — Canvix fits comfortably. Functions run on AWS Lambda
+# (full Node.js API surface: node:crypto scrypt auth, node:net/node:tls for
+# the pg driver, node:http for the MCP transport — all native there).
+
+[build]
+ command = "npm run build"
+ publish = ".next"
+
+[build.environment]
+ NODE_VERSION = "22"
+ # Netlify runs lifecycle scripts (unlike locked-down local sandboxes),
+ # so postinstall → prisma generate + the wasm portability patch just run.
+ NPM_FLAGS = "--include=dev"
+
+[[plugins]]
+ package = "@netlify/plugin-nextjs"
+
+# Static-ish route headers stay managed by the Next runtime; nothing else
+# to configure — middleware, route handlers, ISR and streaming all work
+# out of the box with the v5 runtime.
diff --git a/next.config.ts b/next.config.ts
index 43bae0b..be832eb 100644
--- a/next.config.ts
+++ b/next.config.ts
@@ -26,6 +26,33 @@ const nextConfig: NextConfig = {
],
"/api/mcp": ["./node_modules/sharp/**/*"],
},
+ // v0.9.4: the traced @prisma/client ships ~90 MB of wasm the patched
+ // client provably never loads — in BOTH copies Next traces (the nft one
+ // at node_modules/… and Turbopack's hashed copy under .next/node_modules/):
+ // - *wasm-base64*: base64-embedded compilers for every dialect; the
+ // patched loader (scripts/patch-prisma-wasm.mjs) only ever ESM-imports
+ // the raw .wasm (workerd) or reads it from disk (Node/Bun).
+ // - query_engine_bg*: the OLD library-engine wasm — dead with
+ // engineType = "client".
+ // - query_compiler_bg.{mysql,sqlite,sqlserver,cockroachdb}.*: other
+ // dialects' JS wrappers; the datasource is postgresql, fixed at
+ // generate time.
+ // Netlify's function limit (50 MB zipped) made this visible; every
+ // platform gets the smaller artifact. Keep the postgresql wrappers,
+ // raw.wasm and wasm-module.mjs — those are live.
+ outputFileTracingExcludes: {
+ "/api/**": [
+ "**/@prisma/client*/runtime/*wasm-base64*",
+ "**/@prisma/client*/runtime/query_engine_bg*",
+ "**/@prisma/client*/runtime/query_compiler_bg.{mysql,sqlite,sqlserver,cockroachdb}.*",
+ ],
+ "/api/mcp": [
+ // sharp's non-linux binaries never load on any serverless host
+ // (all linux-x64); keeps the standalone lean for every deploy.
+ "./node_modules/@img/sharp-darwin-*",
+ "./node_modules/@img/sharp-win32-*",
+ ],
+ },
};
export default nextConfig;
diff --git a/package-lock.json b/package-lock.json
index ab0c20d..616b479 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -38,6 +38,7 @@
"zustand": "^5.0.6"
},
"devDependencies": {
+ "@netlify/plugin-nextjs": "^5.16.5",
"@opennextjs/cloudflare": "^1.0.0",
"@playwright/test": "^1.64.1",
"@tailwindcss/postcss": "^4",
@@ -3234,6 +3235,16 @@
"@emnapi/runtime": "^1.7.1 || 2.0.0-beta.2"
}
},
+ "node_modules/@netlify/plugin-nextjs": {
+ "version": "5.16.5",
+ "resolved": "https://registry.npmjs.org/@netlify/plugin-nextjs/-/plugin-nextjs-5.16.5.tgz",
+ "integrity": "sha512-pt0j/YCZr5Kn2ziGS4Ps+RvREEn5LN2M9iv9iqEgNWZGb4esu7MCMy4RIYS0UR3JuBHxVtsvPHo0gEv+RKFpag==",
+ "dev": true,
+ "license": "MIT",
+ "engines": {
+ "node": ">=18.0.0"
+ }
+ },
"node_modules/@next/env": {
"version": "16.4.3",
"resolved": "https://registry.npmjs.org/@next/env/-/env-16.4.3.tgz",
diff --git a/package.json b/package.json
index 38cc928..ab719d2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "canvix",
- "version": "0.9.3",
+ "version": "0.9.4",
"private": false,
"description": "Canvix — free & open-source graphic design tool. A community-built Canva alternative.",
"scripts": {
@@ -56,6 +56,7 @@
"zustand": "^5.0.6"
},
"devDependencies": {
+ "@netlify/plugin-nextjs": "^5.16.5",
"@opennextjs/cloudflare": "^1.0.0",
"@playwright/test": "^1.64.1",
"@tailwindcss/postcss": "^4",
diff --git a/research/DEPLOYMENT-VERIFICATION.md b/research/DEPLOYMENT-VERIFICATION.md
new file mode 100644
index 0000000..02b0f30
--- /dev/null
+++ b/research/DEPLOYMENT-VERIFICATION.md
@@ -0,0 +1,140 @@
+# Canvix — Deployment Verification Report (v0.9.4)
+
+Date: 2026-10-29 · Scope: full-stack deploy readiness against the **live
+Supabase database** on every supported platform, plus the Netlify port.
+
+The database under test: Supabase transaction pooler
+(`aws-0-ap-southeast-2.pooler.supabase.com:6543`, PostgreSQL 17.11) —
+the same URL style every platform must use (serverless functions have no
+IPv6 route to the direct endpoint).
+
+## 1. Database — connects perfectly
+
+`scripts/verify-deploy-readiness.ts` (new; reusable pre-deploy gate):
+
+| Check | Result |
+|---|---|
+| Connect + server version | ✓ PostgreSQL 17.11 (aarch64) |
+| Migrations | ✓ 0001_init, 0002_accounts, 0003_anon_attribution all applied |
+| Tables | ✓ User, Session, Design, DesignEvent, Template |
+| Columns | ✓ Design.ownerId, Design.anonKey, User.passwordHash, Session.expiresAt |
+| Indexes | ✓ Design_pkey, Design_ownerId_idx, Design_anonKey_idx |
+| Data | ✓ 110 templates · 1304 designs · 35 users · 6611 events |
+| Parameterized queries | ✓ through the transaction pooler (pgbouncer discipline holds) |
+
+Auto-normalization confirmed on every connection: Supabase-pooler URLs
+get `sslmode=require` + `pgbouncer=true&connection_limit=1` injected
+(`src/lib/db-url.ts`), and the pg layer translates `sslmode=require` →
+`no-verify` (node-postgres treats `require` as verify-full, which rejects
+Supabase's pooler CA chain).
+
+One sandbox gotcha worth recording: a stale `DATABASE_URL` exported in
+the shell (an SQLite `file:` path) silently overrides `.env` for the
+Prisma CLI and the standalone server — when the CLI says "the URL must
+start with the protocol postgresql://", check `echo $DATABASE_URL`
+first. The app itself is unaffected when the URL is passed explicitly
+or the variable is unset.
+
+## 2. Production Node standalone (the self-host / Vercel-equivalent path)
+
+`npm run build` → `PORT=3100 NODE_ENV=production node
+.next/standalone/server.js` with the live `DATABASE_URL`:
+
+| Route | Result |
+|---|---|
+| `/api/health` | `{"ok":true,…,"templates":110}` |
+| `/` (landing) | 200 in ~18 ms |
+| `/api/templates` | 200, full 110-template list |
+| `/api/designs` | 200, list with thumbnails (1304 rows' DB) |
+| `/api/auth/me` (anonymous) | `{"user":null}` |
+| `POST /api/mcp` (no AI provider) | 503 — documented degradation, not a crash |
+| SSE `/api/collab/<id>/stream` | events stream live from the event log |
+| `POST /api/auth/register` + login | user created, session cookie set |
+| Cross-origin `POST /api/designs` | 403 — CSRF same-origin enforcement works |
+
+Probe rows (the `deployprobe` user) were deleted afterwards.
+
+## 3. Cloudflare Workers
+
+- `opennextjs-cloudflare build`: ✓
+- `wrangler deploy --dry-run`: **2.13 MB gzipped** (free-plan limit 3 MB)
+- `wrangler dev` (workerd) preview: landing 200, static assets served,
+ `/api/auth/me` works, health returns the **structured** 503 with no
+ uncaught exceptions in the log — exactly the documented local-dev TLS
+ limitation (`research/CLOUDFLARE-WORKERS-PORTABILITY.md`); the real
+ deployment remains the verification path for the DB leg:
+ `npx wrangler secret put DATABASE_URL` → `npm run deploy` →
+ `/api/health` on the workers.dev URL. Hyperdrive is the fallback if a
+ real deployment ever shows the same connect failure.
+
+## 4. Netlify (new in v0.9.4)
+
+Adapter: Netlify's OpenNext-based Next.js runtime
+(`@netlify/plugin-nextjs` 5.16.5, pinned in devDependencies + declared in
+`netlify.toml`). Node 22 for builds; functions run on AWS Lambda with a
+full Node API surface — scrypt auth, `pg` sockets and `sharp` all native.
+
+`npx netlify-cli build --offline` (no account needed) runs the exact
+pipeline: build command, functions bundling, edge-functions bundling, all
+plugin lifecycle events — **completed clean**.
+
+### The 50 MB problem and the fix
+
+The first offline build produced a **70.4 MB zipped** server-handler
+function (166.7 MB unzipped) — over Netlify's 50-MB-zipped limit.
+Forensics on the zip: the traced `@prisma/client` shipped ~90 MB of wasm
+the patched client provably never loads, **twice** (nft's copy under
+`node_modules/` and Turbopack's hashed copy under
+`.next/node_modules/@prisma/client-2c3a283f134fdcb6/`):
+
+- `*wasm-base64*` — base64-embedded query compilers for postgresql,
+ mysql, sqlite, sqlserver, cockroachdb (≈2.6 MB each, .js + .mjs)
+- `query_engine_bg*` — the old library-engine wasm, dead with
+ `engineType = "client"`
+- `query_compiler_bg.{mysql,sqlite,sqlserver,cockroachdb}.*` — other
+ dialects' JS wrappers (the datasource is postgresql, fixed at generate
+ time)
+
+Proof of safety: the patched loader
+(`scripts/patch-prisma-wasm.mjs`) only ever ESM-imports the raw `.wasm`
+(workerd branch) or reads it from disk (Node/Bun branch), and a repo-wide
+grep shows **no file imports any `*wasm-base64*` module**.
+
+`outputFileTracingExcludes` in `next.config.ts` now removes exactly the
+dead files (plus sharp's darwin/win32 binaries), keeping the live ones
+(postgresql wrappers, `raw.wasm`, `wasm-module.mjs`).
+
+| Artifact | Before | After | Limit |
+|---|---|---|---|
+| Netlify function zip | 70.4 MB | **20.8 MB** | 50 MB zipped / 250 MB unzipped (52.0 MB now) |
+| Cloudflare worker | 2.13 MB gz | **2.13 MB gz** | 3 MB |
+| Node standalone | ~166 MB | ~52 MB | — |
+
+Verified after the diet: standalone boots against the live DB (health,
+designs, templates green); workerd preview unchanged; the Netlify zip
+still contains the raw wasm + wasm-module loader in both traced copies;
+full gate 232/232 tests, tsc clean, eslint clean.
+
+### Deploying for real (free)
+
+1. Push the repo to GitHub → Netlify UI → *Add new site → Import an
+ existing project* (build settings come from `netlify.toml`).
+2. *Site settings → Environment variables* → `DATABASE_URL` = the
+ transaction-pooler URL (optionally `ZAI_BASE_URL` / `ZAI_API_KEY`).
+3. Deploy → open `/api/health` — `{"ok":true}` = full stack green.
+
+## 5. What still needs a real account (and is one command each)
+
+This sandbox has no Cloudflare/Netlify/Vercel credentials, so the last
+mile — hitting each platform's live infrastructure — is documented
+instead of executed:
+
+- **Cloudflare Workers**: `npx wrangler secret put DATABASE_URL` →
+ `npm run deploy` → `/api/health` on `https://canvix.<you>.workers.dev`
+- **Netlify**: UI import + one env var (above)
+- **Vercel**: repo import + `DATABASE_URL` (already the documented
+ default path; `postinstall` regenerates the Prisma client on every
+ build — the v0.9.1 Vercel cache fix)
+
+Everything below that last mile is verified green: same codebase, same
+database, three platforms' build pipelines exercised end-to-end.
diff --git a/scripts/verify-deploy-readiness.ts b/scripts/verify-deploy-readiness.ts
new file mode 100644
index 0000000..7df93aa
--- /dev/null
+++ b/scripts/verify-deploy-readiness.ts
@@ -0,0 +1,82 @@
+// scripts/verify-deploy-readiness.ts — one-shot deployment readiness check
+// Verifies: migrations applied, schema matches Prisma models, core row counts,
+// connection-string normalization parity across runtimes.
+// Usage: npx tsx scripts/verify-deploy-readiness.ts <DATABASE_URL>
+import { createScriptClient } from '../src/lib/db-script'
+
+async function main() {
+ const url = process.argv[2] ?? process.env.DATABASE_URL
+ if (!url) {
+ console.error('✗ no DATABASE_URL given')
+ process.exit(1)
+ }
+ const db = createScriptClient(url)
+ const pass = (label: string, detail: string) => console.log(`✓ ${label} — ${detail}`)
+ const fail = (label: string, detail: string) => {
+ console.error(`✗ ${label} — ${detail}`)
+ process.exitCode = 1
+ }
+ try {
+ // 1. server version
+ const [ver] = await db.$queryRawUnsafe('SELECT version()::text AS v') as Array<{ v: string }>
+ pass('connect', ver.v.split(',')[0])
+
+ // 2. migrations applied
+ const migrations = await db.$queryRawUnsafe<{ migration_name: string; finished_at: string }[]>(
+ `SELECT migration_name::text, finished_at::text FROM "_prisma_migrations" ORDER BY finished_at`,
+ )
+ const names = migrations.map((m) => m.migration_name)
+ for (const want of ['0001_init', '0002_accounts', '0003_anon_attribution']) {
+ if (names.includes(want)) pass('migration', `${want} applied (${migrations.find((m) => m.migration_name === want)?.finished_at ?? '?'})`)
+ else fail('migration', `${want} MISSING`)
+ }
+
+ // 3. schema completeness (tables + key columns the v0.9.x code depends on)
+ const tables = await db.$queryRawUnsafe<{ table_name: string }[]>(
+ `SELECT table_name::text FROM information_schema.tables WHERE table_schema='public'`,
+ )
+ const tableNames = tables.map((t) => t.table_name)
+ for (const want of ['User', 'Session', 'Design', 'DesignEvent', 'Template']) {
+ if (tableNames.includes(want)) pass('table', `${want} present`)
+ else fail('table', `${want} MISSING`)
+ }
+ const cols = await db.$queryRawUnsafe<{ table_name: string; column_name: string }[]>(
+ `SELECT table_name::text, column_name::text FROM information_schema.columns WHERE table_schema='public' AND table_name IN ('Design','User','Session')`,
+ )
+ const colKey = new Set(cols.map((c) => `${c.table_name}.${c.column_name}`))
+ for (const want of ['Design.ownerId', 'Design.anonKey', 'User.passwordHash', 'Session.expiresAt']) {
+ if (colKey.has(want)) pass('column', `${want} present`)
+ else fail('column', `${want} MISSING`)
+ }
+
+ // 4. row counts + indexes the app relies on
+ const [counts] = await db.$queryRawUnsafe(
+ `SELECT (SELECT COUNT(*)::int FROM "Template") AS templates, (SELECT COUNT(*)::int FROM "Design") AS designs,
+ (SELECT COUNT(*)::int FROM "User") AS users, (SELECT COUNT(*)::int FROM "Session") AS sessions,
+ (SELECT COUNT(*)::int FROM "DesignEvent") AS events`,
+ ) as Array<{ templates: number; designs: number; users: number; sessions: number; events: number }>
+ pass('data', `templates=${counts.templates} designs=${counts.designs} users=${counts.users} sessions=${counts.sessions} events=${counts.events}`)
+ if (counts.templates !== 110) fail('templates', `expected 110, got ${counts.templates}`)
+
+ const idx = await db.$queryRawUnsafe<{ indexname: string }[]>(
+ `SELECT indexname::text FROM pg_indexes WHERE schemaname='public' AND tablename='Design'`,
+ )
+ const idxNames = idx.map((i) => i.indexname)
+ pass('indexes', idxNames.join(', ') || '(none)')
+
+ // 5. transaction-pooler discipline: prepared statements must not be used.
+ // A $1-placeholder query through the app client proves the pgbouncer
+ // compatibility path works (the driver deduplicates named statements).
+ const [param] = await db.$queryRawUnsafe('SELECT $1::int AS n', 7) as Array<{ n: number }>
+ if (param.n === 7) pass('parameterized query', 'works through pooler')
+ else fail('parameterized query', `got ${param.n}`)
+
+ console.log('\nDeploy-readiness: ' + (process.exitCode ? 'FAILED' : 'ALL GREEN'))
+ } catch (e) {
+ console.error('✗ fatal — ' + (e as Error).message)
+ process.exitCode = 1
+ } finally {
+ await db.$disconnect()
+ }
+}
+main()