A modern, full-stack AI chatbot platform that combines a Next.js frontend with a FastAPI-based RAG (Retrieval-Augmented Generation) service. Create, manage, and embed AI chatbots with document-based knowledge and comprehensive analytics.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Chatty Platform β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Frontend (Next.js) β Backend (FastAPI + Qdrant) β
β βββββββββββββββββββββββββββ β βββββββββββββββββββββββββββββββ β
β β β’ Authentication β β β β’ Document Processing β β
β β β’ Chatbot Management ββββΌββΊβ β’ Vector Search (RAG) β β
β β β’ Embeddable Widget β β β β’ User Isolation β β
β β β’ Analytics Dashboard β β β β’ Qdrant Vector DB β β
β β β’ Real-time Chat β β β β’ OpenAI Embeddings β β
β βββββββββββββββββββββββββββ β βββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Chatty/
βββ front-end/ # Next.js Frontend Application
β βββ app/ # Next.js App Router
β β βββ api/ # API Routes (Auth, Chat, Analytics)
β β βββ components/ # React Components
β β βββ dashboard/ # Dashboard Pages
β β βββ chatbot/ # Chatbot Management
β βββ lib/ # Database & Utilities
β βββ public/ # Static Assets & Widget
β βββ package.json # Frontend Dependencies
β
βββ rag-service/ # FastAPI Backend Service
β βββ main.py # FastAPI Application
β βββ services/ # Business Logic
β β βββ document_processor.py
β β βββ rag_service.py
β β βββ vector_store.py
β βββ models/ # Data Models
β βββ docker-compose.yml # Service Orchestration
β βββ requirements.txt # Python Dependencies
β
βββ .gitignore # Unified Git Ignore Rules
βββ README.md # This File
- π Authentication: NextAuth with email/password and Google OAuth
- π€ Chatbot Management: Create, configure, and manage multiple chatbots
- π Embeddable Widget: Lightweight JavaScript widget for any website
- π Analytics Dashboard: Real-time metrics and conversation analytics
- π¨ Modern UI: Responsive design with dark/light theme support
- π‘οΈ Security: Domain restrictions and user isolation
- π Document Processing: Support for PDF, TXT, and DOCX files
- π§ RAG Integration: Retrieval-Augmented Generation with OpenAI embeddings
- π Vector Search: Semantic search using Qdrant vector database
- π€ User Isolation: Complete data separation between users and chatbots
- π³ Docker Support: Easy deployment with Docker Compose
- π JWT Authentication: Secure API access with token validation
- Node.js (v18 or higher)
- Python (v3.8 or higher)
- Docker and Docker Compose
- MongoDB (local or Atlas)
- OpenAI API Key (for embeddings and chat completions)
git clone <your-repo-url>
cd ChattyCreate environment files for both services:
Frontend (front-end/.env.local):
# MongoDB
MONGODB_URI="mongodb://localhost:27017"
MONGODB_DB="chat_app"
# NextAuth
NEXTAUTH_SECRET="your-strong-secret"
NEXTAUTH_URL="http://localhost:3000"
# Google OAuth (optional)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-client-secret"
# OpenRouter API (for chat completions)
OPENAI_API_KEY="your-openrouter-api-key"
# RAG Service
RAG_SERVICE_URL="http://localhost:8000"Backend (rag-service/.env):
# OpenAI API (for embeddings)
OPENAI_API_KEY="your_openai_api_key_here"
# JWT Configuration
JWT_SECRET_KEY="your_jwt_secret_key_here"
NEXTJS_JWT_SECRET="your_nextjs_jwt_secret_here"
# Qdrant Configuration
QDRANT_HOST=localhost
QDRANT_PORT=6333
# Next.js Integration
NEXTJS_APP_URL=http://localhost:3000# Navigate to RAG service directory
cd rag-service
# Start Qdrant and FastAPI service
docker-compose up -d
# Verify services are running
curl http://localhost:8000/health
curl http://localhost:6333/collections# Navigate to frontend directory
cd ../front-end
# Install dependencies
npm install
# Start development server
npm run dev- Frontend: http://localhost:3000
- RAG Service API: http://localhost:8000
- Qdrant Dashboard: http://localhost:6333/dashboard
-
Start Backend Services:
cd rag-service docker-compose up -d -
Start Frontend:
cd ../front-end npm run dev -
Access the Application:
- Open http://localhost:3000 in your browser
- Sign up for an account
- Create your first chatbot
- Upload documents to enable RAG functionality
Create a root-level docker-compose.yml:
version: '3.8'
services:
frontend:
build: ./front-end
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- MONGODB_URI=${MONGODB_URI}
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
- NEXTAUTH_URL=${NEXTAUTH_URL}
- OPENAI_API_KEY=${OPENAI_API_KEY}
- RAG_SERVICE_URL=http://rag-service:8000
depends_on:
- rag-service
rag-service:
build: ./rag-service
ports:
- "8000:8000"
environment:
- OPENAI_API_KEY=${OPENAI_API_KEY}
- JWT_SECRET_KEY=${JWT_SECRET_KEY}
- QDRANT_HOST=qdrant
- NEXTJS_APP_URL=${NEXTJS_APP_URL}
depends_on:
- qdrant
qdrant:
image: qdrant/qdrant
ports:
- "6333:6333"
volumes:
- qdrant_data:/qdrant/storage
volumes:
qdrant_data:- Frontend: Deploy to Vercel, Netlify, or any Node.js hosting
- Backend: Deploy to Railway, Render, or any Python hosting
- Database: Use MongoDB Atlas and Qdrant Cloud
Local MongoDB:
# macOS with Homebrew
brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb/brew/mongodb-community
# Ubuntu/Debian
sudo apt-get install mongodb
sudo systemctl start mongodMongoDB Atlas (Recommended for production):
- Create account at MongoDB Atlas
- Create a cluster
- Get connection string
- Update
MONGODB_URIin environment variables
- OpenAI API Key: Get from OpenAI Platform
- OpenRouter API Key: Get from OpenRouter (for chat completions)
- Google OAuth: Set up at Google Cloud Console
- Users sign up/sign in via NextAuth
- JWT tokens are generated for API access
- Sessions are managed securely
- Users create chatbots with custom configurations
- Each chatbot gets a unique ID and embeddable widget code
- Domain restrictions can be set for security
- Users upload documents (PDF, TXT, DOCX) via the frontend
- Documents are processed and chunked by the RAG service
- Text chunks are converted to embeddings using OpenAI
- Embeddings are stored in Qdrant with user isolation
- Users interact with chatbots via the embeddable widget
- Messages are sent to the chat API
- RAG service searches for relevant document chunks
- Context is combined with user message and sent to LLM
- Response is returned and stored for analytics
- All interactions are logged for analytics
- Real-time metrics are displayed in the dashboard
- User engagement and chatbot performance are tracked
-
Frontend Changes:
- Add components in
front-end/app/components/ - Create API routes in
front-end/app/api/ - Update pages in
front-end/app/
- Add components in
-
Backend Changes:
- Add services in
rag-service/services/ - Update models in
rag-service/models/ - Add API endpoints in
rag-service/main.py
- Add services in
Frontend Testing:
cd front-end
npm testBackend Testing:
cd rag-service
python -m pytestIntegration Testing:
# Test document upload
curl -X POST "http://localhost:8000/documents/upload" \
-H "Authorization: Bearer <token>" \
-F "file=@test.pdf" \
-F "chatbot_id=test_chatbot"
# Test chat with RAG
curl -X POST "http://localhost:8000/chat/context" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
-d '{"query": "test query", "chatbot_id": "test_chatbot"}'- JWT Authentication: Secure API access
- User Isolation: Complete data separation
- Domain Restrictions: Control where widgets can be embedded
- File Validation: Secure document uploads
- Rate Limiting: Prevent abuse
- HTTPS Support: Encrypted communication
- Real-time Metrics: User engagement, conversation counts
- Performance Monitoring: Response times, error rates
- Usage Analytics: Token usage, document processing stats
- Health Checks: Service availability monitoring
- 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 - see the LICENSE file for details.
- Documentation: Check the individual README files in
front-end/andrag-service/ - Issues: Report bugs and request features via GitHub Issues
- Discussions: Join community discussions for help and ideas
Built with β€οΈ using Next.js, FastAPI, MongoDB, Qdrant, and OpenAI