AI Playground is now organized as a product-style client-server app instead of a frontend-only AI demo.
- Frontend app:
/(Vite + React) - Backend API:
/server(Node.js + Express + MongoDB) - Architecture notes:
/docs/ARCHITECTURE.md
- Install dependencies:
npm install
- Create env:
Set
cp .env-example .env
VITE_GOOGLE_CLIENT_ID(Google Cloud OAuth Web client ID — same value as serverGOOGLE_CLIENT_ID).VITE_API_BASE_URLcan stay empty for local dev (Vite proxies/apito the backend). - Run frontend:
npm run dev
Frontend runs at http://localhost:5173.
- Install backend dependencies:
npm --prefix server install
- Create backend env:
Set
cp server/.env-example server/.env
GOOGLE_CLIENT_ID(same as frontend),JWT_SECRET,MONGODB_URI, and optionallyGEMINI_API_KEY. - Run backend:
npm run server:dev
Backend runs at http://localhost:8080 with health check at /health.
- Creative Quest: mission-based drawing + AI scoring + XP
- Artful Guesswork: free drawing + AI object guessing feedback
- Story Builder: drawing-driven chapter generation and progression
- Leaderboard API: top players by XP/level
- Backend owns AI orchestration and progression scoring
- Missions are generated by AI with user profile context (age group, skill level, level)
- Zod payload validation on AI endpoints
- MongoDB persistence for users, drawings, and stories
- Server-side Google Sign-In + JWT auth (no Firebase client SDK on frontend)
- Security headers with Helmet
- Structured request logs with Morgan
- Frontend API layer (
src/lib/api.js) with token forwarding - Vite API proxy for local development
npm run dev- run frontendnpm run build- frontend production buildnpm run preview- preview frontend buildnpm run server:dev- run backend in watch modenpm run server:start- run backend in standard mode
POST /api/v1/auth/google— exchange Google ID token for app JWTGET /api/v1/users/me— current user profile (auth required)GET /api/v1/gallery— art gallery from MongoDB drawings/storiesPOST /api/v1/drawings/:id/feedback— guesswork correct/incorrect feedbackPOST /api/v1/ai/creative-quest/submitPOST /api/v1/ai/guesswork/submitPOST /api/v1/ai/stories/chapterGET /api/v1/leaderboard
Yes — you can host frontend + backend in one Vercel project from this repo. The layout is a lightweight monorepo (/ = Vite client, /server = Express API).
| Part | Vercel target |
|---|---|
| React app | Static build from dist/ (Vite) |
| Express API | Serverless function at api/index.mjs |
| Routes | /api/* and /health → API; everything else → SPA |
Local dev is unchanged: npm run dev + npm run server:dev.
- Push the repo to GitHub and import it in Vercel.
- Leave Root Directory as
.(repo root). - Vercel reads
vercel.json— install, build, and rewrites are already configured. - Add Environment Variables in the Vercel project (Production + Preview):
| Variable | Required | Notes |
|---|---|---|
MONGODB_URI |
Yes | MongoDB Atlas connection string |
MONGODB_DB_NAME |
No | Default ai_playground |
GOOGLE_CLIENT_ID |
Yes | Same OAuth Web client ID as frontend |
JWT_SECRET |
Yes | Long random secret |
GEMINI_API_KEY |
No | Mock AI works without it |
VITE_GOOGLE_CLIENT_ID |
Yes | Same as GOOGLE_CLIENT_ID |
VITE_API_BASE_URL |
No | Leave empty for same-origin /api |
CLIENT_ORIGIN |
No | Auto-set from VERCEL_URL if omitted |
NODE_ENV |
No | Set production in Production |
- In Google Cloud Console, add your Vercel URL to OAuth Authorized JavaScript origins (e.g.
https://your-app.vercel.app). - Deploy. Test
https://your-app.vercel.app/healthand sign-in.
- AI routes call Gemini and may take 10–30s. Hobby plan functions timeout at 10s; Pro allows up to 60s (
maxDurationinvercel.json). Upgrade or move AI-heavy workloads to Railway/Render if you hit timeouts. - MongoDB Atlas must allow Vercel IPs (use
0.0.0.0/0or Atlas Serverless). socket.iois listed in server deps but not used — safe to ignore on Vercel.- For a separate API-only Vercel project, point root to
server/and use only theapi/handler pattern (frontend would setVITE_API_BASE_URL).
npm i -g vercel
vercelBackend (server/.env):
MONGODB_URI— requiredGOOGLE_CLIENT_ID+JWT_SECRET— required for sign-inGEMINI_API_KEY— optional (mock AI responses work without it)
Frontend (.env in project root):
VITE_GOOGLE_CLIENT_ID— same OAuth Web client ID as serverVITE_API_BASE_URL— empty locally (Vite proxy); set to your API URL in production