Skip to content
dav nguyxn edited this page Sep 30, 2025 · 1 revision

AI-RAG Assistant Chatbot (β€œLumina”) β€” Confluence/Wiki Page

Last updated:Β Sep 30, 2025
Owner:Β David NguyenΒ (repo:Β hoangsonww/AI-RAG-Assistant-Chatbot)


1) Overview

LuminaΒ is a full-stack RAG-powered chatbot that answers questions about David Nguyen or general topics. It pairs a modern React/MUI frontend with an Express/TypeScript backend, adds JWT authentication, and usesΒ Retrieval-Augmented Generation (RAG)Β viaΒ LangChainΒ andΒ PineconeΒ to ground LLM responses in a curated knowledge base. Logged-in users can save, search, and rename conversations; guests can chat without persistence.

Live apps

  • Frontend:Β https://lumina-david.vercel.app

  • Backend + Swagger:Β https://ai-assistant-chatbot-server.vercel.app

  • Backup frontend:Β https://lumina-ai-chatbot.netlify.app

Key Capabilities

  • Real-time chat with markdown rendering

  • RAG over personal knowledge base (Pinecone vector DB)

  • Auth (signup/login/reset) withΒ JWT

  • Conversation CRUD + search (MongoDB via Mongoose)

  • Guest mode (ephemeral conversations)

  • Light/Dark themes, responsive UI, polished animations

  • CI/CD viaΒ GitHub ActionsΒ (deploy to Vercel/Netlify)

  • OpenAPI spec + Swagger docs


2) Architecture at a Glance

[ User ] 
   β”‚  (browser)
   β–Ό
[ Frontend: React + MUI + TS ]
   β”‚  REST (HTTPS)
   β–Ό
[ Backend: Express + TS ]
   β”œβ”€ Auth (JWT)
   β”œβ”€ Conversations API
   β”œβ”€ Chat API (LLM + RAG orchestration w/ LangChain)
   β”‚
   β”œβ”€ MongoDB (Users, Conversations)
   └─ Pinecone (Vectors: knowledge chunks)
            β–²
            β”‚  indexer script (storeKnowledge.ts / npm run store)
            └─ Knowledge sources (docs, notes, etc.)

RAG loop (high-level)

  1. Embed & storeΒ knowledge in Pinecone (storeKnowledge.ts).

  2. RetrieveΒ top-k chunks from Pinecone for a user query (cosine similarity).

  3. AugmentΒ the prompt with retrieved context (LangChain).

  4. GenerateΒ an answer via LLM (OpenAI/Gemini).

  5. PersistΒ messages to MongoDB for authenticated users; useΒ ephemeralΒ storage for guests.


3) Repository Structure

AI-RAG-Assistant-Chatbot/
β”œβ”€β”€ client/                     # React + TS + MUI application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/         # Navbar, Sidebar, ChatArea
β”‚   β”‚   β”œβ”€β”€ pages/              # Landing, Home, Login, Signup, ForgotPassword, 404
β”‚   β”‚   β”œβ”€β”€ services/api.ts     # API client
β”‚   β”‚   β”œβ”€β”€ theme.ts            # Light/Dark themes
β”‚   β”‚   └── types/              # conversation.d.ts, user.d.ts
β”‚   β”œβ”€β”€ Dockerfile, docker-compose.yml, tsconfig.json, package.json
β”‚
β”œβ”€β”€ server/                     # Express + TS backend
β”‚   └── src/
β”‚       β”œβ”€β”€ server.ts           # App bootstrap
β”‚       β”œβ”€β”€ routes/             # auth.ts, conversations.ts, chat.ts
β”‚       β”œβ”€β”€ models/             # User.ts, Conversation.ts
β”‚       β”œβ”€β”€ middleware/         # auth.ts (JWT guard)
β”‚       β”œβ”€β”€ services/           # authService.ts
β”‚       β”œβ”€β”€ utils/              # ephemeralConversations.ts
β”‚       └── scripts/            # storeKnowledge.ts (RAG indexer)
β”‚   β”œβ”€β”€ Dockerfile, docker-compose.yml, tsconfig.json, package.json
β”‚
β”œβ”€β”€ openapi.yaml                # API contract (importable into Swagger/Postman)
β”œβ”€β”€ docker-compose.yml          # Root compose for local dev
β”œβ”€β”€ .github/workflows/          # CI/CD (build, test, deploy)
β”œβ”€β”€ Jenkinsfile                 # (legacy/optional)
β”œβ”€β”€ README.md, LICENSE, CITATION.cff
└── .env.example                # Example server env

4) Technology Stack

  • Frontend: React + TypeScript, Material UI (MUI)

  • Backend: Node.js, Express, TypeScript

  • Database: MongoDB (Mongoose)

  • Vector DB: Pinecone (k-NN cosine similarity)

  • RAG/Orchestration: LangChain

  • LLMs: OpenAI / Google Gemini (configurable)

  • Auth: JWT + middleware

  • Infra/Delivery: Vercel (FE), Netlify (FE backup), Vercel (BE)

  • Docs: OpenAPI + Swagger

  • CI/CD: GitHub Actions (install β†’ test β†’ build β†’ deploy; artifacts, linting)

  • Containers: Docker, docker-compose

  • Testing: Jest (FE + BE)

  • Misc: Python/Jupyter for experiments (optional)


5) Environments & Configuration

Environment Variables (server)

CreateΒ server/.envΒ (seeΒ .env.example) with:

PORT=5000
MONGODB_URI=mongodb://localhost:27017/ai-assistant
JWT_SECRET=replace_with_a_strong_secret
GOOGLE_AI_API_KEY=your_google_ai_api_key_here
AI_INSTRUCTIONS="System prompt for the assistant"
PINECONE_API_KEY=your_pinecone_api_key_here
PINECONE_INDEX_NAME=your_pinecone_index_name_here

Notes

  • JWT_SECRETΒ must be long and random; rotate if leaked.

  • AI_INSTRUCTIONSΒ holds your system prompt (persona/guardrails).

  • Ensure Pinecone index (dimension/metric) matches your embedding model.

Environment Variables (client)

CreateΒ client/.envΒ (if not already present):

REACT_APP_API_BASE_URL=http://localhost:5000

Update this value to the deployed backend URL in hosted environments.


6) Local Development

Prerequisites

  • Node 18+ / npm

  • Docker (optional, recommended)

  • MongoDB (local or Docker)

  • Pinecone account & index

Quick Start (no Docker)

Backend

git clone https://github.com/hoangsonww/AI-RAG-Assistant-Chatbot.git
cd AI-RAG-Assistant-Chatbot/server
npm install
# 1) Prepare .env (see above)
# 2) (One-time) index your knowledge into Pinecone:
npm run store           # or: npx ts-node src/scripts/storeKnowledge.ts
# 3) Run the API:
npm run dev             # ts-node + nodemon

Frontend

cd ../client
npm install
npm start               # http://localhost:3000

Dockerized Dev

From repo root:

docker-compose up --build

This brings up the FE and BE services as defined in rootΒ docker-compose.yml.
EditΒ .envΒ to point FE β†’ BE service hostname within the compose network if needed.


7) Data Model (high-level)

The exact schemas live inΒ server/src/models. Below is a typical structure to guide usage and API expectations.

User

  • emailΒ (unique),Β passwordHashΒ (bcrypt),Β name?

  • createdAt,Β updatedAt

  • emailVerified?Β or verification helper endpoints

Conversation

  • userIdΒ (ref User; omitted for guest)

  • title

  • messages[]Β ofΒ { role: 'user' | 'assistant', content: string, ts }

  • createdAt,Β updatedAt

Ephemeral Conversations

  • Utility (utils/ephemeralConversations.ts) handles non-authenticated chat state without DB writes.


8) API Reference (OpenAPI + Highlights)

OpenAPI:Β openapi.yamlΒ (repo root). Import into Swagger UI/Postman.
Deployed Swagger: at the backend host (e.g.,Β /docs).

Auth

  • POST /api/auth/signupΒ β€” create account
    Body:Β { email, password, name? }
    Returns:Β { token, user }

  • POST /api/auth/loginΒ β€” authenticate
    Body:Β { email, password }Β β†’Β { token, user }

  • GET /api/auth/verify-email?email=<addr>Β β€” email existence check

  • POST /api/auth/reset-passwordΒ β€” start/reset flow (implementation depends on env)

Example

curl -X POST "$API/api/auth/login" \
  -H "Content-Type: application/json" \
  -d '{"email":"me@example.com","password":"secret"}'

UseΒ Authorization: Bearer <token>Β for subsequent protected requests.

Conversations (JWT required)

  • POST /api/conversationsΒ β€” create new conversation
    Body:Β { title? }Β β†’Β { conversation }

  • GET /api/conversationsΒ β€” list all for user

  • GET /api/conversations/:idΒ β€” get by id

  • PUT /api/conversations/:idΒ β€” rename
    Body:Β { title }

  • GET /api/conversations/search/:queryΒ β€” title/content search

  • DELETE /api/conversations/:idΒ β€” delete

Chat

  • POST /api/chatΒ β€” send a user message and get AI response
    Body:Β { message: string, conversationId?: string }
    Returns:Β { reply, conversationId? }

    • Authenticated users: message persisted to conversation

    • Guests: handled via ephemeral store


9) RAG: Indexing & Retrieval

Indexing Knowledge (one-time or as needed)

# From server/:
npm run store
# or
npx ts-node src/scripts/storeKnowledge.ts
  • Reads your knowledge sources (implementation specific)

  • Splits/embeds documents

  • Upserts vectors intoΒ PineconeΒ (PINECONE_INDEX_NAME)

Tip: Re-run after updating the knowledge base.

Retrieval & Generation (runtime)

  1. Embed incoming user query.

  2. Pinecone similarity search (cosine) β†’ top-k chunks.

  3. Assemble prompt (system instructions + retrieved context + user query).

  4. Call configured LLM (OpenAI/Gemini).

  5. Stream/return markdown answer; persist if authenticated.


10) Frontend UX Notes

  • Pages: Landing, Home (chat), Login, Signup, Forgot Password, 404

  • Components:Β Navbar,Β SidebarΒ (collapsible, lists conversations),Β ChatArea

  • Theme: Light/Dark with localStorage persistence

  • Guest Mode: Skip auth; ephemeral conversations only


11) CI/CD

GitHub Actions (recommended)

Workflow inΒ .github/workflows/:

  • Install deps (client & server)

  • Lint,Β JestΒ tests

  • Build apps

  • Deploy:

    • FE β†’Β VercelΒ (primary) +Β NetlifyΒ (backup)

    • BE β†’Β Vercel

  • Artifacts upload, notifications on success/failure

Required secretsΒ (examples):Β VERCEL_TOKEN,Β VERCEL_PROJECT_ID_(client/server),Β NETLIFY_AUTH_TOKEN, etc., plus runtime env for both apps. Configure inΒ Repo Settings β†’ Secrets and variables β†’ Actions.

Jenkinsfile

Present for legacy/alt CI; prefer GitHub Actions unless org mandates Jenkins.


12) Deployment Runbook

  1. Prepare secretsΒ in Vercel/Netlify dashboards:

    • Server:Β MONGODB_URI,Β JWT_SECRET,Β PINECONE_*,Β AI_INSTRUCTIONS,Β GOOGLE_AI_API_KEY

    • Client:Β REACT_APP_API_BASE_URL

  2. TriggerΒ a release by merging to the main branch.

  3. Verify:

    • Backend health: openΒ /docsΒ and testΒ /api/auth/loginΒ with a test user.

    • Frontend health: loadΒ /Β andΒ /chat.

  4. Smoke test RAG:

    • Ask a question covered by the knowledge base; verify grounded response.

Rollback: Revert the commit or redeploy a prior successful build from Vercel/Netlify dashboards.


13) Security & Privacy

  • JWT: Signed withΒ JWT_SECRET. Store tokens only inΒ memoryΒ orΒ secure storageΒ on the client; avoid localStorage if possible.

  • Password hashing: Use bcrypt (or argon2) server-side.

  • CORS: Restrict origins in production.

  • PII: User emails are stored; conversation content may include sensitive dataβ€”ensure your privacy notice covers this.

  • Rate limiting: Recommended forΒ /api/chatΒ and auth routes.

  • Secrets management: Use platform secret managers; never commit secrets.

  • License: MIT (seeΒ LICENSE).


14) Testing

Frontend

cd client
npm test

Backend

cd server
npm test

Add integration tests for:

  • Auth flow (signup/login/jwt guard)

  • Conversation CRUD

  • Chat happy path + RAG retrieval stubs/mocks