A Retrieval-Augmented Generation (RAG) SaaS application with FastAPI backend, multi-tenant architecture, and an embeddable chat widget.
- 🔐 Authentication - JWT-based auth with user roles (admin/user)
- 📄 Document Management - Upload and process documents per user
- 🤖 RAG Chat - AI-powered chat with context from your documents
- 💳 Subscriptions - Stripe integration for paid plans
- 💾 Multi-tenant - Each user has isolated data storage
- 💬 Embeddable Widget - Chat widget for any website
- Backend: FastAPI, SQLAlchemy, PostgreSQL/SQLite
- AI: LangChain, Ollama, Pinecone
- Auth: fastapi-users (JWT)
- Payments: Stripe
- Frontend Widget: Vanilla JS Web Components + Shadow DOM
- Python 3.13+
- Node.js 18+ (for widget build)
- Ollama (for local LLM)
- Pinecone account (optional, for vector storage)
# Create virtual environment
python -m venv venv
source venv/bin/activate # Linux/Mac
# venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your API keys
# Run the server
python main.pyThe API will be available at http://localhost:8000
cd widget
# Install dependencies
npm install
# Build for production
npm run build
# The built files will be in dist/| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login and get JWT |
| GET | /api/auth/me |
Get current user |
| Method | Endpoint | Description |
|---|---|---|
| POST | /storage/upload |
Upload file |
| GET | /storage/files |
List user files |
| DELETE | /storage/files/{filename} |
Delete file |
| Method | Endpoint | Description |
|---|---|---|
| POST | /rag/query |
Query RAG system |
| POST | /rag/documents |
Process documents |
| GET | /rag/stats |
Get RAG statistics |
| Method | Endpoint | Description |
|---|---|---|
| GET | /payments/subscription |
Get subscription status |
| POST | /payments/checkout |
Create checkout session |
| POST | /payments/portal |
Open customer portal |
| Method | Endpoint | Description |
|---|---|---|
| GET | /widget/config |
Get widget configuration |
| GET | /widget/theme |
Get theme for premium users |
Add the widget to any website with just a few lines of code:
<!-- Add the script -->
<script src="https://your-domain.com/widget/rag-chat-widget.js"></script>
<!-- Add the widget element -->
<rag-chat-widget
site-id="your-site-id"
api-url="https://your-api.com">
</rag-chat-widget>| Attribute | Required | Description |
|---|---|---|
site-id |
Yes | Your site identifier |
api-url |
No | Backend API URL (defaults to current domain) |
position |
No | bottom-right (default) or bottom-left |
theme |
No | Theme name for premium users |
Premium users can customize colors by calling the theme endpoint:
// Fetch custom theme
fetch('/widget/theme?user_id=123')Returns CSS variables that can be applied to the widget.
cd widget
npm install
npm run buildOutput files:
dist/rag-chat-widget.js- ES moduledist/rag-chat-widget.umd.cjs- UMD bundle (for CDN)
rag-python/
├── app/
│ ├── auth/ # Authentication (fastapi-users)
│ ├── db/ # Database models
│ ├── payments/ # Stripe integration
│ ├── services/ # RAG service
│ ├── storage/ # File storage
│ ├── widget/ # Widget backend endpoints
│ └── app.py # Main FastAPI app
├── widget/
│ ├── src/
│ │ ├── components/ # UI components
│ │ ├── services/ # API client
│ │ └── styles/ # CSS
│ └── vite.config.js # Build config
├── alembic/ # Database migrations
├── tests/ # Test suite
└── main.py # Entry point
| Feature | Free | Premium |
|---|---|---|
| Max Documents | 10 | Unlimited |
| Max File Size | 10 MB | 100 MB |
| Max Vectors | 1,000 | Unlimited |
| RAG Queries/Day | 50 | Unlimited |
| Custom Theme | ❌ | ✅ |
pytest tests/ -v# Format with black
black .
# Lint with flake8
flake8 .
# Type check with mypy
mypy .MIT License