A professional, fully functional ChatGPT clone with modern UI/UX, streaming responses, and AI integration using OpenAI GPT-4 or Perplexity API.
- π¨ Modern Chat Interface: Clean, professional UI with user/AI message bubbles
- β‘ Streaming Animations: Real-time typing effects for AI responses
- π Dark/Light Mode: Toggle between themes with smooth transitions
- π Copy to Clipboard: One-click copy functionality for AI messages
- π± Responsive Design: Works perfectly on desktop, tablet, and mobile
- β¨οΈ Keyboard Shortcuts:
Enterto send messagesShift+Enterfor new linesCtrl+Nfor new conversationCtrl+Tto toggle theme
- π¬ Chat Management: Start new conversations, maintain chat history
- π― Auto-scroll: Automatically scrolls to latest messages
- π€ AI Integration: Support for OpenAI GPT-4 and Perplexity API
- πΎ Context Management: Maintains conversation context across messages
- π Security: Rate limiting, CORS protection, input validation
- π Performance: Optimized API calls with proper error handling
- π Monitoring: Health checks and logging
- π§Ή Memory Management: Automatic cleanup of old conversations
- Node.js 16+ or Python 3.8+
- OpenAI API key or Perplexity API key
- Git (optional)
-
Install Dependencies
npm install
-
Configure Environment
cp .env.example .env # Edit .env and add your API keys -
Run the Application
# Development mode npm run dev # Production mode npm start
-
Install Dependencies
pip install -r requirements.txt
-
Configure Environment
cp .env.example .env # Edit .env and add your API keys -
Run the Application
# Development mode python server.py # Production mode with Gunicorn gunicorn server:app --bind 0.0.0.0:5000
The application will be available at http://localhost:3000 (Node.js) or http://localhost:5000 (Python).
chatgpt-clone/
βββ frontend/
β βββ index.html # Main HTML file
β βββ style.css # CSS styles and themes
β βββ app.js # Frontend JavaScript logic
βββ backend/
β βββ server.js # Node.js Express server
β βββ server.py # Python Flask server
β βββ package.json # Node.js dependencies
β βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ README.md # This file
βββ docs/ # Additional documentation
-
OpenAI API Key (Recommended)
- Sign up at OpenAI Platform
- Go to API Keys section
- Create a new API key
- Add to
.envfile:OPENAI_API_KEY=sk-...
-
Perplexity API Key (Alternative)
- Sign up at Perplexity AI
- Go to Settings > API
- Create a new API key
- Add to
.envfile:PERPLEXITY_API_KEY=pplx-...
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key for GPT-4 | Required |
PERPLEXITY_API_KEY |
Perplexity API key | Alternative |
PORT |
Server port | 3000 (Node.js), 5000 (Python) |
NODE_ENV / FLASK_ENV |
Environment mode | development |
FRONTEND_URL |
Frontend URL for CORS | http://localhost:3000 |
GET /api/health
Response: { "status": "healthy", "timestamp": "...", "version": "1.0.0" }
POST /api/conversations
Response: { "conversationId": "uuid" }
POST /api/conversations/:id/messages
Body: {
"message": "Hello!",
"usePerplexity": false
}
Response: {
"message": { "role": "assistant", "content": "...", "timestamp": "..." },
"conversationId": "uuid"
}
GET /api/conversations/:id
Response: { "id": "uuid", "messages": [...], "createdAt": "...", "lastActivity": "..." }
DELETE /api/conversations/:id
Response: { "message": "Conversation deleted successfully" }
- Install Vercel CLI:
npm i -g vercel - Configure
vercel.json:{ "version": 2, "builds": [ { "src": "server.js", "use": "@vercel/node" }, { "src": "frontend/*", "use": "@vercel/static" } ], "routes": [ { "src": "/api/(.*)", "dest": "/server.js" }, { "src": "/(.*)", "dest": "/frontend/$1" } ], "env": { "OPENAI_API_KEY": "@openai-api-key" } } - Deploy:
vercel --prod
-
Prepare for Deployment
# Add Procfile for Node.js echo "web: node server.js" > Procfile # Or for Python echo "web: gunicorn server:app --bind 0.0.0.0:$PORT" > Procfile
-
Deploy to Heroku
heroku create your-chatgpt-clone heroku config:set OPENAI_API_KEY=your_key_here git push heroku main
-
Create Dockerfile
FROM node:18-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "server.js"]
-
Build and Deploy
docker build -t chatgpt-clone . docker run -p 3000:3000 --env-file .env chatgpt-clone
- Modify CSS variables in
style.css - Add custom color schemes
- Adjust typography and spacing
- Change model parameters in backend
- Modify system prompts
- Adjust context window size
- Add new features to
app.js - Customize message rendering
- Add new keyboard shortcuts
- Default: 100 requests per hour, 20 per minute
- Configurable per endpoint
- IP-based tracking
- Graceful API failure handling
- User-friendly error messages
- Comprehensive logging
- Automatic cleanup of old conversations
- Configurable retention policies
- Memory usage optimization
- Environment variable for API keys
- Rate limiting to prevent abuse
- Input validation and sanitization
- CORS configuration
- Use HTTPS in production
- Implement proper authentication
- Regular security updates
- Monitor API usage
-
API Key Not Working
- Verify key is correctly set in
.env - Check API key permissions and billing
- Ensure no extra spaces in key
- Verify key is correctly set in
-
CORS Errors
- Update
FRONTEND_URLin environment - Check domain configuration
- Verify protocol (http/https)
- Update
-
Port Already in Use
- Change
PORTin.env - Kill process:
lsof -ti:3000 | xargs kill -9
- Change
-
Dependencies Issues
- Clear cache:
npm cache clean --force - Delete node_modules:
rm -rf node_modules && npm install
- Clear cache:
- User authentication and profiles
- Persistent database storage
- File upload support
- Voice input/output
- Message search functionality
- Export conversations
- Multiple AI model support
- Custom prompt templates
- Analytics dashboard
- Multi-language support
Replace in-memory storage with:
- PostgreSQL for conversation storage
- Redis for session management
- MongoDB for document storage
- WebSocket integration for real-time updates
- Server-sent events for streaming responses
- Progressive Web App (PWA) support
- Offline functionality
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
If you encounter any issues or need help with setup:
- Check the troubleshooting section
- Review environment configuration
- Verify API key setup
- Check console logs for errors
- OpenAI for GPT-4 API
- Perplexity AI for alternative API
- Modern web technologies and best practices
- Open source community for inspiration
Happy coding! π