AI‑assisted form builder built with Next.js. Generate forms from natural language, customize with a drag‑and‑drop builder, publish multi‑page forms, collect submissions, and manage billing.
Production URL: https://formcraftai.avikmukherjee.me
- AI form generation: Uses Google Gemini to generate a form schema from a prompt (
/api/form/ai). - Drag‑and‑drop builder: Reorder fields and pages via
@dnd-kitwith live previews. - Multi‑page forms: Create and navigate multiple pages per form.
- Conditional logic: Show/hide fields based on other field values.
- Validation: Required and custom validators per field type.
- Theming and styles: Dark theme, font picker (Google Fonts), custom colors.
- Submissions + export: Store responses and export CSV in dashboard.
- Templates: Seed demo templates for quick starts.
- Auth & access control: Protected routes via Clerk and middleware.
- Billing: Paid plan via Polar (
/checkout, customer portal, webhooks).
- App: Next.js 15 (App Router), React 19, TypeScript
- UI: Tailwind CSS v4, Radix UI, Lucide
- State/Data: Zustand, React Hook Form, TanStack Query
- Charts: Recharts
- DB: MongoDB with Mongoose
- Auth: Clerk
- AI: Google Generative AI (Gemini)
- Billing: Polar
- Node.js 20+ (LTS recommended)
- MongoDB (local or hosted)
- Accounts/keys for: Clerk, Google AI Studio (Gemini), Polar
git clone https://github.com/Avik-creator/formcraftAI.git
cd formcraftai
bun i # or: pnpm i | yarn | bun installCreate a .env.local in the project root:
# App
NEXT_PUBLIC_APP_URL=http://localhost:3000
NODE_ENV=development
# Database
DB_URL=mongodb://localhost:27017/vi-forms
# Auth (Clerk)
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxx
CLERK_SECRET_KEY=sk_test_xxx
# Google Generative AI (Gemini)
GEMINI_API_KEY=your_gemini_api_key
# Google Fonts (optional; falls back to curated list when absent)
GOOGLE_FONTS_API_KEY=your_fonts_api_key
# Polar (billing)
POLAR_ACCESS_TOKEN=pol_...
POLAR_WEBHOOK_SECRET=whsec_...
POLAR_SUCCESS_URL=http://localhost:3000/success
NEXT_PUBLIC_POLAR_PRO_PRODUCT_ID=prod_...Notes:
DB_URLdefaults tomongodb://localhost:27017/vi-formsif missing.NEXT_PUBLIC_APP_URLis used for client links and should be your deployed URL in production.POLAR_SUCCESS_URLshould point to the app’s success page (/success).
bun run dev
# or: pnpm dev | yarn dev | bun devOpen http://localhost:3000.
Login/Signup pages are public. Authenticated users are redirected to '/dashboard' by middleware.
src/
app/ # App Router routes (pages, API, middleware)
api/
form/ai/ # AI generation endpoint
templates/seed/ # seed demo templates (auth‑protected)
webhook/polar/ # Polar billing webhooks
dashboard/ # authenticated dashboard (overview, forms, templates)
builder/ # form builder page
form/[formid]/ # public, published form rendering
checkout/ # Polar checkout handler route
backend/ # server actions, models, db connection
components/ # UI and feature components (builder, form, dashboard, ui)
data-fetching/ # TanStack Query hooks and server/client fetchers
hooks/ # custom hooks
lib/ # core form helpers (create/transform), utils
providers/ # React Query provider
types/ # Type definitions for forms and app
zustand/ # app state stores
Key files:
src/backend/db/connection.ts– Mongoose connection usingDB_URL.src/app/api/form/ai/route.ts– Gemini‑powered AI schema generation (auth required).src/app/checkout/route.ts– Polar Checkout handler.src/app/api/portal/route.ts– Polar Customer Portal (maps Clerk user → Polar customer).src/app/api/webhook/polar/route.ts– Polar webhooks to sync plan state.src/middleware.ts– Route protection and redirects via Clerk.
Authenticated GET to seed starter templates:
GET /api/templates/seed
This clears existing templates and recreates from src/utils/data.ts using createNewForm defaults.
POST /api/form/ai
{
"prompt": "Create a job application form with name, email, resume upload and availability date"
}
Requires a signed‑in user. The endpoint returns a form config with createdBy set to the current user.
- Checkout:
GET /checkout(server route configured withPOLAR_ACCESS_TOKENandPOLAR_SUCCESS_URL). - Customer portal:
GET /api/portalreturns a signed portal URL for the current user. - Webhooks:
POST /api/webhook/polarupdatesUserBillingProfileon subscription/order events. Configure the same URL in your Polar dashboard and setPOLAR_WEBHOOK_SECRET.
- Public:
'/','/sign-in','/sign-up','/form/[formid]' - Protected: everything else (redirects unauthenticated users to
'/sign-in'). - Signed‑in users visiting
'/'or auth pages are redirected to'/dashboard'.
bun run dev # Start dev server (Turbopack)
bun run build # Production build
bun run start # Start production server
bun run lint # Lint- Recommended: Vercel.
- Set all environment variables in your hosting provider.
- Add Clerk callback URLs and allowed origins for your domain.
- Set
NEXT_PUBLIC_APP_URLto your production URL. - Configure Polar webhook to
https://<your-domain>/api/webhook/polarand success URL tohttps://<your-domain>/success.
- "Unauthorized" from API routes: ensure Clerk keys are set and you’re signed in.
- Mongo connection errors: verify
DB_URLand network/firewall settings. - Fonts list empty: set
GOOGLE_FONTS_API_KEYor rely on built‑in fallback. - Billing not updating: double‑check Polar webhook secret and that the webhook URL is reachable.
- Next.js, Clerk, Polar, Google Generative AI, Radix UI, TanStack Query, Zustand, Recharts, Tailwind CSS.
