A comprehensive real-time chat support service with embeddable widgets, admin dashboard, and backend API.
Demo β’ Features β’ Quick Start β’ Documentation β’ Contributing
- Demo
- Features
- Screenshots
- Project Structure
- Technology Stack
- Quick Start
- Chat Widget System
- Admin Dashboard
- API Endpoints
- WebSocket Events
- Docker Development
- Testing
- Configuration
- Performance
- Security
- Deployment
- Contributing
- License
- Support
Live Demo: Coming Soon | Widget Demo: Open
apps/web/dist/demo.htmlafter building
This system enables businesses to provide customer support through chat widgets embedded on their websites, with real-time messaging, ticket management, and admin oversight.
- Real-time Chat: WebSocket-powered instant messaging between clients and support agents
- Embeddable Widget: Standalone chat widget that can be embedded on any website
- Admin Dashboard: Comprehensive interface for managing chat rooms, tickets, and support operations
- Ticket Management: Automatic ticket creation from chat conversations with full lifecycle management
- Dual Widget System: Both integrated and standalone widget options
- Theme Support: Dark/light theme switching with system preference detection
- Persistent Sessions: Chat history and user data preserved across sessions
- Notification System: Real-time notifications for new messages and unread counts
- CORS Support: Configured for cross-origin requests including file:// protocol
- Anonymous Chat: Clients can start conversations without registration
- Agent Assignment: Automatic or manual assignment of support agents to chat rooms
- Chat History: Full conversation history with search and filtering
- Status Management: Room status tracking (waiting, active, closed)
- Message Read Receipts: Track read/unread status for both clients and agents
- Responsive Design: Works seamlessly on desktop and mobile devices
- Bundle Optimization: ~447KB minified widget with tree shaking and code splitting
Click to expand project structure
chat/
βββ apps/
β βββ web/ # Next.js Frontend Application
β βββ app/
β β βββ components/ # React Components
β β β βββ ChatWidget.tsx # Integrated chat widget
β β β βββ ChatWidgetSelector.tsx # Widget type selector
β β β βββ Header.tsx # Navigation header
β β β βββ Footer.tsx # Footer component
β β β βββ ThemeToggle.tsx # Theme switching
β β βββ admin/ # Admin Dashboard
β β β βββ page.tsx # Admin panel for chat management
β β βββ api/ # Next.js API Routes
β β β βββ auth/ # Authentication endpoints
β β β βββ chat-rooms/ # Chat room management
β β β βββ dashboard/ # Dashboard APIs
β β βββ context/ # React Contexts
β β β βββ AuthContext.tsx # Authentication state
β β β βββ ThemeContext.tsx # Theme management
β β βββ hooks/ # Custom React Hooks
β β β βββ useWebSocket.ts # WebSocket connection
β β β βββ usePageData.ts # Page data management
β β βββ login/ # Login page
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Home page
β βββ widget/ # Standalone Chat Widget
β β βββ components/ # Widget-specific components
β β β βββ ChatHeader.tsx # Widget header
β β β βββ ChatFooter.tsx # Widget footer
β β β βββ MessageInput.tsx # Message input component
β β β βββ MessageDisplay.tsx # Message display
β β β βββ EmailInputForm.tsx # Email input form
β β β βββ ChatToggleButton.tsx # Widget toggle button
β β βββ contexts/ # Widget contexts
β β β βββ ThemeProvider.tsx # Widget theme provider
β β βββ hooks/ # Widget hooks
β β β βββ useWebSocket.ts # Widget WebSocket hook
β β βββ types/ # TypeScript types
β β βββ config/ # Widget configuration
β β βββ utils/ # Utility functions
β β βββ StandaloneChatWidget.tsx # Main standalone widget
β β βββ index.tsx # Widget entry point
β β βββ styles.css # Widget styles
β β βββ demo.html # Widget demo page
β βββ scripts/ # Build scripts
β β βββ set-chat-widget.js # Widget type switcher
β βββ dist/ # Built widget files
β βββ test.html # Widget test page
β βββ webpack.config.js # Widget build configuration
β βββ package.json # Dependencies and scripts
βββ back/
βββ user-service/ # NestJS Backend Service
βββ src/
β βββ support/ # Support System Module
β β βββ schemas/ # MongoDB Schemas
β β β βββ chat-room.schema.ts # Chat room data model
β β β βββ ticket.schema.ts # Support ticket model
β β β βββ comment.schema.ts # Comment model
β β βββ dto/ # Data Transfer Objects
β β β βββ chat-room.dto.ts # Chat room DTOs
β β β βββ create-ticket.dto.ts # Ticket creation DTOs
β β βββ support.controller.ts # Support API endpoints
β β βββ support.service.ts # Support business logic
β β βββ chat-room.controller.ts # Chat room endpoints
β β βββ chat-room.service.ts # Chat room business logic
β β βββ chat.gateway.ts # WebSocket gateway
β β βββ support.module.ts # Support module definition
β βββ app.module.ts # Main application module
β βββ main.ts # Application bootstrap
βββ docker-compose.yml # Docker development setup
βββ Dockerfile # Production Docker image
βββ Dockerfile.dev # Development Docker image
βββ package.json # Backend dependencies
Frontend (Next.js Application)
- Framework: Next.js 15.2.4 with App Router
- Runtime: React 19.0.0
- Language: TypeScript 5
- Styling: Tailwind CSS 4
- Animations: Framer Motion 12.6.1
- WebSocket: Socket.io-client 4.8.1
- Authentication: JSON Web Tokens (JWT)
- Build Tool: Webpack 5 (for widget bundling)
Backend (NestJS Service)
- Framework: NestJS (Node.js)
- Database: MongoDB with Mongoose ODM
- WebSocket: Socket.io with NestJS Gateway
- Authentication: JWT with Passport
- API Documentation: Swagger/OpenAPI
- Validation: Class-validator and Class-transformer
- Environment: Docker with Docker Compose
Widget System
- Bundler: Webpack 5 with UMD output
- Styling: CSS with PostCSS
- Isolation: Scoped styles with CSS containment
- Distribution: Self-contained JavaScript bundle
- Node.js 18+
- MongoDB (local or cloud instance)
- Docker and Docker Compose (optional)
- Clone the repository:
git clone https://github.com/Milad93R/chat-support-service.git
cd chat-support-service- Install dependencies:
# Frontend
cd apps/web
npm install
# Backend
cd ../../back/user-service
npm install- Environment Configuration:
Frontend (apps/web/.env.local):
NEXT_PUBLIC_AUTH_API_URL=http://localhost:3003
BACKEND_URL=http://localhost:3003
JWT_SECRET=your-super-secret-jwt-key-here
# Chat Widget Configuration
NEXT_PUBLIC_CHAT_WIDGET_TYPE=standaloneBackend (back/user-service/.env):
MONGODB_URI=mongodb://localhost:27017/chat-support
PORT=3003
NODE_ENV=development- Start the services:
Option A: Using Docker (Recommended)
# Start backend services
cd back/user-service
docker compose up -d
# Start frontend
cd ../../apps/web
npm run devOption B: Local Development
# Start MongoDB locally
mongod
# Start backend
cd back/user-service
npm run start:dev
# Start frontend
cd ../../apps/web
npm run dev- Access the application:
- Frontend: http://localhost:3078
- Admin Dashboard: http://localhost:3078/admin
- API Documentation: http://localhost:3003/api
- MongoDB Express: http://localhost:8081 (admin/admin123)
The application supports two widget implementations:
- Fully integrated with the Next.js application
- Uses app's theme system and authentication context
- Best for applications where the widget should match the app's design
- Requires the full Next.js application context
- Self-contained widget with its own theme system
- Can be embedded in any website without dependencies
- Includes all necessary React components bundled
- Best for third-party integrations and distribution
Using NPM Scripts (Recommended):
# Switch to integrated widget
npm run widget:integrated
# Switch to standalone widget
npm run widget:standalone
# Show help and current widget type
npm run widget:helpManual Configuration:
Update .env.local:
NEXT_PUBLIC_CHAT_WIDGET_TYPE=integrated # or 'standalone'cd apps/web
npm run build:widgetThis creates:
dist/chat-widget.js- The standalone widget bundledist/demo.html- Demo page with usage examples
Simple HTML Integration:
<div id="chat-widget-container"
data-api-base-url="http://localhost:3003"
data-socket-url="http://localhost:3003"></div>
<script src="path/to/chat-widget.js"></script>Programmatic Integration:
window.initChatWidget({
apiBaseUrl: 'https://your-api-server.com',
socketUrl: 'https://your-socket-server.com',
containerId: 'my-chat-widget'
});- Chat Room Management: View and manage all active chat rooms
- Real-time Messaging: Send and receive messages in real-time
- Room Assignment: Assign agents to specific chat rooms
- Status Management: Update room status (waiting, active, closed)
- Message History: View complete conversation history
- Notification System: Real-time notifications for new messages
- Statistics: View support metrics and performance data
- URL: http://localhost:3078/admin
- Default Credentials:
- Email:
admin@example.com - Password:
admin123
- Email:
- View all chat rooms with filtering and sorting
- Join chat rooms to assist clients
- Send messages as support agent
- Mark messages as read
- Close chat rooms
- View chat statistics
Click to expand API documentation
POST /api/auth/login- Admin loginGET /api/auth/profile- Get user profile
GET /api/chat-rooms- Get all chat roomsPOST /api/chat-rooms- Create new chat roomGET /api/chat-rooms/:roomId- Get specific roomPUT /api/chat-rooms/:roomId- Update roomDELETE /api/chat-rooms/:roomId- Delete roomPOST /api/chat-rooms/:roomId/messages- Send messagePUT /api/chat-rooms/:roomId/messages/read- Mark as readGET /api/chat-rooms/:roomId/unread-count- Get unread count
GET /api/dashboard/support- Get support ticketsPOST /api/dashboard/support- Create support ticketPUT /api/dashboard/support- Update support ticketGET /api/dashboard/support/stats- Get support statistics
GET /api/chat-rooms/client/:clientEmail- Get client's chat roomGET /api/chat-rooms/notifications/counts- Get notification counts
Click to expand WebSocket documentation
join-room- Join a chat roomleave-room- Leave a chat roomsend-message- Send a messagemark-messages-read- Mark messages as readget-notification-counts- Get notification counts
new-message- New message receivedroom-joined- Successfully joined roomroom-left- Successfully left roomnotification-counts- Updated notification countsroom-list-update- Room list updatederror- Error occurred
cd back/user-service
docker compose up -dThis starts:
- MongoDB: Database server (port 27017)
- API Service: NestJS backend (port 3003)
- Mongo Express: Database management UI (port 8081)
# Start all services
docker compose up -d
# View logs
docker compose logs -f
# Stop services
docker compose down
# Rebuild and restart
docker compose up --build -d
# Clean up everything
docker compose down -v# Build the widget
npm run build:widget
# Open test page
open apps/web/test.htmlThe backend includes Swagger documentation at:
- Open the main application: http://localhost:3078
- Click the chat widget to start a conversation
- Open admin dashboard: http://localhost:3078/admin
- Login with admin credentials
- View the chat room and respond to messages
Frontend Configuration:
NEXT_PUBLIC_AUTH_API_URL=http://localhost:3003
BACKEND_URL=http://localhost:3003
JWT_SECRET=your-jwt-secret
NEXT_PUBLIC_CHAT_WIDGET_TYPE=standaloneBackend Configuration:
MONGODB_URI=mongodb://localhost:27017/chat-support
PORT=3003
NODE_ENV=developmentThe standalone widget can be configured via:
- HTML data attributes
- JavaScript initialization parameters
- Environment variables (for integrated widget)
The backend is configured to handle CORS for:
- Development origins (localhost ports)
- File protocol (
file://) for standalone widget testing - Custom origins (configurable)
- Standalone Widget: ~447KB minified
- Includes: React, Socket.io, all dependencies
- Optimization: Tree shaking, code splitting, minification
- MongoDB: Indexed queries for chat rooms and messages
- WebSocket: Efficient real-time updates
- Caching: Message history and user sessions
- JWT-based authentication for admin users
- Session persistence in localStorage
- Token expiration handling
- Configured allowed origins
- Credential support for authenticated requests
- Protection against unauthorized access
- Input validation on all API endpoints
- TypeScript type safety
- MongoDB schema validation
# Frontend
cd apps/web
npm run build
npm start
# Backend
cd back/user-service
npm run build
npm run start:prod
# Widget
cd apps/web
npm run build:widget# Backend
cd back/user-service
docker build -t chat-support-api .
docker run -p 3003:3003 chat-support-api
# Frontend
cd apps/web
docker build -t chat-support-web .
docker run -p 3078:3078 chat-support-web- Set up MongoDB instance
- Configure environment variables
- Build and deploy services
- Set up reverse proxy (nginx)
- Configure SSL certificates
We welcome contributions! Please see our Contributing Guidelines for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Make your changes
- Add tests if applicable
- Commit your changes:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Follow TypeScript best practices
- Use ESLint and Prettier for code formatting
- Write meaningful commit messages
- Add JSDoc comments for complex functions
- Follow the existing project structure
- Use GitHub Issues for bug reports and feature requests
- Provide detailed reproduction steps
- Include system information and logs
- Check existing issues before creating new ones
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- π Check the API documentation
- π Review the widget README
- π³ Check Docker setup guide
- π Report bugs via GitHub Issues
- π¬ Join discussions in GitHub Discussions
How do I embed the widget on my website?
See the Chat Widget System section for detailed instructions on embedding the standalone widget.
Can I customize the widget appearance?
Yes! The widget supports theme customization and you can modify the CSS in apps/web/widget/styles.css.
Is this production-ready?
The system includes production-ready features like Docker support, security configurations, and performance optimizations. However, please review and test thoroughly before deploying to production.
- Widget System: Dual widget support (integrated/standalone)
- CORS Support: Enhanced CORS for file:// protocol
- Bundle Optimization: Improved webpack configuration
- Admin Dashboard: Real-time chat management interface
- WebSocket Gateway: Enhanced real-time communication
- Docker Support: Complete containerized development environment
β Star this repository if you find it helpful!



