A modern, real-time AI chat interface built with Next.js 15, React 19, and Socket.IO. This embeddable chat application provides a seamless conversational experience with AI agents, featuring real-time streaming responses, markdown rendering, and a beautiful dark-themed UI.
- Real-time Chat: Stream AI responses in real-time using Socket.IO
- Multi-Agent Support: Connect with different AI agents dynamically
- Rich Markdown Rendering: Full support for markdown, code syntax highlighting
- Conversation History: Persistent conversations with automatic state management
- Responsive UI: Beautiful gradient-based dark theme with smooth animations
- Auto-reconnection: Automatic socket reconnection on connection loss
- Typing Indicators: Visual feedback during AI response generation
- Code Highlighting: Syntax highlighting for 180+ programming languages
- Embeddable: Designed to be embedded in other applications
- Next.js 15.4.6 - React framework with App Router
- React 19.1.0 - UI library with latest features
- TypeScript 5 - Type-safe development
- Redux Toolkit 2.9.2 - Global state management
- RTK Query - API data fetching and caching
- React Redux 9.2.0 - React bindings for Redux
- Socket.IO Client 4.8.1 - WebSocket-based real-time communication
- Tailwind CSS 4 - Utility-first CSS framework
- Tailwind Typography - Beautiful typographic defaults
- Lucide React - Modern icon library
- React Markdown 10.1.0 - Markdown component
- Remark GFM 4.0.1 - GitHub Flavored Markdown support
- Rehype Highlight 7.0.2 - Syntax highlighting
- React Syntax Highlighter 16.1.0 - Code block rendering
- Highlight.js 11.11.1 - Syntax highlighting engine
- ESLint 9 - Code linting
- Prettier 3.6.2 - Code formatting
- Husky 9.1.7 - Git hooks
- Lint-staged 16.2.6 - Pre-commit linting
- Node.js 20+ (recommended)
- npm, yarn, or pnpm package manager
- Backend API server (for agent data)
- Socket.IO server (for real-time communication)
-
Clone the repository
git clone <repository-url> cd chaitanya-embed
-
Install dependencies
npm install # or yarn install # or pnpm install
-
Set up environment variables
Create a
.env.localfile in the root directory:NEXT_PUBLIC_BACKEND_URL=http://localhost:3000 NEXT_PUBLIC_USER_ID=your-user-id NEXT_PUBLIC_SOCKET_URL=http://localhost:4000
NEXT_PUBLIC_BACKEND_URL: Your backend API endpointNEXT_PUBLIC_USER_ID: User identifier for authenticationNEXT_PUBLIC_SOCKET_URL: Socket.IO server URL
-
Start the development server
npm run dev
The application will be available at
http://localhost:3000
chaitanya-embed/
βββ app/ # Next.js App Router
β βββ layout.tsx # Root layout component
β βββ page.tsx # Main chat page
β βββ globals.css # Global styles
βββ components/ # React components
β βββ atoms/ # Atomic components
β β βββ TypingIndicator.tsx
β βββ molecules/ # Molecular components
β β βββ ChatMessage.tsx
β β βββ MarkdownRenderer.tsx
β βββ organisms/ # Organism components
β βββ templates/ # Template components
βββ context/ # React Context providers
β βββ app.tsx # App context for agent data
βββ hooks/ # Custom React hooks
β βββ useSocket.ts # Socket.IO hook
βββ store/ # Redux store
β βββ chaitanya.ts # RTK Query API endpoints
β βββ emptyApi.ts # Base API configuration
β βββ index.ts # Store configuration
β βββ provider.tsx # Redux provider
β βββ socket.ts # Socket service
β βββ socketSlice.ts # Socket state slice
βββ public/ # Static assets
βββ env.ts # Environment configuration
βββ next.config.ts # Next.js configuration
βββ tailwind.config.js # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
βββ package.json # Project dependencies
The project follows Atomic Design principles:
- Atoms: Basic UI elements (TypingIndicator)
- Molecules: Combinations of atoms (ChatMessage, MarkdownRenderer)
- Organisms: Complex UI sections
- Templates: Page-level layouts
- Redux Toolkit: Global application state
- RTK Query: API data fetching and caching with automatic re-fetching
- Socket Slice: WebSocket connection state management
- User sends a message
- Message is emitted to Socket.IO server via
streamevent - Server responds with:
stream.start: Streaming beginsstream.chunk: Individual message chunksstream.end: Streaming completestream.updated: Conversation metadata updatedstream.error: Error occurred
stream: Send a new message{ userId: string; agentId: string; message: string; conversationId?: string; metadata?: object; }
stream.start: AI starts respondingstream.chunk: Partial response chunk{ message: string; }
stream.end: Response completestream.updated: Conversation updated{ conversationId: string; }
stream.error: Error occurred{ error: string; }
The application uses a custom dark theme with:
- Gradient backgrounds
- Smooth transitions and animations
- Tailwind CSS utility classes
- Custom typography for markdown content
- Responsive design for all screen sizes
fadeIn: Smooth fade-in effect for messagespulse: Animated status indicatorsscale: Button hover effects
-
Get Current Agent
GET /embed/agent Headers: { 'x-user-id': string }
-
Get Agent by ID
GET /embed/agent/:id Headers: { 'x-user-id': string }
-
Get Conversation by ID
GET /embed/conversation/:id Headers: { 'x-user-id': string }
npm run build
npm run startEnsure all environment variables are set in your deployment platform:
NEXT_PUBLIC_BACKEND_URLNEXT_PUBLIC_USER_IDNEXT_PUBLIC_SOCKET_URL
- Vercel (optimized for Next.js)
- Netlify
- AWS Amplify
- Docker (containerized deployment)
npm run dev- Start development server with Turbopacknpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm run precommit- Run pre-commit hooks (lint-staged)
The project uses Husky and lint-staged to ensure code quality:
- Automatic code formatting with Prettier
- Linting on commit
- Format check for JS, TS, JSON, MD, and YAML files
Code is formatted according to .prettierrc rules.
- Follow TypeScript best practices
- Use functional components with hooks
- Follow Atomic Design principles
- Write meaningful commit messages
- Ensure all lint checks pass before committing
The chat uses Socket.IO to stream AI responses in real-time, providing a smooth user experience similar to ChatGPT.
Conversations are automatically saved and can be resumed using the conversation ID stored in localStorage.
The socket automatically reconnects when the user starts typing after a disconnection, ensuring seamless communication.
Full GitHub Flavored Markdown support including:
- Headers, lists, tables
- Code blocks with syntax highlighting
- Links, images, blockquotes
- Task lists
- Check if the Socket.IO server is running
- Verify
NEXT_PUBLIC_SOCKET_URLis correct - Check browser console for connection errors
- Clear
.nextfolder:rm -rf .next - Reinstall dependencies:
rm -rf node_modules && npm install - Check Node.js version (requires 20+)
- Ensure Tailwind CSS is properly configured
- Check
tailwind.config.jscontent paths - Verify
globals.cssis imported in layout
Built with β€οΈ using Next.js and React