How techwithemmayt/advanced-ai-formy-builder-drag-n-drop works
Project Type and Purpose
• This is a full-stack, AI-powered form-builder web application built with Next.js 14.
• Users log in (Kinde), drag-and-drop to build forms, leverage AI to generate fields, save/publish forms, collect responses, and view analytics.
Main System Components
A. Client (Web Browser)
• Next.js App Router pages under app/(routes) (Landing, Dashboard, Public form‐submit).
• React/TSX UI components in components/ and Shadcn UI.
• TailwindCSS styling.
B. Next.js Server (Node.js runtime on Vercel)
1. Routing & Rendering
• Server‐rendered pages + Client-side navigation.
• Nested routes for /dashboard, /public/submit-form, etc.
2. Server Actions / API Routes (app/api/* & actions/form.action.ts)
• Form CRUD, fetchFormById, auth callbacks.
3. Business Logic
• lib/ (helper functions, Google-AI integration, prompts).
• context/ (BuilderProvider for drag/drop state).
• hooks/ (use-toast, use-mobile).
4. Authentication
• Kinde OAuth endpoints in app/api/auth/[kindeAuth]/route.ts.
5. Data Layer
• Prisma ORM (lib/prismadb.ts) + prisma/schema.prisma connecting to Neon PostgreSQL.
C. Database
• Neon PostgreSQL (Primary & Pooler connections).
• Prisma migrations & seeding (prisma/seed.ts).
D. External Services
• Kinde for authentication.
• Google/Gemini API for AI-powered form generation.
Component Interactions and Dataflows
• Client → Next.js Page: user visits /dashboard.
• Page invokes Server Action (saveForm, publishForm) → Business Logic in actions/ → Prisma → Neon DB.
• For AI generation: Server Action calls lib/google-ai.ts → Google API → returns generated blocks → persisted.
• Auth: Client redirects to Kinde → callback to Next.js API → session established.
• Public form submit: Client POST to app/api/fetchFormById → DB reads and server returns form schema.
• Analytics: Dashboard page fetches response counts via server action/Prisma.
Architectural Patterns & Principles
• App Router & Nested Routing → clear page segmentation.
• Server Actions for co-located UI & server code (no separate Express).
• Context Provider pattern for in-page state (form builder).
• MVC-like layering: UI → Actions (Controller) → lib/Business Logic → ORM (Model) → DB.
• Type-safe contracts (@types, TS throughout).