Skip to content

rishabh1024/AChatUI

Repository files navigation

AI Chatbot Frontend

A modern, responsive React TypeScript frontend for AI chatbot applications with FastAPI backend integration. Built with Vite, TailwindCSS, and featuring a sleek red, black, and purple color scheme.

AI Chatbot Interface TypeScript Vite TailwindCSS

✨ Features

🎯 Core Functionality

  • Real-time Chat Interface - Smooth, scrollable chat with message history
  • FastAPI Integration - Seamless connection to Python FastAPI backend
  • Message Management - Persistent chat history with timestamps
  • Loading States - Elegant loading animations and status indicators

πŸ›‘οΈ Reliability & Error Handling

  • Robust Error Handling - Comprehensive error catching with user-friendly messages
  • Retry Mechanism - Automatic and manual retry options for failed requests
  • Connection Status - Real-time API health monitoring with visual indicators
  • Request Timeouts - Configurable timeout handling (30s default)
  • Error Boundaries - Application-wide error recovery

πŸ’¬ Enhanced Chat Experience

  • Auto-resizing Input - Smart textarea that grows with content
  • Character Limits - 4000 character limit with real-time counter
  • Keyboard Shortcuts - Enter to send, Shift+Enter for new lines, Esc to clear errors
  • Message Validation - Input sanitization and validation
  • Visual Feedback - Loading dots, character counts, and status indicators

πŸ“± Responsive Design

  • Mobile-First - Fully responsive design for all screen sizes
  • Sidebar Navigation - Collapsible sidebar with chat history, prompts, documents, and tools
  • Modern UI - Clean, professional interface with smooth animations
  • Accessibility - ARIA labels, keyboard navigation, and screen reader support

βš™οΈ Configuration & Performance

  • Environment Configuration - Configurable API endpoints and settings
  • Performance Optimized - React.memo implementation and efficient re-renders
  • TypeScript - Full type safety throughout the application
  • Modular Architecture - Clean separation of concerns and reusable components

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • npm or yarn
  • FastAPI backend running on localhost:8000 (or configured endpoint)

Installation

  1. Clone and navigate to the project

    cd "c:\Users\risha\python-dir\KnowledgeBase\ChatUI"
  2. Install dependencies

    npm install
  3. Configure environment (optional)

    Copy-Item .env.example .env
    # Edit .env with your API settings
  4. Start development server

    npm run dev
  5. Open in browser

    http://localhost:5173
    

πŸ”§ Configuration

Environment Variables

Create a .env file in the root directory:

# API Configuration
VITE_API_BASE_URL=http://localhost:8000
VITE_API_TIMEOUT=30000
VITE_API_RETRY_ATTEMPTS=3

# Development Settings
VITE_DEV_MODE=true
VITE_LOG_LEVEL=debug

API Endpoints

The frontend expects the following FastAPI endpoints:

  • POST /chat - Send chat messages

    {
      "message": "Your message here"
    }
  • GET /health - Health check (optional)

Expected response format:

{
  "message": "AI response here",
  "success": true
}

πŸ“ Project Structure

src/
β”œβ”€β”€ components/          # React components (organized by feature)
β”‚   β”œβ”€β”€ chat/                # Chat-related components
β”‚   β”‚   β”œβ”€β”€ ChatContainer.tsx    # Main chat interface
β”‚   β”‚   β”œβ”€β”€ Message.tsx          # Individual message component
β”‚   β”‚   β”œβ”€β”€ LoadingDots.tsx      # Loading animation
β”‚   β”‚   └── index.ts             # Chat components barrel export
β”‚   β”œβ”€β”€ layout/              # Layout and structural components
β”‚   β”‚   β”œβ”€β”€ Sidebar.tsx          # Navigation sidebar
β”‚   β”‚   β”œβ”€β”€ ErrorBoundary.tsx    # Error handling wrapper
β”‚   β”‚   └── index.ts             # Layout components barrel export
β”‚   β”œβ”€β”€ ui/                  # Reusable UI components
β”‚   β”‚   β”œβ”€β”€ ConnectionStatus.tsx # API status indicator
β”‚   β”‚   └── index.ts             # UI components barrel export
β”‚   └── index.ts             # Main components barrel export
β”œβ”€β”€ hooks/               # Custom React hooks
β”‚   β”œβ”€β”€ useAutoResize.ts     # Auto-resizing textarea hook
β”‚   β”œβ”€β”€ useDebounce.ts       # Debouncing hook
β”‚   └── index.ts             # Hooks barrel export
β”œβ”€β”€ utils/               # Utility functions
β”‚   └── index.ts             # Validation, formatting, helper functions
β”œβ”€β”€ constants/           # Application constants
β”‚   └── index.ts             # Configuration constants and enums
β”œβ”€β”€ services/            # API service layer
β”‚   └── chatService.ts       # FastAPI integration
β”œβ”€β”€ types/              # TypeScript definitions
β”‚   └── chat.ts              # Chat-related types
β”œβ”€β”€ config/             # Configuration
β”‚   └── api.ts               # API configuration
β”œβ”€β”€ styles/             # Global styles
β”‚   β”œβ”€β”€ App.css              # Component styles
β”‚   └── index.css            # Global styles
└── assets/             # Static assets
    └── react.svg            # Icons and images

🎨 Styling & Theming

Color Scheme

  • Primary (Red): #ef4444 - User messages, buttons, accents
  • Secondary (Black/Gray): #0f172a - Text, backgrounds, borders
  • Accent (Purple): #a855f7 - Highlights, gradients, special elements

Customization

Colors are defined in tailwind.config.js and can be easily customized:

colors: {
  primary: {
    500: '#ef4444', // Main red
    // ... other shades
  },
  secondary: {
    900: '#0f172a', // Main black
    // ... other shades
  },
  accent: {
    500: '#a855f7', // Main purple
    // ... other shades
  }
}

πŸ“ Available Scripts

# Development
npm run dev          # Start development server

# Building
npm run build        # Build for production
npm run preview      # Preview production build

# Code Quality
npm run lint         # Run ESLint
npm run type-check   # TypeScript type checking

πŸ”Œ Backend Integration

FastAPI Setup

Your FastAPI backend should have:

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel

app = FastAPI()

# Enable CORS for frontend
app.add_middleware(
    CORSMiddleware,
    allow_origins=["http://localhost:5173"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

class ChatMessage(BaseModel):
    message: str

@app.post("/chat")
async def chat_endpoint(chat_message: ChatMessage):
    # Your AI logic here
    response = await process_ai_message(chat_message.message)
    return {"message": response}

@app.get("/health")
async def health_check():
    return {"status": "healthy"}

πŸ› οΈ Development

Code Quality Standards

  • TypeScript - Strict type checking enabled
  • ESLint - Code linting with React best practices
  • Error Handling - Comprehensive error boundaries and validation
  • Performance - Optimized components with React.memo
  • Accessibility - ARIA labels and keyboard navigation

Testing Recommendations

  • Unit tests for components (Jest + React Testing Library)
  • Integration tests for API calls
  • E2E testing with Playwright or Cypress
  • Manual testing checklist in CODE_QUALITY_IMPROVEMENTS.md

🚨 Troubleshooting

Common Issues

  1. API Connection Failed

    • Check if FastAPI backend is running on correct port
    • Verify CORS settings in backend
    • Check network connectivity
  2. Build Errors

    • Clear node_modules: Remove-Item -Recurse -Force node_modules; npm install
    • Check TypeScript errors: npm run type-check
  3. Performance Issues

    • Check for unnecessary re-renders in React DevTools
    • Verify large message history isn't causing slowdowns

Environment Issues

  • Ensure Node.js version is 18+
  • Check if ports 5173+ are available
  • Verify environment variables are set correctly

πŸ“– Additional Documentation

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

Code Style

  • Use TypeScript strict mode
  • Follow React best practices
  • Implement proper error handling
  • Add accessibility features
  • Write meaningful commit messages

πŸ“„ License

This project is licensed under the MIT License.

🎯 Roadmap

  • Message persistence with local storage
  • File upload support
  • Voice message integration
  • Multi-language support
  • Theming system
  • Plugin architecture
  • Advanced markdown rendering
  • Message search functionality

Built with ❀️ using React, TypeScript, and TailwindCSS

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors