A powerful CLI tool that generates customizable form components for Next.js applications with built-in features like server actions, API routes, Zod validation, and MongoDB integration.
- π¨ Multiple form styles (Default, Card, Inline)
- π Server Actions support for App Router
- π£οΈ API Routes for Pages Router
- β¨ TypeScript support
- π― Zod validation schema generation
- πΎ MongoDB integration
- π¨ Custom color theming
- π± Responsive design
- β‘ Loading states
- β Error handling
- π Optional link integration
- π¨ Custom styling and alignment options
# Clone the repository
git clone nextjs-shadcn-zod-form-generator-cli-based
cd nextjs-shadcn-zod-form-generator-cli-based
# Install dependencies
npm install
# Run
node index.js
-
Basic Form Settings
- Form name
- Number of input fields
- Number of buttons
- Submit button selection
-
Input Field Configuration
- Field name
- Label
- Placeholder
- Input type (text, email, password, number, date, tel, url, textarea)
- Validation rules
- Custom error messages
-
Button Configuration
- Button name
- Variant (default, destructive, outline, secondary, ghost, link)
-
Layout Options
- Form style (Default, Card, Inline)
- Horizontal alignment (Left, Center, Right)
- Vertical alignment (Top, Center, Bottom)
- Custom form width
- Custom colors
-
Advanced Features
- Router type (App Router / Pages Router)
- Server Actions support
- API route generation
- TypeScript integration
- MongoDB database integration
- Loading states
- Error handling
- Success/Error messages
The tool generates the following files in the generated-form
directory:
generated-form/
βββ [routerType]/
β βββ YourForm.tsx
β βββ YourFormAction.ts (if using Server Actions)
βββ api/
β βββ YourForm.ts (or route.ts for App Router)
βββ lib/
β βββ mongodb.ts (if using MongoDB)
βββ YourFormSchema.ts
βββ YourFormConfig.json
$ node index.js
? What is the name of your form? ContactForm
? How many input fields do you want in your form? 3
? How many buttons do you want in your form? 2
? Which button should be the submit button? 1
...
After generating the form, install the required dependencies:
npm install react-hook-form @hookform/resolvers zod
npx shadcn@latest init
npx shadcn@latest add form input button
For MongoDB integration:
npm install mongodb
If using MongoDB, add to your .env
file:
MONGODB_URI=your_mongodb_connection_string_here
ISC
Contributions are welcome! Please feel free to submit a Pull Request.