Skip to content

thankyou0/embeddable-AI-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AI Chatbot Platform

A multi-tenant embeddable AI Chatbot Platform (SaaS) with RAG capabilities, built with React and FastAPI.

Features

  • 🏒 Multi-tenant Architecture: Each organization has isolated data and chatbots
  • πŸ€– Multiple Chatbots per Tenant: Create and manage multiple chatbots
  • πŸ“š Knowledge Ingestion: URLs, PDFs, PowerPoints, text, and Q&A pairs
  • πŸ” RAG Pipeline: Chunk β†’ Embed β†’ Vector Store β†’ Retrieve β†’ Generate
  • πŸ’¬ Two Embed Modes: Chat bubble script and iframe embed
  • πŸ“Š Admin Dashboard: Analytics, conversation history, and management
  • πŸ” Secure Authentication: JWT + refresh tokens with RBAC (admin/editor)
  • ⚑ Rate Limits & Billing: Usage tracking and quota management
  • 🎨 Customizable Appearance: Theme colors, bot names, avatars

Tech Stack

Backend

  • FastAPI (Python 3.11+)
  • PostgreSQL with SQLAlchemy + Alembic
  • ChromaDB/FAISS for vector storage
  • Google Gemini for embeddings + LLM

Frontend

  • React 18 with TypeScript
  • Vite for build tooling
  • TailwindCSS for styling
  • React Query for data fetching
  • Zustand for state management
  • Recharts for analytics charts

Project Structure

β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/           # API routes
β”‚   β”‚   β”œβ”€β”€ core/          # Config, security, logging
β”‚   β”‚   β”œβ”€β”€ db/            # Database models
β”‚   β”‚   β”œβ”€β”€ schemas/       # Pydantic schemas
β”‚   β”‚   β”œβ”€β”€ services/      # Business logic
β”‚   β”‚   └── main.py        # FastAPI app
β”‚   β”œβ”€β”€ alembic/           # Database migrations
β”‚   β”œβ”€β”€ static/            # Widget scripts
β”‚   └── requirements.txt
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ pages/         # Page components
β”‚   β”‚   β”œβ”€β”€ lib/           # API client
β”‚   β”‚   β”œβ”€β”€ store/         # Zustand stores
β”‚   β”‚   └── types/         # TypeScript types
β”‚   └── package.json
β”‚
└── README.md

Quick Start

Prerequisites

  • Python 3.11+
  • Node.js 18+
  • PostgreSQL 14+
  • Google Gemini API key

Backend Setup

  1. Create and activate virtual environment:
cd backend
python -m venv venv
# Windows
venv\Scripts\activate
# Linux/Mac
source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Configure environment:
# Copy example and edit with your values
cp env.example .env

Required environment variables:

DATABASE_URL=postgresql+asyncpg://user:pass@localhost:5432/chatbot_platform
SECRET_KEY=your-32-char-secret-key
JWT_SECRET_KEY=your-32-char-jwt-secret
GEMINI_API_KEY=your-gemini-api-key
  1. Create database:
# In PostgreSQL
CREATE DATABASE chatbot_platform;
  1. Run migrations:
alembic upgrade head
  1. Start the server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Frontend Setup

  1. Install dependencies:
cd frontend
npm install
  1. Start development server:
npm run dev

The frontend runs at http://localhost:3000 and proxies API requests to the backend.

Usage

1. Register an Account

Visit http://localhost:3000/register to create an account and organization.

2. Create a Chatbot

  1. Go to Chatbots β†’ Create Chatbot
  2. Configure name, system prompt, appearance
  3. Save the chatbot

3. Add Knowledge

  1. Open chatbot β†’ Knowledge Base
  2. Add URLs, upload PDFs/PPTs, or add Q&A pairs
  3. Wait for ingestion to complete

4. Embed the Chatbot

  1. Go to chatbot settings β†’ Get Embed Code
  2. Copy the script and add to your website:
<!-- Chat Bubble -->
<script>
  (function() {
    var script = document.createElement('script');
    script.src = 'http://your-domain.com/widget.js';
    script.setAttribute('data-chatbot-id', 'YOUR_CHATBOT_ID');
    script.async = true;
    document.body.appendChild(script);
  })();
</script>

Or use iframe:

<iframe
  src="http://your-domain.com/embed/chat/YOUR_CHATBOT_ID"
  width="400"
  height="600"
  frameborder="0"
></iframe>

API Documentation

Once the backend is running, visit:

  • Swagger UI: http://localhost:8000/api/docs
  • ReDoc: http://localhost:8000/api/redoc

Key Endpoints

Endpoint Description
POST /api/auth/register Register new user & tenant
POST /api/auth/login Login and get tokens
GET /api/chatbots List chatbots
POST /api/chatbots Create chatbot
POST /api/chatbots/{id}/knowledge/url Ingest URL
POST /api/chatbots/{id}/knowledge/file Upload PDF/PPT
POST /api/embed/chat/{id} Chat endpoint for widget
GET /api/admin/dashboard Dashboard stats

Vector Store Adapters

The platform supports multiple vector databases through an adapter interface:

# In backend/app/core/config.py
VECTOR_DB_TYPE=chroma  # or 'faiss'

To add a new adapter (e.g., Pinecone):

  1. Create backend/app/services/vector_stores/pinecone.py
  2. Implement the VectorStoreAdapter interface
  3. Add to factory in vector_store.py

Deployment

Backend (Render/Heroku)

  1. Set environment variables
  2. Use gunicorn with uvicorn workers:
gunicorn app.main:app -w 4 -k uvicorn.workers.UvicornWorker

Frontend (Vercel/Netlify)

  1. Build the frontend:
npm run build
  1. Deploy the dist folder

  2. Configure API URL in production

Database

Use a managed PostgreSQL service:

  • Render PostgreSQL
  • Heroku Postgres
  • Supabase
  • AWS RDS

Configuration Options

Chatbot Settings

Setting Description Default
system_prompt Instructions for the AI "You are a helpful assistant."
temperature Response creativity (0-2) 0.7
max_tokens Max response length 1000
theme_color Widget color #6366f1
allowed_domains CORS whitelist [] (all)

Tenant Limits

Plan Message Limit Features
Free 1,000/month Basic
Pro 10,000/month Priority support
Enterprise Custom SLA, dedicated

Security

  • Passwords hashed with bcrypt
  • JWT tokens with short expiry
  • Refresh token rotation
  • Rate limiting per tenant/session
  • Domain allowlisting for embeds
  • SQL injection protection via ORM

License

MIT License - see LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors