Skip to content

aadithya2112/chatterly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chatterly – Embeddable AI Chat Widget with Analytics

An AI-powered chat widget you can drop into any website, plus a modern dashboard to track user conversations and analytics.

Video Demo

Click the image below to watch a short video demo of the project. It showcases the embeddable chat widget in action, along with the analytics dashboard.

Watch the video

Table of Contents

  1. Features
  2. Architecture
  3. Tech Stack
  4. Getting Started
    1. Prerequisites
    2. Install & Dev
    3. Environment Variables
  5. Project Structure
  6. Embedding the Widget
  7. Deployment & Demos
  8. Challenges & Solutions
  9. Contributing
  10. License

Features

  • Embeddable Widget: AI chat powered by WebSocket + Express API
  • Multi-user Support: Each user can mint multiple widgets
  • Analytics Dashboard: Conversation metrics, usage trends, and more
  • Zero-Config Embed: Copy & paste a single <script> tag
  • Real-time Updates: Socket.io for live chat sessions

Architecture

Monorepo with Turborepo & Bun:

  • apps/chat-widget – React + Vite embeddable widget
  • apps/web – Next.js dashboard & HTTP API
  • apps/backend – Bun + Express + Socket.io server
  • packages/db – Prisma client & database layer

Data Flow

  1. Widget opens a WebSocket to backend → streams user messages.
  2. Backend invokes AI via gemini API → pushes responses back.
  3. REST calls from web (Next.js) read/write analytics via packages/db.
  4. Dashboard UI shows aggregated metrics and real-time sessions.

Tech Stack

  • Language: TypeScript
  • Frameworks: React, Next.js, Express, Socket.io
  • Bundler: Vite (widget), Turbo (monorepo)
  • Runtime: Node.js ≥18 & Bun
  • DB: Prisma + PostgreSQL database
  • Deployment: Digital Ocean (socketio server and nextjs server), GitHub Pages (widget via gh-pages)

Getting Started

Prerequisites

  • Node.js ≥18
  • Bun v1.2.9+ (for backend & db)
  • (Optional) Yarn, npm or pnpm

Install & Dev

Clone & install:

git clone https://github.com/aadithya2112/chatterly
cd chatterly
# install everything
bun install

Run all services in dev mode:

bun run dev
# → dashboard & widget & backend start concurrently

Individually: (Recommended)

  • Generate Prisma Client
    cd packages/db && bunx prisma generate
  • Dashboard (Next.js)
    cd apps/web && bun run dev
  • Widget (Vite)
    cd apps/chat-widget && bun run dev
  • Backend (Socket.io)
    cd apps/backend && bun src/index.ts

Environment Variables

Create a .env (for each app) from .env.example:

# apps/backend/.env
GOOGLE_GENAI_API_KEY=""

# apps/web/.env
DATABASE_URL="postgres://user:pass@localhost:5432/db"
JWT_SECRET=""

# packages/db/.env
DATABASE_URL="postgres://user:pass@localhost:5432/db" # Same as web

## Project Structure

/ ├─ apps/ │ ├─ chat-widget/ # React widget (Vite) │ ├─ web/ # Dashboard & HTTP API (Next.js) │ └─ backend/ # WebSocket server (Bun + Express) └─ packages/ ├─ db/ # Prisma client & migrations


## Embedding the Widget

Once you’ve built & deployed `apps/chat-widget` (→ GitHub Pages or your CDN), add this to any HTML:

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Load the chat widget -->
    <script
      defer
      src="https://YOUR_CDN_URL/chat-widget.js"
      data-widget-id="WIDGET_ID"
      data-api-url="https://dashboard.yoursite.com/api"
      data-ws-url="wss://api.yoursite.com"
    ></script>
  </head>
  <body>
    <h1>My page with AI Chat</h1>
  </body>
</html>
  • data-widget-id: Unique ID from your Dashboard
  • data-api-url: REST endpoints for auth/analytics
  • data-ws-url: WebSocket endpoint for live chat

Deployment & Demos

Challenges & Solutions

  • CORS & WebSocket Upscaling
    Enabled wildcard CORS on Socket.io; for production, lock to whitelisted domains.
  • Monorepo Builds
    Leveraged Turborepo cache to parallelize builds & reduce CI time by 70%.
  • Shared Types
    Configured packages/typescript-config & workspace path aliases to avoid duplication.

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •