A full-stack virtual try-on demo. Pick a garment, supply a photo of yourself, get back an AI-generated image of you wearing it.
Generation runs on FASHN VTON 1.5 / 1.6, a diffusion-based virtual try-on model, behind a swappable provider interface — a free Hugging Face Space for development, fal.ai for production, and a local sharp composite for offline UI work.
| Frontend | Next.js 16 (App Router, Turbopack), React 19, Tailwind v4, TanStack Query v5, Zustand, shadcn/ui |
| Backend | Express 5, TypeScript, Prisma 7, PostgreSQL 16, Zod 4, Multer, sharp, Winston |
| AI | FASHN VTON via @gradio/client (dev) or @fal-ai/client (prod) |
- Two engines, one router.
mode x category -> enginedecides how each product is tried on: FASHN diffusion for garments (server-side, ~25s) and MediaPipe face landmarking for eyewear (in-browser, instant, free). The engine is derived from a registry, never stored on a product. - Product page at
/product/[slug]— renders one try-on button per enabled mode, with no product-type branching anywhere in the component tree. - Live try-on — webcam sunglasses tracking at frame rate. MediaPipe WASM and the model are vendored, and no frame ever leaves the browser.
- Merchant dashboard at
/merchant— real try-on analytics plus per-product mode toggles. A mode with no engine renders disabled, with the reason. - Share card — one canvas composition for both engines; download or Web Share.
- Storefront at
/and the embedded product modal — the same engine on a second integration surface.
Two terminals. PostgreSQL runs in Docker.
# terminal 1 — backend on :5000
cd backend
npm install
docker compose up -d # PostgreSQL 16 on :5432
cp .env.example .env
npm run db:generate # required — the Prisma client is gitignored
npm run db:migrate
npm run db:seed # 8 products + 7 presets
npm run dev# terminal 2 — frontend on :3000
cd frontend
npm install
cp .env.example .env.local
npm run devOpen http://localhost:3000.
Playwright runs both projects. The backend needs Docker up, migrated and seeded.
cd backend && npm test # API + unit, one worker (shared database)
cd backend && npm run test:unit # pure functions, no server
cd frontend && npm test # chromium + mobile (Pixel 7)
cd frontend && npx playwright test --project=mobile
cd frontend && PW_DEV=1 npm run test:uiTests never call a real image provider — both configs start the backend with
TRYON_PROVIDER=mock, and /api/v1/health reports the active provider so a
stray dev server on the port fails loudly instead of timing out.
Frontend E2E runs against next build && next start rather than next dev:
dev-mode compiles routes on first request, and parallel workers hitting cold
routes stall it until proxied requests fail.
Out of the box .env.example sets TRYON_PROVIDER=gradio, which calls the free public Space and takes ~22–43s per image. For instant offline results while working on UI, set TRYON_PROVIDER=mock. Full walkthrough, every environment variable, and troubleshooting: docs/SETUP.md.
virtual-try-on/
├── frontend/ Next.js 16 App Router
├── backend/ Express 5 + Prisma 7 + PostgreSQL
└── docs/ project summary + setup guide
The root is not a workspace or monorepo — there is no root package.json. Run every command from inside frontend/ or backend/.
- docs/PROJECT_SUMMARY.md — what the project is, which AI model it uses, architecture, API surface, known limitations.
- docs/SETUP.md — prerequisites, environment variables, provider selection, commands, end-to-end verification, troubleshooting.
- CLAUDE.md — conventions and gotchas for anyone (or any agent) editing the code.
TRYON_TIMEOUT_MS(75s, server) must stay belowGIVE_UP_MS(90s,useTryOnJob.ts). Invert them and a slow job shows "taking longer than expected" while the generation is still about to succeed.TRYON_RATE_LIMIT_PER_HOUR(default 10) is global, not per-visitor — every request arrives through the Next.js proxy sharing one source address. Raise it before a demo.- The
falprovider's request field names have never been exercised against a live response. Verify at https://fal.ai/models/fal-ai/fashn/tryon/v1.6/api before first use. - Live try-on needs a secure context.
localhostqualifies; a LAN IP does not. The demo runs on an Android phone over an ngrok HTTPS tunnel, because the presenting machine has no camera. - Tunnel port 3000 only.
next.config.tsproxies/api/*and/uploads/*to the backend server-side, so the backend is never exposed. - MediaPipe assets are vendored in
frontend/public/mediapipe/on purpose. Loading them from Google's CDN would make the live feature depend on the network. - Only the judge-facing journey (storefront, product page, live stage, capture, share) is built for a phone.
/try-onand/merchantare desktop-only.