A modern React application that uses AI (Gemini) to generate React components based on natural language descriptions. Features include user authentication, session management, real-time chat with AI, and live component preview.
- 🔐 User Authentication - Sign up and login with email/password
- 💬 AI Chat Interface - Natural language component generation
- 🎨 Live Preview - See generated components in real-time
- 📝 Code Editor - Edit JSX and CSS with syntax highlighting
- 💾 Session Management - Save and manage your component sessions
- 📱 Responsive Design - Works on desktop and mobile devices
- Node.js with Express.js
- MongoDB with Mongoose ODM
- JWT for authentication
- Google Gemini AI for code generation
- React with Vite
- Modern CSS with Flexbox/Grid
- Real-time preview of generated components
- Node.js (v16 or higher)
- MongoDB database (local or cloud)
- Google Gemini API key
git clone <repository-url>
cd Component_generatorcd server
npm installCreate a .env file in the server directory:
MONGO_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret_here
PORT=3000
GEMINI_API_KEY=your_gemini_api_key_here- Go to Google AI Studio
- Create a new API key
- Copy the key and paste it in your
.envfile
npm start
# or
node server.jsThe server will run on http://localhost:3000
cd frontend
npm installnpm run devThe frontend will run on http://localhost:5173
POST /api/auth/signup- User registrationPOST /api/auth/login- User loginGET /api/auth/me- Get current user
GET /api/sessions- Get all user sessionsPOST /api/sessions- Create new sessionPUT /api/sessions/:id- Update sessionDELETE /api/sessions/:id- Delete session
POST /api/ai/generate- Generate component from prompt
- Sign Up/Login: Create an account or login with existing credentials
- Create Session: Start a new session to begin generating components
- Chat with AI: Describe the component you want in natural language
- Preview: Switch to the Preview tab to see your component in action
- Edit Code: Modify the generated JSX and CSS in the code editor
- Save: Your changes are automatically saved to the session
- "Create a button component with hover effects"
- "Make a card component with image and description"
- "Generate a navigation bar with logo and menu items"
- "Create a form with input fields and submit button"
- "Make a responsive grid layout for a portfolio"
Component_generator/
├── server/
│ ├── config/
│ │ └── db.js
│ ├── controllers/
│ │ ├── authController.js
│ │ ├── sessionController.js
│ │ └── aiController.js
│ ├── middleware/
│ │ └── authMiddleware.js
│ ├── models/
│ │ ├── User.js
│ │ └── Session.js
│ ├── routes/
│ │ ├── auth.js
│ │ ├── sessions.js
│ │ └── ai.js
│ ├── utils/
│ │ └── generateToken.js
│ ├── server.js
│ └── package.json
└── frontend/
├── src/
│ ├── App.jsx
│ ├── App.css
│ └── main.jsx
└── package.json
-
Server not starting
- Check if MongoDB is running
- Verify your
.envfile has all required variables - Ensure port 3000 is not in use
-
AI not generating components
- Verify your Gemini API key is correct
- Check the server logs for API errors
- Ensure you have sufficient API quota
-
Frontend not connecting to backend
- Verify the server is running on port 3000
- Check CORS settings in server.js
- Ensure the API_BASE URL is correct in App.jsx
If you encounter issues:
- Check the browser console for frontend errors
- Check the server console for backend errors
- Verify all environment variables are set correctly
- Ensure all dependencies are installed
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the MIT License.