JohnReedLOL/Real-Time-Typing-Chat

โ˜… 0Forks 0GitHub โ†—Compare

Project website โ†—

README

Real-Time Typing Chat App

A beautiful, minimalist real-time chat application where users can see each other's typing character-by-character instantly. Built with Next.js 14, Socket.IO, and Tailwind CSS.

Features

  • โšก Real-time typing synchronization - See every keystroke instantly
  • ๐Ÿ”„ Two-way communication - Both users can type simultaneously
  • ๐Ÿ“ฑ Responsive design - Side-by-side on desktop, stacked on mobile
  • ๐ŸŽจ Beautiful UI - Clean, modern interface with smooth animations
  • ๐Ÿ”— Shareable sessions - Generate unique session links to invite others
  • ๐Ÿšซ No registration - Start chatting immediately without accounts
  • ๐Ÿ“Š Connection status - Real-time indicators and user presence
  • ๐Ÿงน Ephemeral sessions - Automatic cleanup of inactive sessions

Tech Stack

  • Frontend: Next.js 14 (App Router), React, TypeScript
  • Styling: Tailwind CSS, shadcn/ui components
  • Real-time: Socket.IO
  • Backend: Node.js, Express
  • Icons: Lucide React
  • Deployment: Vercel (frontend), Railway (WebSocket server)

Architecture

This app uses a separate deployment strategy:

  • Frontend: Static Next.js app deployed to Vercel/Netlify
  • WebSocket Server: Node.js server deployed to Railway

Getting Started

Prerequisites

  • Node.js 16+
  • npm or yarn

Local Development

  1. Clone the repository

    git clone <your-repo-url>
    cd realtime-chat-app
  2. Install dependencies

    npm install
  3. Start the WebSocket server (in server directory)

    cd server
    npm install
    npm run dev
  4. Start the Next.js development server (in root directory)

    npm run dev
  5. Open your browser

Deployment

Step 1: Deploy WebSocket Server to Railway

  1. Create a new Railway project
  2. Connect your GitHub repository
  3. Set the Root Directory to server
  4. Railway will automatically detect the Node.js app
  5. Set environment variables:
    • NODE_ENV=production
    • FRONTEND_URL=https://your-frontend-domain.com (optional)
  6. Deploy and note the Railway URL (e.g., https://your-app.up.railway.app)

Step 2: Deploy Frontend to Vercel

  1. Push your code to GitHub
  2. Connect your repository to Vercel
  3. Vercel will automatically detect the Next.js app
  4. The frontend will be deployed as a static site
  5. No environment variables needed (WebSocket URL is hardcoded)

Step 3: Update WebSocket URL (if needed)

If your Railway URL is different, update the WebSocket URL in: app/chat/[sessionId]/page.tsx line 32:

const socketUrl = 'https://your-railway-app.up.railway.app';

Environment Variables

Frontend: No environment variables needed

Backend (Railway):

NODE_ENV=production
PORT=3001
FRONTEND_URL=https://your-frontend-domain.com

Project Structure

โ”œโ”€โ”€ app/                    # Next.js app directory
โ”‚   โ”œโ”€โ”€ chat/[sessionId]/  # Dynamic chat page
โ”‚   โ”œโ”€โ”€ globals.css        # Global styles
โ”‚   โ”œโ”€โ”€ layout.tsx         # Root layout
โ”‚   โ””โ”€โ”€ page.tsx           # Landing page
โ”œโ”€โ”€ components/            # Reusable components
โ”‚   โ””โ”€โ”€ ui/               # shadcn/ui components
โ”œโ”€โ”€ lib/                  # Utility functions
โ”œโ”€โ”€ server/               # WebSocket server (separate deployment)
โ”‚   โ”œโ”€โ”€ index.js          # Server implementation
โ”‚   โ””โ”€โ”€ package.json      # Server dependencies
โ””โ”€โ”€ README.md

How It Works

  1. Session Creation: Users create a unique session ID or join an existing one
  2. Real-time Connection: Socket.IO establishes WebSocket connection to Railway server
  3. Typing Sync: Every keystroke is immediately broadcast to connected users
  4. User Management: Server tracks active users and their typing status
  5. Session Cleanup: Inactive sessions are automatically cleaned up

Troubleshooting

Connection Issues

  1. Check that the Railway WebSocket server is running
  2. Verify the WebSocket URL in the frontend code
  3. Check browser console for connection errors
  4. Test the health endpoint: https://your-railway-app.up.railway.app/health

Railway Deployment Issues

  1. Ensure Root Directory is set to server
  2. Check that package.json exists in the server directory
  3. Verify environment variables are set correctly
  4. Check Railway logs for server errors

Browser Support

  • Chrome/Edge 90+
  • Firefox 88+
  • Safari 14+
  • Mobile browsers with WebSocket support

Performance

  • Optimized for low latency
  • Efficient WebSocket message handling
  • Automatic cleanup of inactive sessions
  • Client-side debouncing for typing indicators

Security

  • CORS properly configured
  • No data persistence (ephemeral sessions)
  • Rate limiting ready for production
  • Environment-based configuration

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

MIT License - feel free to use this project for personal or commercial purposes.

Contributors

Abdelhakk1

Issues