Skip to content

A modern Node.js AI chatbot framework with ReactJS frontend, OpenAI integration, and secure JWT authentication. Easily build, train, and deploy intelligent conversational agents with persistent data storage using MongoDB/Mongoose. Powered by Vite for fast development and extensible for custom AI use cases.

Notifications You must be signed in to change notification settings

rijughosh01/node-chatbot-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– NodeGPT - AI Chat Assistant

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.

✨ Features

πŸ” Authentication & User Management

  • User Registration & Login with secure JWT tokens
  • Password Hashing using bcryptjs
  • Session Management with localStorage
  • Protected Routes with middleware authentication

πŸ’¬ Chat Functionality

  • 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

🎨 Modern UI/UX

  • 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

πŸ”§ Technical Features

  • 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

πŸš€ Live Demo

πŸ› οΈ Tech Stack

Frontend

  • 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

Backend

  • 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

πŸ“ Project Structure

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

πŸš€ Quick Start

Prerequisites

  • Node.js (v16 or higher)
  • MongoDB database
  • OpenAI API key

Backend Setup

  1. Clone the repository

    git clone https://github.com/rijughosh01/node-chatbot-ai
    cd ChatGPT-like-AI-chatbot/backend
  2. Install dependencies

    npm install
  3. Environment Variables Create a .env file 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
  4. Start the server

    # Development
    npm run dev
    
    # Production
    npm start

Frontend Setup

  1. Navigate to frontend directory

    cd ../frontend
  2. Install dependencies

    npm install
  3. Environment Variables Create a .env file in the frontend directory:

    VITE_API_BASE_URL=http://localhost:8080/api
  4. Start the development server

    npm run dev
  5. Build for production

    npm run build

🌐 Deployment

Backend Deployment (Render)

  1. Connect your GitHub repository to Render
  2. Create a new Web Service
  3. Configure the service:
    • Build Command: npm install
    • Start Command: npm start
    • Environment Variables:
      • MONGODB_URI
      • OPENAI_API_KEY
      • JWT_SECRET

Frontend Deployment (Vercel)

  1. Install Vercel CLI

    npm install -g vercel
  2. Deploy from frontend directory

    cd frontend
    vercel
  3. Add environment variable in Vercel dashboard:

    • VITE_API_BASE_URL=https://your-backend-url.onrender.com/api

πŸ”§ API Endpoints

Authentication

  • POST /api/auth/register - User registration
  • POST /api/auth/login - User login
  • POST /api/auth/logout - User logout

Chat

  • GET /api/thread - Get all user threads
  • GET /api/thread/:threadId - Get specific thread messages
  • POST /api/chat - Send message and get AI response
  • DELETE /api/thread/:threadId - Delete thread

🎯 Key Features Explained

1. Thread Management

  • 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

2. Real-time Chat

  • 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

3. Security

  • JWT-based authentication
  • Password hashing with bcryptjs
  • Protected API routes
  • User-specific data isolation

4. Responsive Design

  • Mobile-first approach
  • Swipeable sidebar for mobile navigation
  • Adaptive layouts for different screen sizes

πŸ”’ Environment Variables

Backend (.env)

MONGODB_URI=mongodb://localhost:27017/chatbot
OPENAI_API_KEY=sk-your-openai-api-key
JWT_SECRET=your-super-secret-jwt-key
PORT=8080

Frontend (.env)

VITE_API_BASE_URL=http://localhost:8080/api

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License.

πŸ™ Acknowledgments

  • 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

πŸ“ž Support

If you have any questions or need help, please open an issue on GitHub.


Made with ❀️ by Pritam Ghosh

About

A modern Node.js AI chatbot framework with ReactJS frontend, OpenAI integration, and secure JWT authentication. Easily build, train, and deploy intelligent conversational agents with persistent data storage using MongoDB/Mongoose. Powered by Vite for fast development and extensible for custom AI use cases.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published