Skip to content

sharif2008/Chatwoot-RAG-AI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Priyo Chatbot

A multi-tenant RAG + Chatwoot platform where customers interact through Chatwoot, while a RAG backend retrieves relevant knowledge, queries an external LLM, and posts AI-generated responses back to the conversation. Operators manage tenants, users, knowledge documents, and Chatwoot integrations through a centralized dashboard. Each tenant has an isolated knowledge base, Chatwoot configuration, conversations, and vector store, ensuring complete data separation and secure AI-powered customer support.

A multi-tenant RAG + Chatwoot platform. Customers chat through Chatwoot; rag-backend retrieves knowledge, calls an external LLM, and posts replies back. Operators manage tenants, documents, and Chatwoot integration in the dashboard portal.

This monorepo has three parts. Use this README for the big picture; each folder has its own setup guide.


Table of contents

  1. Overview
  2. Architecture
  3. Repository
  4. Getting started
  5. Installation by part
  6. Integration
  7. Reference

1. Overview

Capabilities

Capability Where
Multi-tenant enterprises & users rag-backend + dashboard-portal
Knowledge upload (PDF, DOCX, TXT, MD) Dashboard → API → chunking + embeddings
Vector search (pgvector) Postgres in rag-backend compose
Local embeddings (BGE) embedding service
LLM answers External OpenAI (rag-backend/.env)
Chatwoot webhooks & outbound replies POST /api/v1/webhooks/chatwoot/{enterpriseId}
Operator admin UI dashboard-portal
Customer widget test site demo-ui — dev only

Roles

Role Scope
SUPER_ADMIN Platform owner — all enterprises
ENTERPRISE_ADMIN Single tenant — settings, knowledge, users, Chatwoot
ENTERPRISE_USER Single tenant — knowledge and query (limited admin)
HUMAN_AGENT Chatwoot inbox only
VIEWER Read-only overview

Tenant isolation is enforced in the API (enterpriseId on every row).

Enterprise (tenant)

An enterprise is one customer organization (tenant) on the platform — for example a company, brand, or support desk. Everything that belongs to that customer is scoped by a single enterpriseId (UUID). One Priyo deployment can host many enterprises; their data never mixes.

Field Description
id UUID — used in API paths and the Chatwoot webhook URL
name Display name (e.g. Acme Corp)
slug Unique URL-safe id (e.g. acme-corp, lowercase and hyphens)
description Optional notes about the tenant (max 2000 characters)
status ACTIVE, SUSPENDED, or INACTIVE

What belongs to an enterprise

Resource Purpose
Users ENTERPRISE_ADMIN and ENTERPRISE_USER accounts tied to this tenant (SUPER_ADMIN has no enterprise)
Knowledge documents PDF, DOCX, TXT, etc. — chunked, embedded, and searched only within this tenant
Chatwoot integration Base URL, account id, API token, inbox — one integration record per enterprise
Conversations & messages Chat history from Chatwoot webhooks, linked for RAG context
Webhook POST /api/v1/webhooks/chatwoot/{enterpriseId} routes inbound Chatwoot events to the correct tenant

Typical lifecycle

  1. SUPER_ADMIN creates an enterprise in the dashboard (name, slug, optional description).
  2. Upload knowledge for that enterprise until documents are READY.
  3. ENTERPRISE_ADMIN opens Settings in the dashboard — configure name, description, status.
  4. Configure Chatwoot Setting for the same enterpriseId.
  5. Register the webhook in Chatwoot using that UUID.
  6. End-customer messages on the Chatwoot inbox trigger RAG using only that enterprise’s knowledge base.
Platform (one rag-backend)
├── Enterprise A  →  knowledge A  →  Chatwoot inbox A  →  webhook …/chatwoot/{id-A}
├── Enterprise B  →  knowledge B  →  Chatwoot inbox B  →  webhook …/chatwoot/{id-B}
└── SUPER_ADMIN   →  manages all enterprises (no tenant scope)

Parts at a glance

Part Name Folder Port (dev) Required in prod
1 Chatwoot chatwoot-setup 3000 Yes
2a RAG API rag-backend 4000 Yes
2b Embeddings embedding 8088 Yes
2c Dashboard dashboard-portal 5000 Yes (operators)
3 Widget test demo-ui 8080 No (dev only)

2. Architecture

Full diagram (also at the top of this README):

Priyo Chatbot system architecture

Markdown link: docs/priyo-architecture.png

The stack has four layers — Users, Part 1 (Chatwoot), Part 2 (RAG), and External (OpenAI). Each enterprise gets isolated knowledge, webhook URL, and Chatwoot settings.

Layers and services

Layer Component Folder / service Port
Users Chat widget (customer) demo-ui or your site 8080
Users Human agent Chatwoot inbox UI
Users Operator dashboard-portal 5000
Part 1 Chatwoot inbox chatwoot-setup 3000
Part 1 Chatwoot Postgres internal to Chatwoot
Part 2a AI agent (webhook + reply) rag-backend 4000
Part 2a RAG backend per enterpriseId
Part 2 PostgreSQL + pgvector rag-backend compose 5433
Part 2b Embedding (BGE) embedding 8088
External OpenAI LLM prerequisite (OPENAI_API_KEY)

Flow legend

Arrow Meaning
Solid Message / data flow — widget → Chatwoot → AI agent → RAG → DB → LLM
Dashed Reply — AI agent → Chatwoot → widget
Dashed purple Operator admin REST — dashboard → rag-backend

Message flow (AI path)

  1. Customer sends a message via the Chatwoot widget → Chatwoot inbox.
  2. Chatwoot fires message_created webhook → AI agent (rag-backend :4000).
  3. RAG backend embeds the query → searches PostgreSQL/pgvector → calls embedding (:8088) as needed.
  4. RAG backend sends context + query to OpenAI → gets an answer.
  5. AI agent posts the reply through the Chatwoot API → customer sees it in the widget.

Human agents reply in Chatwoot directly. Operators use the dashboard for enterprises, Settings, knowledge, users, and Chatwoot integration.

Databases

Database Used by Notes
Chatwoot Postgres Chatwoot only Internal to chatwoot-setup compose
rag_enterprise_db + pgvector rag-backend Tenants, knowledge, vectors — host 5433 in dev

Each environment needs its own RAG database, secrets, and webhook URLs.


3. Repository

Folder layout

<repository-root>/
├── chatwoot-setup/      # Part 1
├── rag-backend/         # Part 2a (+ compose: DB, embedding)
├── embedding/           # Part 2b
├── dashboard-portal/    # Part 2c
├── demo-ui/             # Part 3
├── docs/                # priyo-architecture.png
└── README.md

Environment templates

Part Template Never commit
2a rag-backend/.env.example .env
2c dashboard-portal/.env.local.example .env.local
1 (dev) chatwoot-setup/.env.example .env

Share production secrets via a password manager or CI — not git.


4. Getting started

Suggested install sequence

Step Part Action
1 2 rag-backend: docker compose up -d
2 2c dashboard-portal: npm run dev
3 2 Register super admin → enterprise → knowledge (READY)
4 1 Chatwoot — official docs or chatwoot-setup
5 1 + 2 Integration — webhook + Chatwoot Setting
6 3 (optional) demo-ui on :8080

Local quick start

Step 1 — RAG stack (Part 2a + 2b + DB)

cd rag-backend
cp .env.example .env
# Edit: JWT_SECRET, OPENAI_API_KEY
docker compose up -d

Wait 1–3 minutes on first boot (embedding model), then:

curl http://127.0.0.1:8088/health
curl http://127.0.0.1:4000/api/v1/internal/live
URL
API http://127.0.0.1:4000
Swagger http://127.0.0.1:4000/api/docs
Hot reload rag-backend README

Step 2 — Dashboard (Part 2c)

cd dashboard-portal
cp .env.local.example .env.local
npm install && npm run dev

Open http://localhost:5000dashboard-portal/README.md.

Step 3 — Chatwoot (Part 1)

Production Official Docker deployment
Local dev chatwoot-setup/README.mdhttp://localhost:3000

Step 4 — Integration + widget test

Webhook §6 Integration
Widget test (optional) demo-uihttp://127.0.0.1:8080

Health checks

Part Service Check
2b Embedding curl http://127.0.0.1:8088/health
2a RAG API curl http://127.0.0.1:4000/api/v1/internal/live
2a Swagger http://127.0.0.1:4000/api/docs
2c Dashboard http://localhost:5000
1 Chatwoot http://localhost:3000
3 Demo widget http://127.0.0.1:8080

Embedding may need 1–3 minutes on first start — rag-backend troubleshooting.


5. Installation by part

Each part follows the same structure: overview → tech stack → prerequisites → install → docs.


Part 1 — Chatwoot

Folder chatwoot-setup/
Port 3000
Purpose Customer inbox, website widget, webhooks to rag-backend

Tech stack

Layer Technologies
Application Ruby on Rails, Sidekiq
Data PostgreSQL, Redis
Deploy Official Chatwoot Docker / K8s / VM
Dev helper chatwoot-setup/ compose (optional)

Prerequisites

Production Local dev
Guide Official Docker deployment chatwoot-setup README
Runtime Per official guide Docker Compose V2
Resources Postgres + Redis ~2 GB+ RAM
Network Public URL + TLS Port 3000
Config Chatwoot env vars .env.example.env

Install

Path Steps
Production Docker deployment · Environment variables
Local dev cp .env.example .envdb:chatwoot_preparedocker compose up -dchatwoot-setup/README.md

Handoff to Part 2

Credential Where
Base URL e.g. https://chat.example.com or http://localhost:3000
Account ID Account settings
API access token Profile → Access Token
Inbox Website inbox (id binds on first webhook)
Webhook URL After enterprise in Part 2 — §6 Integration

Documentation

Doc Purpose
chatwoot-setup/README.md Local compose + networking
rag-backend — Chatwoot setup Webhooks, API flow

Part 2 — RAG stack

Folders rag-backend/ · embedding/ · dashboard-portal/
Purpose Knowledge base, RAG, LLM replies, operator admin

Tech stack

Component Technologies Port
2a API NestJS 10, TypeORM, Passport/JWT, Node 20 4000
2b Embeddings Python 3.11, FastAPI, sentence-transformers (BGE) 8088
2c Dashboard Next.js 16, React 19, MUI, TanStack Query 5000
Database PostgreSQL 16, pgvector 5433
Dev Docker Compose V2 (rag-backend/docker-compose.yml)

Prerequisites

Production Development
Node.js 20+ 20+
Python 3.11+ (embedding) In Docker image
PostgreSQL 16+ + pgvector Via compose
Docker Optional Engine 20.10+, Compose 2.20+
Secrets JWT_SECRET, OPENAI_API_KEY rag-backend/.env.example
OpenAI (LLM) External account + API key Same
Dashboard API_URL → prod API .env.local.example
Ports 4000, 5000, 8088, 5433 free

Install

Component Production Development
2a + DB + 2b Production install cd rag-backend && cp .env.example .env && docker compose up -d
2c npm run build && npm run start + prod API_URL cd dashboard-portal && cp .env.local.example .env.local && npm install && npm run dev

Components (detail)

# Component README Notes
2a rag-backend README API, migrations, webhooks, Swagger
2b embedding README Started by compose; /v1/embed API
2c dashboard-portal README Overview, Settings (tenant admin), knowledge, Chatwoot Setting, API tokens
Nest embedding client src/rag/embedding/README.md HTTP client to 2b

Database

  • pgvector — chunk embeddings for similarity search
  • Migrations — on API startup (DATABASE_MIGRATIONS_RUN)
  • New env — fresh volume, new JWT_SECRET, no shared prod secrets

Part 3 — Widget test page

Folder demo-ui/
Port 8080
Purpose Static site + Chatwoot widget for local testing (not production)

Tech stack

Layer Technologies
Site Static HTML, Node.js static server
Widget Chatwoot Web SDK (/packs/js/sdk.js)

Prerequisites

Requirement Notes
Part 1 Chatwoot running (e.g. :3000)
Website inbox Script → demo-ui/index.html
Node.js 18+
Part 2 Optional — for AI replies (§6)
Port 8080 free

Install

Step Action
1 Chatwoot → Inboxes → Website → copy widget script (demo-ui README)
2 Paste into index.html or set BASE_URL + websiteToken
3 cd demo-ui && npm starthttp://127.0.0.1:8080
Verify Expected
Message in Chatwoot Widget OK
AI reply Part 2 integrated

Documentation

demo-ui/README.md


6. Integration

Connect Part 1 (Chatwoot) to Part 2 (RAG). Use Part 3 to test as a customer.

Steps

# Action
1 Create enterprise in dashboard (name, slug, description) — note enterpriseId (UUID)
2 Upload knowledge — status READY
3 Settings / Chatwoot Setting in dashboard — org details + Base URL, Account ID, API token
4 Webhook in Chatwoot: POST {RAG_API}/api/v1/webhooks/chatwoot/{enterpriseId}message_created
5 Send test message → AI reply or handoff in thread

Webhook URL

Environment Example
Local (Chatwoot in Docker, API on host) http://host.docker.internal:4000/api/v1/webhooks/chatwoot/<enterprise-uuid>
Production https://api.yourcompany.com/api/v1/webhooks/chatwoot/<enterprise-uuid>

Responsibilities

Task Where
Webhook, API token, inbox Chatwoot admin or dashboard Chatwoot Setting
Enterprise, knowledge, users dashboard-portal / rag-backend API
Secrets & URLs Part 1 handoff + Part 2 .env

Guides


7. Reference

Environment variables

Part Service Key variables Template
2a rag-backend JWT_SECRET, OPENAI_API_KEY, DATABASE_*, EMBEDDING_* .env.example
2c dashboard-portal API_URL, NEXT_PUBLIC_APP_NAME .env.local.example
1 chatwoot-setup SECRET_KEY_BASE, FRONTEND_URL, POSTGRES_*, REDIS_* .env.example
Variable Required for
JWT_SECRET API authentication
OPENAI_API_KEY LLM answers
EMBEDDING_BACKEND=local + EMBEDDING_SERVICE_URL BGE embeddings (default dev)
API_URL Dashboard → API proxy

Production vs development

Part Development Production
1 chatwoot-setup compose or official install Official Chatwoot install
2a–2b–DB docker compose up -d in rag-backend/ Separate Postgres, embedding, Nest — guide
2c npm run dev npm run build && npm run start
3 Optional :8080 Not used
Secrets Local .env CI / password manager

Documentation index

Part README
Overview This file
1 — Chatwoot chatwoot-setup/README.md · official docs
2a — API + DB rag-backend/README.md
2b — Embeddings embedding/README.md
2c — Dashboard dashboard-portal/README.md
3 — Widget test demo-ui/README.md
Diagram docs/priyo-architecture.png

About

A multi-tenant RAG + Chatwoot platform where customers interact through Chatwoot, while a RAG backend retrieves relevant knowledge, queries an external LLM, and posts AI-generated responses back to the conversation. Operators manage tenants, users, knowledge documents, and Chatwoot integrations through a centralized dashboard.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages