FieldCraft is Cursor for Form Builders powered by Tambo AI, designed for the TamboHack. It uses Next.js, React, TypeScript, Tailwind CSS, and Zod for schema validation. This README will guide you through the architecture and file structure so you can replicate or extend the app.
FieldCraft enables dynamic, schema-driven form creation and rendering. Forms are defined using JSON objects validated by Zod schemas, and rendered as interactive UI components. The app supports multi-section forms, conditional logic, and extensible field types.
Defines the blueprint for each form field type using Zod.
- File:
src/lib/form-field-schemas.ts - Purpose: Centralized schema definitions for all supported field types and structural elements.
- Basic Fields:
text,email,password,number,checkbox,select,radio,textarea,date - Structural Elements:
group(for sections),divider(for visual separation)
The formFieldSchema allows for maximum flexibility in form layout:
// Individual fields at top level
const simpleForm = [
{ type: "text", label: "Name", name: "name" },
{ type: "email", label: "Email", name: "email" }
];
// Mixed structure with groups and individual fields
const complexForm = [
{ type: "text", label: "Title", name: "title" }, // Individual field
{ type: "divider", label: "Personal Information" }, // Visual separator
{
type: "group",
label: "Contact Details",
fields: [
{ type: "text", label: "Name", name: "name" },
{ type: "email", label: "Email", name: "email" }
]
},
{ type: "checkbox", label: "Subscribe", name: "subscribe" } // Another individual field
];Contains the JSON structure for each form instance.
- File:
src/lib/form-definitions.ts - Purpose: Stores the form layout, sections, fields, and conditional logic. Can be static or loaded dynamically. Serves as examples and default forms.
Builds composite Zod schemas and validates form data.
- File:
src/lib/form-validation.ts - Purpose: Maps form definitions to Zod schemas, validates user input, and handles errors.
Renders the form UI based on definitions and schemas.
- File:
src/components/form/form-renderer.tsx - Purpose: Dynamically generates React components for each field, section, and divider. Handles conditional rendering and user interaction.
- Flexible Rendering: Supports both grouped fields (within
fieldsetelements) and individual fields at the top level - Conditional Logic: Can show/hide sections based on field values
- Custom Buttons: Supports custom button configurations with different variants
- Responsive Design: Mobile-first design with dark mode support
- Error Handling: Graceful fallbacks for invalid form definitions
FieldCraft leverages Tambo AI for intelligent form generation:
- FormRenderer: Registered as a Tambo component in
src/lib/tambo.ts - AI-Driven: Forms can be generated dynamically based on natural language prompts
- Schema Validation: All AI-generated forms are validated against Zod schemas
- "Create a registration form for a work event"
- "Build a contact form with validation"
- "Generate an order form with multiple sections"
- "Create a multi-step user registration form with account setup, personal info, preferences, and review steps"
- "Build a product feedback form with multiple rating steps and recommendation section"
- "Generate a multi-step event registration form with ticket selection and payment"
- "Create a customer survey form with experience ratings and feedback collection"
- "Make a multi-step form for collecting user preferences across different categories"
-
Clone the repository and install dependencies:
git clone <your-repo-url> cd FieldCraft npm install
-
Run the development server:
npm run dev
-
Explore the core files:
- Edit or extend field schemas in
src/lib/form-field-schemas.ts - Define new forms in
src/lib/form-definitions.ts - Add validation logic in
src/lib/form-validation.ts - Customize rendering in
src/components/form/form-renderer.tsx
- Edit or extend field schemas in
- Define Schema: Add new field schema in
src/lib/form-field-schemas.ts - Update Union: Include in the
formFieldSchemaunion type - Add Component: Create rendering component in
src/components/form/form-renderer.tsx - Register Component: Add to
FieldComponentsobject
- Conditional Logic: Use
conditionproperties on groups or fields - Custom Validation: Extend validation logic in
form-validation.ts - Styling: Customize appearance using Tailwind CSS classes
- Accessibility: All components include proper ARIA labels and keyboard navigation
// Custom field type
const customFieldSchema = z.object({
type: z.literal("custom"),
label: z.string(),
name: z.string(),
customProperty: z.string().optional()
});
// Add to union
export const formFieldSchema = z.union([
// ... existing schemas
customFieldSchema
]);- Next.js 15
- React 19
- TypeScript
- Tailwind CSS v4
- Zod
- Tambo AI SDK
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License
FieldCraft was built for the TamboHack: For Your UI Only.