Skip to content

Atomic is a full-stack AI-powered contextual chatbot application built with React, Node.js, and Google Gemini AI. The application features multiple AI personalities, real-time chat functionality, user authentication, and persistent memory using vector embeddings.

Notifications You must be signed in to change notification settings

DeveloperChetram/Contextual_Chatbot_React

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

117 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Atomic - Contextual Chatbot React

App Screenshot

A full-stack AI-powered contextual chatbot application built with React, Node.js, and Google Gemini AI. The application features multiple AI personalities, real-time chat functionality, user authentication, and persistent memory using vector embeddings.

πŸ“‹ Table of Contents

🎬 Demo Video

Watch a quick demo of the Atomic personality in action:

πŸŽ₯ Interactive Demo Video

Watch Demo Video

🎬 Direct Video Player

πŸ“± Live Application

🌐 Try it yourself: https://atomic-llm.vercel.app

πŸ“Έ Screenshots

Chat Interface Overview

Chat Interface Demo

Light/Dark Theme Support

Light Mode Support

Responsive in many screens

Responsive Chat

🌟 Features

Core Functionality

  • Multi-Personality AI Chat: Choose from different AI characters (Atomic, Jahnvi, Chandni, Osho, Harsh Bhaiya)
  • Real-time Communication: WebSocket-based instant messaging
  • User Authentication: Secure login/register system with JWT tokens
  • Persistent Memory: Vector-based conversation memory using Pinecone
  • Credit System: User credit management for API usage
  • Responsive Design: Mobile-friendly interface with dark/light themes

AI Personalities

  • Atomic: Precise, factual, and concise responses
  • Jahnvi: Friendly, knowledgeable girl from Damoh, MP
  • Chandni: Calm, reserved, and direct personality
  • Osho: Mystical, meditative, and paradoxical responses
  • Harsh Bhaiya: Motivational mentor and coding school founder

Technical Features

  • Vector Embeddings: Gemini embedding model for semantic search
  • Contextual Memory: Pinecone vector database for conversation history
  • Markdown Support: Rich text rendering with syntax highlighting
  • CORS Configuration: Cross-origin resource sharing setup
  • Cookie-based Auth: Secure authentication with HTTP-only cookies

πŸ—οΈ Architecture

Frontend (React + Vite)

frontend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”œβ”€β”€ ChatInterface.jsx    # Main chat UI
β”‚   β”‚   β”œβ”€β”€ Login.jsx            # Authentication forms
β”‚   β”‚   β”œβ”€β”€ Register.jsx
β”‚   β”‚   β”œβ”€β”€ ThemeToggler.jsx     # Dark/Light mode
β”‚   β”‚   └── TypingIndicator.jsx  # Real-time typing
β”‚   β”œβ”€β”€ redux/               # State management
β”‚   β”‚   β”œβ”€β”€ store.js             # Redux store
β”‚   β”‚   β”œβ”€β”€ reducers/            # State reducers
β”‚   β”‚   └── actions/             # Action creators
β”‚   β”œβ”€β”€ api/                 # API configuration
β”‚   β”‚   └── axios.jsx            # HTTP client setup
β”‚   β”œβ”€β”€ routes/              # React Router
β”‚   └── styles/               # CSS files

Backend (Node.js + Express)

backend/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ controllers/          # Request handlers
β”‚   β”‚   β”œβ”€β”€ auth.controllers.js    # Authentication logic
β”‚   β”‚   └── chat.controllers.js    # Chat operations
β”‚   β”œβ”€β”€ models/              # Database schemas
β”‚   β”‚   β”œβ”€β”€ user.model.js          # User data model
β”‚   β”‚   β”œβ”€β”€ chat.model.js           # Chat sessions
β”‚   β”‚   └── message.model.js        # Message history
β”‚   β”œβ”€β”€ services/            # Business logic
β”‚   β”‚   β”œβ”€β”€ ai.service.js           # Gemini AI integration
β”‚   β”‚   └── vector.service.js       # Pinecone operations
β”‚   β”œβ”€β”€ routes/              # API endpoints
β”‚   β”œβ”€β”€ middlewares/         # Custom middleware
β”‚   β”œβ”€β”€ sockets/             # WebSocket handlers
β”‚   β”œβ”€β”€ db/                  # Database connection
β”‚   └── app.js               # Express app configuration

πŸš€ Getting Started

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB Atlas account
  • Google AI API key
  • Pinecone API key
  • Git

Installation

  1. Clone the repository

    git clone https://github.com/DeveloperChetram/Contextual_Chatbot_React.git
    cd Contextual_Chatbot_React
  2. Backend Setup

    cd backend
    npm install
  3. Frontend Setup

    cd ../frontend
    npm install

Environment Variables

Backend (.env)

# Database
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/database_name

# JWT Secret
JWT_SECRET=your_jwt_secret_key

# Google AI
GOOGLE_API_KEY=your_google_ai_api_key

# Pinecone
PINECONE_API_KEY=your_pinecone_api_key

# Environment
NODE_ENV=development

Frontend (.env)

VITE_BACKEND_URL=http://localhost:3001/api

Running the Application

  1. Start Backend Server

    cd backend
    npm run dev

    Server runs on http://localhost:3001

  2. Start Frontend Development Server

    cd frontend
    npm run dev

    Frontend runs on http://localhost:5173

  3. Access the Application Open http://localhost:5173 in your browser

πŸ”§ Configuration

CORS Setup

The application is configured to allow requests from:

  • http://localhost:5173 (Frontend dev server)
  • https://atomic-llm.vercel.app (Production frontend)
  • https://contextual-chatbot-react.onrender.com (Production backend)

Database Models

User Model

{
  email: String (required),
  fullName: {
    firstName: String (required),
    lastName: String (required)
  },
  credits: Number (default: 50),
  passwordHash: String (required),
  timestamps: true
}

Chat Model

{
  userId: ObjectId (required),
  title: String,
  messages: [ObjectId],
  timestamps: true
}

Message Model

{
  chatId: ObjectId (required),
  content: String (required),
  role: String (required), // 'user' or 'model'
  character: String,
  timestamps: true
}

🌐 Deployment

Frontend (Vercel)

  1. Connect your GitHub repository to Vercel
  2. Set environment variable: VITE_BACKEND_URL=https://your-backend-domain.com/api
  3. Deploy automatically on push to main branch

Backend (Render)

  1. Connect your GitHub repository to Render
  2. Set environment variables:
    • MONGO_URI
    • JWT_SECRET
    • GOOGLE_API_KEY
    • PINECONE_API_KEY
    • NODE_ENV=production
  3. Deploy automatically on push to main branch

Production URLs

  • Frontend: https://atomic-llm.vercel.app
  • Backend: https://contextual-chatbot-react.onrender.com

πŸ”Œ API Endpoints

Authentication

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

Chat

  • GET /api/chat - Get user's chat sessions
  • POST /api/chat - Create new chat session
  • POST /api/chat/:chatId/message - Send message to chat

Health Check

  • GET /api/health - Server health status
  • GET /api/cors-test - CORS configuration test

πŸ› οΈ Technologies Used

Frontend

  • React 19 - UI framework
  • Vite - Build tool and dev server
  • Redux Toolkit - State management
  • React Router - Client-side routing
  • Axios - HTTP client
  • Socket.io-client - Real-time communication
  • React Markdown - Markdown rendering
  • React Syntax Highlighter - Code highlighting

Backend

  • Node.js - Runtime environment
  • Express.js - Web framework
  • Mongoose - MongoDB ODM
  • Socket.io - WebSocket server
  • JWT - Authentication tokens
  • bcryptjs - Password hashing
  • CORS - Cross-origin resource sharing
  • Cookie Parser - Cookie handling

AI & Database

  • Google Gemini AI - Language model and embeddings
  • Pinecone - Vector database for memory
  • MongoDB Atlas - Document database

πŸ› Troubleshooting

Common Issues

  1. CORS Errors

    • Ensure backend URL is in allowed origins
    • Check environment variables are set correctly
    • Verify CORS middleware is properly configured
  2. Database Connection Issues

    • Verify MongoDB URI is correct
    • Check network access settings in MongoDB Atlas
    • Ensure environment variables are loaded
  3. AI API Errors

    • Verify Google AI API key is valid
    • Check API quota and limits
    • Ensure Pinecone API key is correct
  4. Authentication Issues

    • Check JWT secret is set
    • Verify cookie settings for production
    • Ensure user model is properly configured

Debug Commands

# Test backend health
curl https://contextual-chatbot-react.onrender.com/api/health

# Test CORS
curl -H "Origin: http://localhost:5173" https://contextual-chatbot-react.onrender.com/api/health

# Test login endpoint
curl -X POST -H "Content-Type: application/json" -d '{"email":"test@test.com","password":"test"}' https://contextual-chatbot-react.onrender.com/api/auth/login

πŸ“ Development Notes

Character System

The AI personalities are defined in backend/src/services/ai.service.js. Each character has:

  • Unique personality traits
  • Specific communication style
  • Cultural context (Indian English, Hinglish)
  • Response patterns

Memory System

  • Messages are embedded using Gemini's embedding model
  • Vector embeddings are stored in Pinecone
  • Context is retrieved based on semantic similarity
  • Memory helps maintain conversation continuity

Credit System

  • Users start with 50 credits
  • Each AI interaction consumes credits
  • Credits prevent API abuse
  • System tracks usage per user

🀝 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 ISC License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

DeveloperChetram

πŸ™ Acknowledgments

  • Google Gemini AI for language model capabilities
  • Pinecone for vector database services
  • MongoDB Atlas for database hosting
  • Vercel and Render for deployment platforms
  • The React and Node.js communities for excellent tooling

Note: This application is designed for educational and personal use. Please ensure you have proper API keys and follow the terms of service for all third-party services used.

About

Atomic is a full-stack AI-powered contextual chatbot application built with React, Node.js, and Google Gemini AI. The application features multiple AI personalities, real-time chat functionality, user authentication, and persistent memory using vector embeddings.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published