An intelligent survey generation tool that uses Google's Gemini AI to create customized healthcare survey forms based on natural language prompts.
- 🤖 AI-Powered Survey Generation: Generate survey forms using natural language prompts
- 📋 Multiple Field Types: Support for various input types including text, numbers, ratings, multiple choice, and more
- ✏️ Interactive Editor: Edit and customize generated survey fields with drag-and-drop reordering
- 📱 Responsive Design: Mobile-friendly interface built with Tailwind CSS
- 🎨 Modern UI: Built with shadcn/ui components and Radix UI primitives
- 🔗 Shareable Surveys: Generate unique URLs for each survey
- 🧩 Modular Architecture: Clean component structure for easy maintenance and customization
- 🔄 Real-time Preview: See changes instantly as you edit survey fields
- Framework: Next.js 15 with App Router
- Language: TypeScript
- Styling: Tailwind CSS v4
- UI Components: shadcn/ui + Radix UI
- AI Integration: Google Gemini AI
- Icons: Lucide React
Before you begin, ensure you have the following installed:
- Node.js (version 18.0 or later)
- npm, yarn, pnpm, or bun package manager
- Google Gemini API Key (get one from Google AI Studio)
git clone <repository-url>
cd ai-survey-builderChoose your preferred package manager:
# Using npm
npm ci
# Using yarn
yarn install --frozen-lockfile
# Using pnpm
pnpm install
# Using bun
bun installCreate a .env.local file in the root directory and add your Google Gemini API key:
# .env.local
GEMINI_API_KEY=your_gemini_api_key_hereTo get your Gemini API key:
- Visit Google AI Studio
- Sign in with your Google account
- Create a new API key
- Copy the key and paste it in your
.env.localfile
Start the development server:
# Using npm
npm run dev
# Using yarn
yarn dev
# Using pnpm
pnpm dev
# Using bun
bun devOpen http://localhost:3000 in your browser to see the application.
-
Enter a Prompt: Type a natural language description of the survey you want to create
- Example: "Create a survey for post-visit feedback at a dermatology clinic"
- Example: "Generate a customer satisfaction survey for a restaurant"
-
AI Generation: The application will use Google Gemini AI to generate appropriate survey fields
-
Edit Fields: Customize the generated fields using the interactive editor:
- Modify questions and descriptions
- Change field types (text, number, rating, multiple choice, etc.)
- Set required/optional status
- Configure field-specific options (max length, ranges, choices)
-
Save Survey: Save your completed survey template locally (for demo purposes, the data is not persisted, you should implement a backend for saving data if needed)
To load a previously created survey, click Load a template button and select a survey from the list. The application will populate the editor with the selected survey fields. Then you can edit or customize the fields as needed. (the data is not persisted, for demo purposes, there are two dummy templates initially available)
To share a survey, click Load a template button and click Share button next to the survey you want to share. This will copy the URL to your clipboard that you can share with others. They can access the survey using this URL and fill it out.
- Short Text (fieldType: 0): Single-line text input with optional max length
- Long Text (fieldType: 1): Multi-line textarea
- Number (fieldType: 2): Numeric input with optional range validation
- Yes/No (fieldType: 3): Boolean radio button selection
- Multiple Choice (fieldType: 4): Radio buttons or checkboxes with custom options
- Dropdown (fieldType: 5): Select dropdown with custom options
- Rating (fieldType: 6): 1-5 star rating slider
demo-survey/
├── app/
│ ├── [uuid]/ # Dynamic route for individual surveys
│ │ └── page.tsx
│ ├── api/ # API routes
│ │ ├── route.ts # Main API endpoint for AI generation
│ │ └── getGeminiParams.ts
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Main page
├── components/
│ ├── survey/ # Survey-related components
│ │ ├── SurveyGenerator.tsx # AI survey generation component
│ │ ├── TemplateDialog.tsx # Template selection dialog
│ │ ├── SurveyEditor.tsx # Survey editing interface
│ │ ├── FieldEditor.tsx # Individual field editor
│ │ ├── FieldTypeSelector.tsx # Field type selection dropdown
│ │ ├── SurveyPreview.tsx # Survey preview component
│ │ ├── SurveyField.tsx # Individual survey field renderer
│ │ └── index.ts # Component exports
│ └── ui/ # shadcn/ui components
├── lib/
│ ├── dummy-data.ts # Sample survey data
│ └── utils.ts # Utility functions
└── public/ # Static assets
The application has been refactored into modular, reusable components for better maintainability:
SurveyGenerator: Handles AI-powered survey generation from natural language promptsTemplateDialog: Manages template selection and sharing functionalitySurveyEditor: Main editing interface with drag-and-drop field managementFieldEditor: Individual field editing with type-specific configuration optionsFieldTypeSelector: Dropdown for selecting different field typesSurveyPreview: Real-time preview of the survey as users would see itSurveyField: Renders individual survey fields based on their type
Home Page (app/page.tsx)
├── SurveyGenerator
├── TemplateDialog
├── SurveyEditor
│ ├── FieldEditor (multiple instances)
│ │ └── FieldTypeSelector
│ └── Drag & Drop Context
└── SurveyPreview
└── SurveyField (multiple instances)
All survey components are exported from components/survey/index.ts for clean imports.
The application has been completely refactored from a monolithic structure to a modular component-based architecture:
- Before: All functionality was contained in a single 500+ line
page.tsxfile - After: Functionality is split into focused, reusable components in the
components/survey/directory
- Maintainability: Each component has a single responsibility
- Reusability: Components can be easily reused across different parts of the application
- Testing: Individual components can be tested in isolation
- Collaboration: Multiple developers can work on different components simultaneously
- Code Organization: Related functionality is grouped together
// Clean imports from the index file
import { SurveyGenerator, TemplateDialog, SurveyEditor, SurveyPreview } from '@/components/survey'Generates survey fields based on a natural language prompt.
Request Body:
{
"prompt": "Create a survey for post-visit feedback"
}Response:
[
{
"fieldType": 6,
"fieldLabel": "How would you rate your overall experience?",
"fieldDescription": "Please rate your visit from 1 to 5",
"requiredField": true
}
]npm run dev- Start development server with Turbopacknpm run build- Build the application for productionnpm run start- Start the production servernpm run lint- Run ESLint for code quality
- Update the
SurveyFieldinterface inapp/api/route.ts - Add the new field type to the
FieldTypeSelectorcomponent (components/survey/FieldTypeSelector.tsx) - Implement the field rendering in the
SurveyFieldcomponent (components/survey/SurveyField.tsx) - Add field-specific editing options in the
FieldEditorcomponent (components/survey/FieldEditor.tsx) - Update the AI prompt schema in
getGeminiParams.ts
The modular component structure makes it easy to customize specific parts:
- Survey Generation: Modify
SurveyGenerator.tsxto change the AI prompt interface - Field Editing: Update
FieldEditor.tsxto add new field configuration options - Preview Display: Customize
SurveyField.tsxto change how fields are rendered - Template Management: Modify
TemplateDialog.tsxto change template selection behavior
The project uses Tailwind CSS v4 with shadcn/ui components. Customize the theme by modifying:
app/globals.cssfor global stylescomponents.jsonfor shadcn/ui configuration- Individual component files for component-specific styles
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/new-feature) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- API Key Error: Ensure your
GEMINI_API_KEYis correctly set in.env.local - Build Errors: Make sure all dependencies are installed with
npm ci - TypeScript Errors: Run
npm run lintto identify and fix type issues
- Check the Next.js Documentation
- Visit shadcn/ui Documentation
- Review Google Gemini AI Documentation