A modern, AI-powered knowledge base application that allows you to upload documents, scrape web links, and chat with your content using advanced RAG (Retrieval Augmented Generation) technology.
- π Document Upload: Support for PDF, DOCX, TXT, MD, CSV, HTML, XML and more
- π Web Scraping: Add web content by URL with automatic scraping and indexing
- π¬ Intelligent Chat: AI-powered conversations with your documents using RAG
- π§΅ Thread Management: Organize conversations by topics/projects
- π Semantic Search: Find relevant content across all your documents
- π Public Sharing: Share knowledge base threads via public chat API
- π Secure Authentication: Email-based OTP authentication
- π Vector Storage: Powered by Qdrant for high-performance semantic search
- π€ LLM Integration: Uses Bifrost gateway for flexible LLM provider management
- Frontend: Next.js 15 with React 19, Tailwind CSS v4, Shadcn/ui components
- Backend: Next.js API routes with TypeScript
- Database: MySQL with Prisma ORM
- Vector Store: Qdrant for embeddings and semantic search
- Document Processing: LlamaIndex for parsing and chunking
- Authentication: Auth.js (NextAuth) with email OTP
- LLM Gateway: Bifrost for unified LLM provider access
- State Management: Zustand with persistence
- Deployment: Docker with multi-service orchestration
- Node.js 20+ and npm
- Docker and Docker Compose
- MySQL database
- Bifrost LLM gateway (for AI features)
git clone <repository-url>
cd chat-with-knowledge-base
npm install
Copy the environment template and configure your settings:
cp env.example .env
Update .env
with your actual values:
# π΄ SENSITIVE - Required for all environments
MYSQL_ROOT_PASSWORD="your-secure-root-password"
MYSQL_PASSWORD="your-secure-user-password"
NEXTAUTH_SECRET="$(openssl rand -base64 32)" # Generate with this command
RESEND_API_KEY="re_your_resend_api_key_here"
MAXIM_API_KEY="your-maxim-api-key"
MAXIM_LOG_REPO_ID="your-maxim-log-repo-id"
# π‘ ENVIRONMENT-SPECIFIC
DATABASE_URL="mysql://chatuser:${MYSQL_PASSWORD}@localhost:3306/chat_kb"
EMAIL_FROM="[email protected]"
ALLOWED_EMAIL_DOMAINS="yourdomain.com,gmail.com"
# π’ NON-SENSITIVE (optional to override defaults)
# MYSQL_DATABASE="chat_kb"
# MYSQL_USER="chatuser"
# BIFROST_API_URL="http://bifrost:8080"
# QDRANT_URL="http://qdrant:6333"
Required External Services:
- Resend Account: Sign up at resend.com for email OTP
- Maxim AI Account: Get API key from your Maxim AI dashboard
# Generate Prisma client and push schema to database
npm run recalibrate
# Start development server (runs on port 3333)
npm run dev
# Build the application
npm run build
# Start production server
npm start
# Build and start all services (web, MySQL, Qdrant, Bifrost)
docker-compose up --build
# Run in background
docker-compose up -d --build
# Stop services
docker-compose down
TBD
npm run dev
- Start development server with Turbopack on port 3001npm run build
- Build the application for productionnpm run start
- Start production servernpm run lint
- Run ESLint for code qualitynpm run format
- Format code with Prettiernpm run recalibrate
- Generate Prisma client and sync database schemanpm run check
- Type-check TypeScript without emitting files
src/
βββ app/ # Next.js app router pages and API routes
β βββ api/ # REST API endpoints
β βββ thread/[id]/ # Dynamic thread pages
β βββ settings/ # Settings page
βββ components/ # React components
β βββ ui/ # Shadcn/ui base components
β βββ layout/ # Layout components
β βββ knowledge-base/ # Feature-specific components
βββ modules/ # Business logic modules
β βββ auth/ # Authentication
β βββ storage/ # Database operations
β βββ rag/ # RAG and document processing
β βββ llm/ # LLM gateway
β βββ scraper/ # Web scraping
β βββ api/ # API utilities
βββ stores/ # Zustand state management
βββ types/ # TypeScript type definitions
βββ lib/ # Utility functions
- LlamaIndex: Document parsing, chunking, and RAG orchestration
- Qdrant: Vector database for semantic search
- Prisma: Type-safe database ORM
- Zustand: Lightweight state management
- Bifrost: LLM gateway for provider abstraction
- Tailwind CSS v4: Utility-first styling
- Shadcn/ui: Modern component library
POST /api/auth/signin
- Email OTP authenticationPOST /api/auth/verify
- Verify OTP code
GET /api/threads
- List user threadsPOST /api/threads
- Create new threadGET /api/threads/[id]
- Get thread detailsPUT /api/threads/[id]
- Update thread titleDELETE /api/threads/[id]
- Delete thread
GET /api/documents?threadId=
- List thread documentsPOST /api/documents/upload
- Upload and index documentsDELETE /api/documents/[id]
- Delete document
POST /api/links
- Scrape and index web content
POST /api/chat
- Chat with knowledge base (supports streaming)POST /api/chat/public
- Public chat API (API key authentication)
GET /api/settings/api-keys
- List API keysPOST /api/settings/api-keys
- Create API keyDELETE /api/settings/api-keys/[id]
- Delete API key
The application uses email-based OTP authentication:
- User enters email address
- System sends OTP code via email
- User enters OTP to complete authentication
- Session is maintained via secure cookies
For programmatic access, create API keys via the Settings page:
curl -X POST "http://localhost:3333/api/chat/public" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"message": "Your question", "threadId": "thread-id"}'
- Sign In: Use email OTP authentication
- Create Thread: Start a new conversation topic
- Upload Documents: Add PDF, DOCX, TXT files to your knowledge base
- Add Links: Scrape web content by URL
- Chat: Ask questions about your documents using natural language
- Share: Use public chat API to share knowledge base access
The application runs with multiple services:
- web: Next.js application (port 3333)
- mysql: MySQL database (port 3306)
- qdrant: Vector database (port 6333)
- bifrost: LLM gateway (port 8080)
- Build Errors: Ensure all environment variables are set
- Database Connection: Verify MySQL is running and accessible
- Vector Search Issues: Check Qdrant service status
- LLM Errors: Verify Bifrost configuration and API keys
# View application logs
docker-compose logs web
# View all service logs
docker-compose logs
# Follow logs in real-time
docker-compose logs -f
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the MIT License.
For issues and questions:
- Check the troubleshooting section
- Review Docker service logs
- Verify environment configuration
- Create an issue with detailed error information