⚠️ Beta Release: This project is currently in beta. Some features or functions may not work or behave as expected. Please report any issues you encounter.
Full-stack TypeScript application: React + Vite frontend with an Express backend, featuring chat, document ingestion, embeddings, and provider settings.
- Multi-Provider Support: OpenAI, Anthropic, OpenRouter, Ollama, and any OpenAI-compatible API
- 40+ AI Models: GPT-4o, GPT-5, Claude, Gemini, Grok, DeepSeek, Qwen, and more
- Three Chat Modes:
- 💬 Chat Mode: Standard conversational AI
- 🔬 Research Mode: Deep research with web search, planning, and synthesis
- 📚 Study Mode: Interactive learning with quizzes and hints
- Web Search Integration: Real-time web search with source citations
- Streaming Responses: Smooth, real-time message streaming
- Smart Chat Titles: AI-generated conversation titles
- Incognito Mode: Chat without saving history
- Context Management: Automatic token counting and cost tracking
- Document Upload: PDF, DOCX, XLSX/XLS support (up to 15MB per file)
- Semantic Search: Vector embeddings with cosine similarity
- Smart Chunking: Intelligent text segmentation with overlap
- Document Querying: Ask questions about your uploaded documents
- Storage Management: 200MB per-user storage with usage tracking
- Background Processing: Async document processing with status tracking
- Modern UI: Beautiful, responsive design with Tailwind CSS
- Dark Theme: Eye-friendly dark mode interface
- Smooth Animations: Framer Motion powered transitions
- Code Highlighting: Syntax highlighting for 180+ languages
- Math Rendering: LaTeX/KaTeX support for mathematical notation
- Markdown Support: Full GFM (GitHub Flavored Markdown)
- Message Editing: Quote and reference previous messages
- Split-Pane Artifacts: Side-by-side view for generated content
- HTML/CSS/JS Rendering: Live preview of web pages with download capability
- Python Execution: Run Python code in-browser with Pyodide (no server needed)
- Mermaid Diagrams: Render flowcharts, sequence diagrams, and more
- LaTeX Math: Display complex mathematical equations with KaTeX
- Syntax Highlighting: Beautiful code display for all artifact types
- Sandboxed Execution: Safe, isolated environment for running code
- MCP Server Support: Connect to local and remote MCP servers
- Multiple Transports: stdio (local process), SSE, and Streamable HTTP
- Tools Integration: Access external tools from MCP servers
- Resource Access: Read files, databases, and APIs via MCP resources
- Prompt Templates: Use pre-defined prompts from MCP servers
- Per-User Configuration: Each user manages their own MCP servers
- Connection Testing: Verify MCP server connectivity before saving
- User Authentication: Secure JWT-based auth with HTTP-only cookies
- Encrypted Storage: AES-256-GCM encryption for API keys
- Per-User Isolation: Complete data separation between users
- Secure Cookies: sameSite=strict with secure flag in production
- No Key Exposure: API keys never sent to frontend
- Custom System Prompts: Personalize AI behavior
- Provider Settings: Configure multiple AI providers
- Model Selection: Choose from 40+ models with pricing info
- Embedding Models: Multiple OpenAI embedding options
- Display Name: Personalized user experience
- Onboarding Wizard: Guided setup for new users
- TypeScript: Full type safety across frontend and backend
- SQLite Database: Lightweight, embedded database
- RESTful API: Clean API architecture
- Real-time Processing: WebSocket-style streaming
- Error Handling: Comprehensive error management
- CI/CD Ready: GitHub Actions workflow included
Clean, modern interface with animated background
Switch between Chat, Research, and Study modes seamlessly
Choose from 40+ models across multiple providers
Copy messages, ask follow-ups, and interact with AI responses
Upload and manage documents with RAG capabilities
Customize font size and style for better readability
Live HTML/CSS/JS rendering, Python execution, Mermaid diagrams, and LaTeX math in split-pane view
bun installcp .env.example .env.localEdit .env.local and set your secrets:
JWT_SECRET=your-secret-key-here
ENCRYPTION_KEY=your-32-byte-encryption-key
CORS_ORIGIN=http://localhost:5173Open two terminals:
Terminal 1 - Frontend (Vite dev server):
bun run devRuns on http://localhost:5173
Terminal 2 - Backend (Express server):
bun run server:devRuns on http://localhost:3001
| Variable | Description | Default |
|---|---|---|
VITE_API_BASE_URL |
Backend API base URL | http://localhost:3001/api |
| Variable | Description | Required | Default |
|---|---|---|---|
NODE_ENV |
Environment mode | No | development |
PORT |
Express server port | No | 3001 |
CORS_ORIGIN |
Allowed origin for CORS | No | http://localhost:5173 |
JWT_SECRET |
Secret for signing JWT tokens | Yes (production) | dev-insecure-jwt-secret |
ENCRYPTION_KEY |
32+ byte key for encrypting API keys | Yes | - |
OPENAI_API_KEY |
Fallback OpenAI key (optional) | No | - |
| Variable | Description | Default |
|---|---|---|
PDF_EXTRACTOR |
Force PDF extractor: unpdf or pdfjs |
Auto-detect |
PDF_MAX_PAGES |
Max pages to extract from PDFs | 40 |
PDF_MAX_TEXT_CHARS |
Max characters from PDF text | 250000 |
DOC_MAX_TEXT_CHARS |
Max characters from documents | 300000 |
DOC_MAX_CHUNKS |
Max chunks per document | 200 |
| Command | Description |
|---|---|
bun run dev |
Start Vite dev server (frontend) |
bun run server:dev |
Start Express server in watch mode |
bun run server |
Start Express server (no watch) |
bun run build |
Type-check and build frontend |
bun run preview |
Preview production build |
bun run lint |
Lint the codebase |
aichatvtwo/
├── src/ # Frontend React app
│ ├── components/ # React components
│ ├── contexts/ # React contexts
│ ├── pages/ # Page components
│ ├── services/ # API service layer
│ └── types/ # TypeScript types
├── server/ # Backend Express app
│ ├── src/
│ │ ├── auth.ts # Authentication logic
│ │ ├── chat.ts # Chat proxy
│ │ ├── chats.ts # Chat CRUD
│ │ ├── documents.ts # Document processing
│ │ ├── embeddings.ts # Embedding generation
│ │ ├── search.ts # Web search
│ │ ├── server.ts # Express server
│ │ ├── userSettings.ts # User settings
│ │ ├── extractors/ # Document extractors
│ │ └── utils/ # Utilities
│ └── database/ # SQLite DB and uploads (gitignored)
├── .github/workflows/ # CI/CD workflows
└── .env.local # Local environment (gitignored)
- Bun 1.0+ (or Node.js 20+ with npm)
- Persistent storage for database and uploads
The project includes a CI workflow (.github/workflows/ci.yml) that:
- Installs dependencies
- Runs linter
- Builds frontend
- Type-checks server
- Runs security audit
-
Set required environment variables:
JWT_SECRET=<strong-random-secret> ENCRYPTION_KEY=<32-byte-key> CORS_ORIGIN=https://your-frontend-domain.com NODE_ENV=production
-
Build the frontend:
bun run build
This creates a
dist/folder with static assets. -
Serve the frontend:
- Use a static hosting service (Vercel, Netlify, Cloudflare Pages)
- Or serve via Express by adding static middleware
-
Run the backend:
bun run server
- Ensure
server/database/is writable - Consider using PM2 or similar for process management
- Ensure
-
Database persistence:
- The SQLite database is stored in
server/database/chat.db - User uploads are in
server/database/uploads/ - Mount these directories to persistent storage in production
- The SQLite database is stored in
Frontend:
- Vercel, Netlify, Cloudflare Pages (static hosting)
- Set
VITE_API_BASE_URLto your backend URL
Backend:
- Railway, Render, Fly.io, DigitalOcean App Platform
- Ensure persistent volumes for database and uploads
- Set all required environment variables
AI Chat supports the Model Context Protocol, allowing you to extend AI capabilities by connecting to MCP servers.
MCP is an open protocol that enables AI applications to securely access external tools, data sources, and services. Think of it as a universal adapter that lets AI models interact with your local files, databases, APIs, and more.
-
Navigate to Settings → MCP Servers (Alt+6)
-
Choose a transport type:
- stdio: Run MCP servers as local processes (e.g., Node.js, Python scripts)
- SSE: Connect to remote servers via Server-Sent Events
- Streamable HTTP: Modern HTTP-based transport for remote servers
-
Example: Local File System Access
Name: File System Transport: stdio Command: npx Args: ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/directory"]
-
Test the connection before saving
-
Enable/disable servers as needed
Popular MCP servers you can use:
- @modelcontextprotocol/server-filesystem: Access local files
- @modelcontextprotocol/server-github: GitHub integration
- @modelcontextprotocol/server-postgres: PostgreSQL database access
- @modelcontextprotocol/server-sqlite: SQLite database access
- Custom servers: Build your own using the MCP TypeScript SDK
Once configured, MCP tools become available to the AI during conversations. The AI can:
- Call tools to perform actions (e.g., read files, query databases)
- Access resources (e.g., file contents, API responses)
- Use prompt templates defined by MCP servers
- 🔐 User API keys are encrypted at rest using AES-256-GCM
- 🍪 Authentication tokens are HTTP-only cookies with
sameSite=strict - 🔒 CORS restricted to configured origin
- 🛡️ JWT tokens required in production
See SECURITY.md for vulnerability reporting.
Frontend:
- React 19
- TypeScript
- Vite
- Tailwind CSS
- Framer Motion
- React Markdown with KaTeX
Backend:
- Express 5
- TypeScript
- SQLite (better-sqlite3)
- OpenAI SDK
- Model Context Protocol SDK
- JWT authentication
- Multer for file uploads
MIT
- Fork the repository
- Create a feature branch
- Make your changes
- Run
bun run lintandbun run build - Submit a pull request