A comprehensive form builder application built with Next.js, TypeScript, and PostgreSQL.
- Dynamic Form Creation: Create forms with various field types (text, select, checkbox, date).
- Flexible Validation: Configure validation rules for each field.
- Form Submissions: Submit and view form responses with built-in validation.
- Database Persistence: Store all data in a PostgreSQL database.
- Responsive Design: Optimized for both desktop and mobile devices.
- Node.js 18+
- Supabase account and project
- Clerk account for authentication
-
Clone the repository:
git clone <your-repo-url> cd form-builder
-
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env.local
Edit
.env.localand add your configuration:# Supabase Configuration NEXT_PUBLIC_SUPABASE_URL=your-supabase-project-url NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key SUPABASE_SERVICE_ROLE_KEY=your-supabase-service-role-key # Clerk Authentication NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your-clerk-publishable-key CLERK_SECRET_KEY=your-clerk-secret-key -
Set up the database: Run the SQL migration scripts in your Supabase SQL editor:
- First run
scripts/supabase-migration.sqlto create the base tables - Then run
scripts/003-simple-auth.sqlto set up authentication and sharing
- First run
-
Run the development server:
npm run dev
Open http://localhost:3000 in your browser to view the application.
├── app/ # Next.js App Router pages
│ ├── api/ # API routes
│ │ └── forms/ # Form-related API endpoints
│ ├── create/ # Form creation page
│ ├── forms/ # Form viewing and management pages
│ ├── sign-in/ # Authentication pages
│ ├── sign-up/ # User registration
│ ├── submit/ # Public form submission pages
│ ├── fonts/ # Custom fonts
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout with authentication
│ └── page.tsx # Home page
├── components/ # React components
│ ├── ui/ # shadcn/ui components
│ ├── form-builder.tsx # Form creation interface
│ ├── form-renderer.tsx # Form display and submission
│ └── submissions-viewer.tsx # View form submissions
├── lib/ # Utility functions
│ ├── supabase/ # Supabase configuration
│ │ ├── client.ts # Client-side Supabase client
│ │ ├── server.ts # Server-side Supabase client
│ │ └── types.ts # Generated database types
│ ├── types.ts # TypeScript type definitions
│ ├── db.ts # Database connection (legacy)
│ ├── utils.ts # Utility functions
│ └── validation.ts # Form validation logic
├── scripts/ # Database migration scripts
│ ├── supabase-migration.sql # Main Supabase migration
│ ├── 002-add-authentication.sql # Authentication setup
│ ├── 003-simple-auth.sql # Simplified auth with share IDs
│ └── update-existing-tables.sql # Schema updates
├── middleware.ts # Clerk authentication middleware
└── public/ # Static assets
- Text Input: Supports minimum and maximum length validation.
- Dropdown Select: Configurable options.
- Checkbox: Provides boolean true/false values.
- Date Picker: Supports constraints for past or future dates.
GET /api/forms- List all forms for authenticated user.POST /api/forms- Create a new form (requires authentication).GET /api/forms/[id]- Retrieve a specific form (requires authentication).GET /api/forms/[id]/public- Retrieve a public form by share ID (no authentication).GET /api/forms/[id]/submissions- Retrieve form submissions (requires authentication).POST /api/forms/[id]/submissions- Submit form data (public endpoint).
id- UUID primary key.name- Form name.description- Optional description.user_id- Foreign key linking to authenticated user.share_id- Unique identifier for public sharing.created_at- Creation timestamp.updated_at- Last update timestamp.
id- UUID primary key.form_id- Foreign key linking to the forms table.name- Field name (used for data keys).label- Display label for the field.type- Field type (text, dropdown, checkbox, date).required- Whether the field is required.validation_config- JSON containing validation rules.field_config- JSON containing field-specific configuration.field_order- Order of the field in the form.
id- UUID primary key.form_id- Foreign key linking to the forms table.data- JSON containing the form submission.created_at- Submission timestamp.
To add new field types:
- Update the
FormFieldtype inlib/types.ts. - Incorporate rendering logic in
components/form-renderer.tsx. - Implement validation logic in
lib/validation.ts. - Create configuration UI in
components/form-builder.tsx.
MIT License