A full-stack web application that generates AI images from text prompts using React, Node.js, and ClipDrop API.
- Features
- Tech Stack
- Project Structure
- Installation
- Environment Variables
- API Endpoints
- Components Overview
- Authentication
- Credits System
- Usage
- Screenshots
- Contributing
- Author
- AI Image Generation: Convert text prompts to stunning images using ClipDrop API
- User Authentication: Secure registration and login with JWT tokens
- Credits System: Each user gets 5 free credits, with ability to purchase more
- Real-time Feedback: Toast notifications for all user actions
- Responsive Design: Works seamlessly on desktop and mobile devices
- Smooth Animations: Beautiful Framer Motion animations throughout the app
- Automatic Token Management: JWT tokens stored in localStorage with auto-refresh
- Credit Tracking: Real-time credit updates after image generation
- Download Functionality: Download generated images directly
- Protected Routes: Authentication required for image generation
- Error Handling: Comprehensive error handling with user-friendly messages
- Loading States: Beautiful loading animations during image generation
- React 19.1.0 - UI Framework
- Vite - Build tool and development server
- Tailwind CSS 4.1.11 - Styling and responsive design
- Framer Motion 12.23.12 - Animations and transitions
- React Router DOM 7.7.0 - Client-side routing
- Axios 1.11.0 - HTTP client for API calls
- React Toastify 11.0.5 - Toast notifications
- Node.js with Express 5.1.0 - Server framework
- MongoDB with Mongoose 8.17.0 - Database and ODM
- JWT (jsonwebtoken 9.0.2) - Authentication tokens
- bcrypt 6.0.0 - Password hashing
- CORS 2.8.5 - Cross-origin resource sharing
- dotenv 17.2.1 - Environment variable management
- ClipDrop API - AI image generation
- MongoDB Atlas - Cloud database
ImageGenrator/
โโโ Client/ # Frontend React application
โ โโโ public/ # Static assets
โ โ โโโ favicon.svg
โ โ โโโ vite.svg
โ โโโ src/
โ โ โโโ assets/ # Images, icons, and static files
โ โ โ โโโ logo.svg
โ โ โ โโโ profile_icon.png
โ โ โ โโโ credit_star.svg
โ โ โ โโโ [40+ other assets]
โ โ โโโ Components/ # Reusable React components
โ โ โ โโโ Navbar.jsx # Navigation with user info
โ โ โ โโโ Login.jsx # Authentication modal
โ โ โ โโโ Header.jsx # Hero section
โ โ โ โโโ Descrip.jsx # Description section
โ โ โ โโโ Steps.jsx # How it works section
โ โ โ โโโ Testimonials.jsx # User testimonials
โ โ โ โโโ GenrateBtn.jsx # Generate image button
โ โ โ โโโ Fotter.jsx # Footer component
โ โ โโโ Context/
โ โ โ โโโ AppContext.jsx # Global state management
โ โ โโโ Pages/ # Main application pages
โ โ โ โโโ Home.jsx # Landing page
โ โ โ โโโ Result.jsx # Image generation page
โ โ โ โโโ BuyCredit.jsx # Credit purchase page
โ โ โโโ App.jsx # Main app component
โ โ โโโ main.jsx # React entry point
โ โ โโโ index.css # Global styles
โ โโโ .env # Frontend environment variables
โ โโโ package.json # Frontend dependencies
โ โโโ vite.config.js # Vite configuration
โ โโโ tailwind.config.js # Tailwind CSS configuration
โโโ server/ # Backend Node.js application
โ โโโ Config/
โ โ โโโ Mongodb.js # Database connection
โ โโโ Controllers/ # Business logic
โ โ โโโ UserController.js # User authentication & credits
โ โ โโโ ImageController.js # Image generation logic
โ โโโ Middlewares/
โ โ โโโ Auth.js # JWT authentication middleware
โ โโโ Models/
โ โ โโโ UserModel.js # User data schema
โ โโโ Routes/ # API route definitions
โ โ โโโ UserRoutes.js # User-related endpoints
โ โ โโโ ImageRoutes.js # Image generation endpoints
โ โโโ .env # Backend environment variables
โ โโโ package.json # Backend dependencies
โ โโโ server.js # Express server entry point
โโโ readme.md # This file
- Node.js (v16 or higher)
- MongoDB Atlas account
- ClipDrop API key
git clone https://github.com/Praharsh7270/ImageGenrator.git
cd ImageGenratorcd server
npm installcd ../Client
npm installPORT=5000
MONGO_URI="your_mongodb_connection_string"
JWT_SECRET="your_jwt_secret_key"
CLIPDROP_api="your_clipdrop_api_key"VITE_BACKENDURL="http://localhost:5000"-
MongoDB Atlas:
- Create account at MongoDB Atlas
- Create cluster and get connection string
-
ClipDrop API:
- Sign up at ClipDrop
- Get your API key from dashboard
POST /api/user/register # Register new user
POST /api/user/login # User login
POST /api/user/credits # Get user credits (Protected)
POST /api/image/generateImage # Generate AI image (Protected)
// Request
POST /api/user/register
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}
// Response
{
"success": true,
"user": { ... },
"token": "jwt_token_here"
}// Request (with JWT token in headers)
POST /api/image/generateImage
Headers: { "token": "your_jwt_token" }
{
"prompt": "a beautiful sunset over mountains"
}
// Response
{
"success": true,
"image": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...",
"message": "Image generated successfully",
"resultImage": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA..."
}- Login.jsx: Modal with animated form for login/register
- Auth.js: JWT middleware for protected routes
- AppContext.jsx: Global state management for user data
- Result.jsx: Main image generation interface with loading states
- ImageController.js: Backend logic for ClipDrop API integration
- GenrateBtn.jsx: Call-to-action button with animations
- Home.jsx: Combines all sections for landing page
- Header.jsx: Hero section with animated elements
- Descrip.jsx: Feature descriptions
- Steps.jsx: How-to-use section
- Testimonials.jsx: User feedback section
- Navbar.jsx: Responsive navigation with user info
- Fotter.jsx: Footer with social links
- User registers/logs in โ Server generates JWT token
- Token stored in localStorage and React state
- All protected API calls include token in headers
- Server validates token using middleware
- Auto-redirect to login if token invalid/expired
- Password Hashing: bcrypt with salt rounds
- JWT Expiration: 30-day token validity
- Protected Routes: Authentication required for image generation
- Input Validation: Server-side validation for all inputs
- Free Credits: 5 credits given on registration
- Credit Deduction: 1 credit per image generation
- Credit Tracking: Real-time updates in UI
- Credit Protection: Frontend and backend validation
- Purchase Flow: Redirect to buy credits page when insufficient
// Frontend credit check
if (credits <= 0) {
toast.error("Insufficient credits!");
navigate("/buycredit");
return;
}
// Backend credit validation
if (user.credits <= 0) {
return res.status(400).json({
success: false,
message: "Insufficient credits"
});
}- Start Backend Server
cd server
npm run server # Uses nodemon for development
# or
npm start # For production- Start Frontend Development Server
cd Client
npm run dev # Starts Vite dev server- Access Application
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000
- Landing Page: User sees hero section, features, and testimonials
- Sign Up: Click "Get Started" โ Register with email/password
- Dashboard: Access to image generation with 5 free credits
- Generate Image: Enter prompt โ Beautiful loading animation โ Generated image
- Download: Save generated image to device
- Credits: Monitor remaining credits in navbar
- Buy Credits: Redirect when credits run out
- Framer Motion: Smooth page transitions and micro-interactions
- Loading States: Beautiful progress indicators during image generation
- Hover Effects: Interactive buttons and cards
- Page Transitions: Seamless navigation between pages
- Mobile-First: Optimized for all device sizes
- Tailwind CSS: Utility-first CSS framework
- Flexible Layouts: Adapts to different screen sizes
- Touch-Friendly: Mobile gesture support
- Toast Notifications: User-friendly error messages
- Network Errors: Graceful handling of API failures
- Validation: Client and server-side input validation
- Loading States: Clear feedback during async operations
const AppContext = {
user: null, // Current user data
token: "jwt_token", // Authentication token
credits: 5, // Available credits
showLogin: false, // Login modal visibility
generateImage: fn, // Image generation function
getUserCredits: fn, // Fetch user credits
logout: fn // Logout function
}-
CORS Errors
- Ensure CORS is enabled in server.js
- Check frontend/backend URLs match
-
Authentication Failures
- Verify JWT_SECRET in environment variables
- Check token format in API calls
-
Image Generation Issues
- Validate ClipDrop API key
- Check credit availability
- Monitor API rate limits
- Use React DevTools for component debugging
- Monitor Network tab for API call issues
- Check browser console for JavaScript errors
- Use MongoDB Compass for database inspection
Note: Add screenshots of your application here
- Landing page with hero section
- Image generation interface
- Generated image with download options
- User authentication modal
- Credits tracking in navigation
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
Praharsh Singh
- GitHub: @Praharsh7270
- Email: praharshsingh471@gmail.com
- ClipDrop API for AI image generation
- MongoDB Atlas for cloud database hosting
- Vercel/Netlify for deployment options
- React Community for excellent documentation
- Tailwind CSS for utility-first styling
- Payment integration for credit purchases
- Image history and gallery
- Advanced prompt suggestions
- Social sharing features
- Image editing tools
- Batch image generation
- User profile customization
- Admin dashboard
- API rate limiting
- Image optimization and compression
Made with โค๏ธ by Praharsh Singh