A modern, full-stack ChatGPT-like AI chatbot built with React, Node.js, and OpenAI API. Features real-time chat, user authentication, conversation history, and a beautiful responsive UI.
- User Registration & Login with secure JWT tokens
- Password Hashing using bcryptjs
- Session Management with localStorage
- Protected Routes with middleware authentication
- Real-time AI Responses using OpenAI GPT-4o-mini
- Conversation Threads - Organize chats by topics
- Message History - Persistent chat storage in MongoDB
- Typewriter Effect - Smooth text animation for AI responses
- Markdown Support - Rich text formatting with syntax highlighting
- Code Copy Feature - One-click code block copying
- Responsive Design - Works on desktop, tablet, and mobile
- Smooth Animations - Framer Motion powered transitions
- Loading States - Interactive loading indicators
- Toast Notifications - User feedback with react-hot-toast
- Mobile Sidebar - Swipeable navigation for mobile devices
- RESTful API - Clean backend architecture
- MongoDB Integration - Scalable data storage
- CORS Enabled - Cross-origin resource sharing
- Environment Variables - Secure configuration management
- Error Handling - Comprehensive error management
- Frontend: node-chatbot-ai.vercel.app
- Backend: chatbot-ai-bber.onrender.com
- React 19.1.0 - Modern React with hooks
- Vite - Fast build tool and dev server
- Tailwind CSS - Utility-first CSS framework
- Framer Motion - Animation library
- React Markdown - Markdown rendering
- React Hot Toast - Toast notifications
- React Spinners - Loading animations
- React Swipeable - Touch gestures
- Node.js - JavaScript runtime
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB object modeling
- JWT - JSON Web Tokens for authentication
- bcryptjs - Password hashing
- OpenAI API - AI chat completions
- CORS - Cross-origin resource sharing
ChatGPT-like-AI-chatbot/
βββ backend/
β βββ models/
β β βββ User.js # User schema
β β βββ Thread.js # Chat thread schema
β βββ routes/
β β βββ auth.js # Authentication routes
β β βββ chat.js # Chat API routes
β βββ utils/
β β βββ authMiddleware.js # JWT authentication middleware
β β βββ openai.js # OpenAI API integration
β βββ package.json
β βββ server.js # Express server
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ App.jsx # Main app component
β β β βββ Chat.jsx # Chat interface
β β β βββ ChatWindow.jsx # Chat window wrapper
β β β βββ Login.jsx # Login form
β β β βββ Register.jsx # Registration form
β β β βββ Sidebar.jsx # Navigation sidebar
β β β βββ MyContext.jsx # React context
β β βββ assets/
β β βββ index.css # Global styles
β βββ public/
β βββ package.json
βββ README.md
- Node.js (v16 or higher)
- MongoDB database
- OpenAI API key
-
Clone the repository
git clone https://github.com/rijughosh01/node-chatbot-ai cd ChatGPT-like-AI-chatbot/backend -
Install dependencies
npm install
-
Environment Variables Create a
.envfile in the backend directory:MONGODB_URI=your_mongodb_connection_string OPENAI_API_KEY=your_openai_api_key JWT_SECRET=your_jwt_secret_key PORT=8080
-
Start the server
# Development npm run dev # Production npm start
-
Navigate to frontend directory
cd ../frontend -
Install dependencies
npm install
-
Environment Variables Create a
.envfile in the frontend directory:VITE_API_BASE_URL=http://localhost:8080/api
-
Start the development server
npm run dev
-
Build for production
npm run build
- Connect your GitHub repository to Render
- Create a new Web Service
- Configure the service:
- Build Command:
npm install - Start Command:
npm start - Environment Variables:
MONGODB_URIOPENAI_API_KEYJWT_SECRET
- Build Command:
-
Install Vercel CLI
npm install -g vercel
-
Deploy from frontend directory
cd frontend vercel -
Add environment variable in Vercel dashboard:
VITE_API_BASE_URL=https://your-backend-url.onrender.com/api
POST /api/auth/register- User registrationPOST /api/auth/login- User loginPOST /api/auth/logout- User logout
GET /api/thread- Get all user threadsGET /api/thread/:threadId- Get specific thread messagesPOST /api/chat- Send message and get AI responseDELETE /api/thread/:threadId- Delete thread
- Each conversation is organized into threads
- Users can create new chats, switch between threads, and delete old conversations
- Thread titles are automatically generated from the first message
- Messages are sent to OpenAI API in real-time
- Responses are streamed back with a typewriter effect
- Markdown formatting with syntax highlighting for code blocks
- JWT-based authentication
- Password hashing with bcryptjs
- Protected API routes
- User-specific data isolation
- Mobile-first approach
- Swipeable sidebar for mobile navigation
- Adaptive layouts for different screen sizes
MONGODB_URI=mongodb://localhost:27017/chatbot
OPENAI_API_KEY=sk-your-openai-api-key
JWT_SECRET=your-super-secret-jwt-key
PORT=8080VITE_API_BASE_URL=http://localhost:8080/api- 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
This project is licensed under the MIT License.
- OpenAI for providing the GPT API
- React team for the amazing framework
- Vercel and Render for hosting services
- All the open-source libraries used in this project
If you have any questions or need help, please open an issue on GitHub.
Made with β€οΈ by Pritam Ghosh