Skip to content

bluegaurav/Basic-AI-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– AI Chatbot - Full Stack Application

Complete Production-Ready AI Chatbot with React Frontend + FastAPI Backend

A modern, responsive, and feature-rich AI chatbot frontend built with React, TypeScript, and Tailwind CSS. Includes user authentication, conversation history, personalized settings, and role-based AI responses.

✨ Features

πŸ” Authentication & User Management

  • User Login/Signup - Secure authentication system
  • User Profiles - Personalized user accounts
  • Session Persistence - Stay logged in across sessions

πŸ’¬ Chat Features

  • Multiple Conversations - Create and manage unlimited chats
  • Conversation History - Access all previous chats
  • Auto-save Messages - Never lose your conversations
  • Message Timestamps - Track conversation timeline
  • Typing Indicator - Visual feedback while AI is responding
  • Auto-scroll - Automatically scrolls to new messages
  • Clear Chat - Reset individual conversations
  • Keyboard Shortcuts - Enter to send, Shift+Enter for new line

βš™οΈ Personalization

  • Role-Based Responses - AI adapts to your role (Student, Professional, Developer, etc.)
  • Custom Context - Provide additional context for tailored responses
  • User Settings - Customize your AI experience
  • 6 Predefined Roles - Student, Professional, Developer, Researcher, Creative, General

🎨 Design & UX

  • Fully Responsive - Works seamlessly on mobile, tablet, and desktop
  • Modern UI/UX - Clean, intuitive interface with smooth animations
  • Sidebar Navigation - Easy access to all conversations
  • Mobile-Optimized - Collapsible sidebar for small screens
  • Dark Sidebar - Professional appearance

πŸ› οΈ Technical

  • Modular Architecture - Well-organized components for easy maintenance
  • Optimized Performance - Lightweight bundle (74KB gzipped)
  • TypeScript - Full type safety for better development experience
  • LocalStorage - Persistent data without backend
  • Customizable - Easy to integrate with your own AI backend

πŸ—οΈ Architecture

Component Structure

src/
β”œβ”€β”€ components/
β”‚   β”œβ”€β”€ ChatApp.tsx           - Main chat application
β”‚   β”œβ”€β”€ ChatContainer.tsx     - Chat messages display
β”‚   β”œβ”€β”€ ChatHeader.tsx        - Header with controls
β”‚   β”œβ”€β”€ ChatInput.tsx         - Message input area
β”‚   β”œβ”€β”€ ChatMessage.tsx       - Individual message bubble
β”‚   β”œβ”€β”€ EmptyState.tsx        - Welcome screen
β”‚   β”œβ”€β”€ Login.tsx             - Authentication page
β”‚   β”œβ”€β”€ Settings.tsx          - User settings modal
β”‚   β”œβ”€β”€ Sidebar.tsx           - Conversation list
β”‚   └── TypingIndicator.tsx   - AI typing animation
β”œβ”€β”€ context/
β”‚   └── AuthContext.tsx       - Authentication state
β”œβ”€β”€ hooks/
β”‚   β”œβ”€β”€ useChat.ts            - Chat state management
β”‚   └── useConversations.ts   - Conversation management
β”œβ”€β”€ types/
β”‚   β”œβ”€β”€ chat.ts               - Chat type definitions
β”‚   └── user.ts               - User type definitions
β”œβ”€β”€ config/
β”‚   └── chatConfig.ts         - Configuration settings
└── App.tsx                   - Root component with auth

Key Components

useChat Hook

Custom hook managing all chat logic:

  • Message state management
  • AI response handling (ready for API integration)
  • Error handling
  • Loading states

ChatContainer

Displays messages with auto-scroll functionality and empty state.

ChatMessage

Renders individual messages with user/AI differentiation, avatars, and timestamps.

ChatInput

Textarea with send button, keyboard shortcuts, and disabled state handling.

🎨 Design Features

  • Gradient backgrounds - Modern, appealing visual design
  • Smooth animations - Fade-in effects for messages
  • Custom scrollbar - Styled scrollbar for better aesthetics
  • Responsive layout - Adapts to all screen sizes
  • Message bubbles - Distinct styling for user vs AI messages
  • Avatar system - Visual distinction between user and AI

πŸ”§ Integration Guide

Connecting to Your AI Backend

Replace the generateAIResponse function in src/hooks/useChat.ts:

const generateAIResponse = async (userMessage: string): Promise<string> => {
  // Replace with your actual API call
  const response = await fetch('YOUR_API_ENDPOINT', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': 'Bearer YOUR_API_KEY',
    },
    body: JSON.stringify({
      message: userMessage,
      // Add other required parameters
    }),
  });
  
  const data = await response.json();
  return data.response;
};

Popular AI API Examples

OpenAI Integration

const response = await fetch('https://api.openai.com/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${YOUR_OPENAI_KEY}`,
  },
  body: JSON.stringify({
    model: 'gpt-3.5-turbo',
    messages: [{ role: 'user', content: userMessage }],
  }),
});

Custom Backend

const response = await fetch('/api/chat', {
  method: 'POST',
  body: JSON.stringify({ message: userMessage }),
});

πŸš€ Development

# Install dependencies
npm install

# Run development server
npm run dev

# Build for production
npm run build

πŸ“± Responsive Breakpoints

  • Mobile: < 640px
  • Tablet: 640px - 1024px
  • Desktop: > 1024px

🎯 Performance Optimizations

  1. Code splitting - Optimized bundle size
  2. Memoization - React hooks with useCallback
  3. Lazy rendering - Only visible messages rendered
  4. Efficient state updates - Minimal re-renders
  5. Optimized animations - CSS animations for better performance

πŸ” Security Considerations

When integrating with a real backend:

  • Never expose API keys in frontend code
  • Use environment variables for sensitive data
  • Implement rate limiting
  • Sanitize user input
  • Use HTTPS for API calls
  • Implement proper authentication

πŸ“ Customization

Changing Colors

Edit the Tailwind classes in components:

  • Primary color: blue-500 to blue-600
  • AI color: purple-500 to purple-600
  • Backgrounds: Gradient combinations

Adding Features

  • Message persistence: Add localStorage in useChat hook
  • File uploads: Extend ChatInput component
  • Voice input: Add Web Speech API
  • Message reactions: Add emoji reaction system
  • Multi-language: Integrate i18n library

πŸ› οΈ Tech Stack

  • React 18 - UI library
  • TypeScript - Type safety
  • Tailwind CSS - Styling
  • Vite - Build tool
  • Lucide React - Icon library

πŸ“„ License

This project is open source and available for use in your applications.

🀝 Contributing

Feel free to customize and enhance this chatbot for your specific needs!


Built with ❀️ for seamless AI interactions

About

It is a basic ai chatbot which use react js as forntend and fast api as backend and use free LLM from open router

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors