Home
Softono
Live-Chat-Support-Demo

Live-Chat-Support-Demo

Open source MIT TypeScript
16
Stars
3
Forks
0
Issues
1
Watchers
1 month
Last Commit

About Live-Chat-Support-Demo

Real-time, open-source chat widget with admin panel β€” built with Next.js, Socket.IO, Zustand, and TailwindCSS.

Platforms

Web Self-hosted

Languages

TypeScript

License Last Commit Issues Stars

Built with Next.js Socket.IO

πŸ’¬ Live Chat Support Demo

This repo is a template β€” click Use this template to create your own real-time chat support app instantly!

A real-time support chat app built with Next.js (App Router), Socket.IO, Zustand, and Tailwind CSS. Visitors can instantly chat with an admin, while both sides see messages update in real time. All chats are locally persisted per role.

Featured on Dev.to πŸš€ Live Chat Support Starter Kit β€” Open Source!


✨ Features

  • βœ… Real-time chat with Socket.IO
  • ⌨️ Typing indicators (visitor ↔ admin)
  • πŸ§‘β€πŸ’» Separate interfaces for visitor and admin
  • 🧠 Role-based persistence:
    • Visitor chats β†’ sessionStorage
    • Admin chats β†’ localStorage
  • πŸ’» Deployed on Vercel (frontend) + Railway (Socket.IO backend)
  • πŸ’… Styled with Tailwind CSS

πŸ“ Project Structure

.
β”œβ”€β”€ frontend/           β†’ Next.js frontend application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/       β†’ Admin & visitor views
β”‚   β”‚   β”œβ”€β”€ components β†’ Shared components
β”‚   β”‚   β”œβ”€β”€ store/     β†’ Zustand state
β”‚   β”‚   β”œβ”€β”€ lib/       β†’ Socket.IO client
β”‚   β”‚   β”œβ”€β”€ types/     β†’ Type definitions
β”‚   β”‚   β”œβ”€β”€ config/    β†’ Configuration files
β”‚   β”‚   └── styles/    β†’ Tailwind styles
β”‚   β”œβ”€β”€ public/        β†’ Static assets
β”‚   β”œβ”€β”€ package.json   β†’ Frontend dependencies
β”‚   └── [config files] β†’ Next.js, TypeScript, etc.
└── backend/           β†’ Socket.IO server
    β”œβ”€β”€ server.js      β†’ Main server entry point
    β”œβ”€β”€ controllers/   β†’ Socket.IO event handlers
    β”œβ”€β”€ services/      β†’ Business logic
    β”œβ”€β”€ routes/        β†’ HTTP routes (if needed)
    β”œβ”€β”€ utils/         β†’ Utility functions
    └── package.json   β†’ Backend dependencies

βš™οΈ Configuration

The application uses a centralized configuration system located in frontend/src/config/:

Chat Configuration (chat.ts)

export const chatConfig = {
  welcomeMessage: 'Hi πŸ‘‹ How can we help you?',  // Initial greeting message
  defaultAgentName: 'Support Team',  // Default name for support agents
};

To modify the chat appearance or behavior:

  1. Update the values in chatConfig
  2. The changes will automatically reflect across all components using these settings

Environment Configuration

  • Frontend: .env.local

    NEXT_PUBLIC_API_URL=http://localhost:3001
  • Backend: .env

    FRONTEND_URL=http://localhost:3000
    FRONTEND_URL_2=https://staging.your-app.com    # Optional: Additional frontend URL
    FRONTEND_URL_3=https://dev.your-app.com        # Optional: Additional frontend URL
    PORT=3001

    πŸ’‘ Multiple Frontend URLs: You can configure multiple frontend URLs by setting additional environment variables (FRONTEND_URL_2, FRONTEND_URL_3, etc.). This is useful when you have multiple environments (staging, development, etc.) that need to connect to the same backend. The backend will automatically handle CORS for all configured URLs.


🧠 State Management

The application uses Zustand for state management with the following key stores:

Chat Store (store/chatStore.ts)

interface ChatState {
  messages: Message[];
  user: User | null;
  conversations: Record<string, Message[]>;
  onlineVisitors: Set<string>;
  isChatFocused: boolean;
  selectedVisitorId: string | null;
  role: UserRole | null;
  // ... actions
}

Key features:

  • Role-based persistence (admin/visitor)
  • Real-time message synchronization
  • Online status tracking
  • Conversation management

Usage Example

const { messages, user, sendMessage } = useChatStore();

// Send a message
sendMessage({
  conversationId: '123',
  senderId: user.id,
  content: 'Hello!'
});

🧩 Component Architecture

The application follows a modular component structure:

Visitor Components

  • ChatWidget: Floating chat button and window container
  • ChatWindow: Main chat interface for visitors
  • MessageBubble: Individual message display
  • MessageInput: Message composition and sending

Admin Components

  • ChatHeader: Conversation header with visitor info
  • VisitorList: List of active visitors
  • ChatContainer: Main admin chat interface

Shared Components

  • Avatar: User avatar display
  • DarkModeToggle: Theme switching
  • ErrorToast: Error notifications
  • MessageInput: Sends messages and emits Socket.IO typing start/stop (debounced idle)

Component Communication

  • Components communicate through Zustand store
  • Real-time updates via Socket.IO
  • Props for component-specific configuration

πŸ§ͺ Dev Tips

  • Open admin and visitor tabs to simulate both roles
  • Test real-time message syncing
  • Test persistence:
    • Reload the tab
    • Visitor chat clears after closing the tab
    • Admin chat stays saved across reloads (localStorage)

🌍 Deployment Notes

Frontend β†’ Vercel

  1. Create a new project in Vercel and connect it to your repository

  2. Configure the following settings in Vercel:

    • Framework Preset: Next.js
    • Root Directory: frontend
    • Build Command: npm run build
    • Output Directory: .next
    • Install Command: npm install
  3. Set the following environment variables in Vercel:

    NEXT_PUBLIC_API_URL=https://your-railway-backend.up.railway.app
  4. Deploy using the Vercel CLI:

    # Install Vercel CLI if you haven't already
    npm i -g vercel
    
    # Deploy
    vercel --prod

Backend β†’ Railway

  • Set start command: node server.js
  • Set environment variables:
FRONTEND_URL=https://your-vercel-project.vercel.app
  • Make sure ports are not hardcoded β€” use process.env.PORT

🧠 Technologies Used


πŸ’‘ Future Improvements

  • πŸ“ Export/download chat history
  • πŸ—ƒ Add backend persistence (DB)
  • πŸ” Auth for both roles
  • πŸ‘₯ Multi-agent support
  • πŸ”„ Support for parallel chats with multiple users

πŸ“„ License

MIT β€” use freely and modify as you wish!


πŸ‘‹ Author

Made with ❀️ by Sanja Malovic