Skip to content

Real-time video chat application built with React, Go, and WebRTC. Features multi-user meetings, live chat, JWT authentication, and peer-to-peer video/audio streaming with WebSocket signaling.

Notifications You must be signed in to change notification settings

rishishanbhag/PolyChat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

29 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ₯ PolyChat

A real-time video chat application built with React, Go, and WebRTC technology. PolyChat enables users to create and join video meetings with multiple participants, featuring peer-to-peer video/audio streaming, real-time chat, and seamless WebSocket signaling.

✨ Features

  • πŸŽ₯ Real-time Video & Audio - WebRTC-based peer-to-peer communication
  • πŸ‘₯ Multi-user Meetings - Support for multiple participants in a single room
  • πŸ’¬ Live Chat - Text messaging during video calls
  • πŸ”— Shareable Meeting Links - UUID-based meeting rooms
  • πŸ” Secure Authentication - JWT-based user authentication with bcrypt password hashing
  • 🌐 WebSocket Signaling - Real-time signaling for WebRTC connections
  • πŸ“± Responsive Design - Built with Tailwind CSS and Radix UI components
  • 🎬 Graceful Fallbacks - Automatic fallback when camera/microphone unavailable
  • πŸ”„ Auto-reconnection - WebSocket reconnection on connection loss

πŸ—οΈ Architecture

Tech Stack

Frontend:

  • βš›οΈ React 19 with Vite
  • 🎨 Tailwind CSS 4 for styling
  • 🧩 Radix UI components
  • πŸ”„ Zustand for state management
  • 🌐 WebRTC for video/audio streaming
  • πŸ”Œ WebSocket client for signaling

Backend:

  • 🐹 Go 1.25 with Chi router
  • πŸ—„οΈ MongoDB Atlas for data persistence
  • πŸ” JWT authentication (golang-jwt/jwt)
  • πŸ”’ Bcrypt password hashing
  • 🌐 Gorilla WebSocket for signaling server
  • πŸ†” UUID for unique meeting identifiers

System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                 β”‚         β”‚                  β”‚
β”‚  React Client   │◄───────►│   Go Server      β”‚
β”‚  (Frontend)     β”‚  HTTP   β”‚   (Backend)      β”‚
β”‚                 β”‚  REST   β”‚                  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                           β”‚
         β”‚ WebSocket                 β”‚
         β”‚ Signaling                 β”‚ MongoDB
         β”‚                           β”‚ Atlas
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                     β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
              β”‚   WebRTC    β”‚
              β”‚ P2P Streams β”‚
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Getting Started

Prerequisites

  • Node.js 18+ and npm
  • Go 1.21+
  • MongoDB Atlas account (or local MongoDB)
  • OpenSSL (for generating secrets)

Installation

1. Clone the Repository

git clone https://github.com/rishishanbhag/PolyChat.git
cd PolyChat

2. Backend Setup

cd server

# Copy environment template
cp .env.example .env

# Edit .env and add your credentials:
# - MONGODB_URI: Your MongoDB connection string
# - JWT_SECRET: Generate with: openssl rand -base64 48
# - ALLOWED_ORIGINS: Frontend URLs (e.g., http://localhost:5173)

# Install dependencies
go mod download

# Run the server
go run cmd/api/main.go

# Or using Make
make run

Server will start on http://localhost:8080

3. Frontend Setup

cd client

# Copy environment template
cp .env.example .env

# Edit .env if needed (defaults work for local development):
# - VITE_API_URL=http://localhost:8080/api
# - VITE_WS_URL=ws://localhost:8080/api/ws

# Install dependencies
npm install

# Run development server
npm run dev

Client will start on http://localhost:5173

Environment Variables

Server (.env):

PORT=8080
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/
DATABASE_NAME=polychat
JWT_SECRET=<generate-with-openssl-rand-base64-48>
ALLOWED_ORIGINS=http://localhost:5173,http://localhost:3000

Client (.env):

VITE_API_URL=http://localhost:8080/api
VITE_WS_URL=ws://localhost:8080/api/ws

See SECURITY.md for detailed security guidelines.

πŸ“– Usage

  1. Sign Up / Login

    • Create an account or login with existing credentials
    • JWT token stored securely in localStorage
  2. Create a Meeting

    • Click "Create Meeting" from the dashboard
    • Share the generated meeting link with participants
  3. Join a Meeting

    • Click on a meeting from your list
    • Or use a shared meeting link
    • Grant camera/microphone permissions when prompted
  4. During the Meeting

    • See all participants' video streams
    • Use chat for text communication
    • Video/audio will automatically fall back if devices unavailable

πŸ”Œ API Endpoints

Authentication

  • POST /api/auth/signup - Register new user
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user

Meetings (Protected)

  • GET /api/meetings - List user's meetings
  • POST /api/meetings - Create new meeting
  • GET /api/meetings/:id - Get meeting details
  • GET /api/meetings/link/:linkId - Get meeting by shareable link
  • POST /api/meetings/:id/join - Join a meeting

WebSocket

  • WS /api/ws?userId=<id>&username=<name>&roomId=<room> - WebSocket signaling connection

πŸ› οΈ Development

Backend Structure

server/
β”œβ”€β”€ cmd/api/main.go           # Application entry point
β”œβ”€β”€ internal/
β”‚   β”œβ”€β”€ auth/                 # JWT utilities
β”‚   β”œβ”€β”€ database/             # MongoDB connection
β”‚   β”œβ”€β”€ handlers/             # HTTP request handlers
β”‚   β”œβ”€β”€ middleware/           # Auth middleware
β”‚   β”œβ”€β”€ models/               # Data models
β”‚   β”œβ”€β”€ repository/           # Database operations
β”‚   β”œβ”€β”€ server/               # Server setup & routes
β”‚   └── websocket/            # WebSocket hub & clients
β”œβ”€β”€ .env.example              # Environment template
└── go.mod                    # Go dependencies

Frontend Structure

client/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/           # React components
β”‚   β”‚   β”œβ”€β”€ ChatBox.jsx      # Chat component
β”‚   β”‚   └── ui/              # Reusable UI components
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ api.js           # HTTP API client
β”‚   β”‚   β”œβ”€β”€ websocket.js     # WebSocket client
β”‚   β”‚   └── webrtc.js        # WebRTC manager
β”‚   β”œβ”€β”€ pages/               # Page components
β”‚   β”‚   β”œβ”€β”€ DashboardPage.jsx
β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx
β”‚   β”‚   β”œβ”€β”€ SignupPage.jsx
β”‚   β”‚   └── MeetingRoomPage.jsx
β”‚   β”œβ”€β”€ store/
β”‚   β”‚   └── useStore.js      # Zustand state management
β”‚   β”œβ”€β”€ App.jsx              # Root component
β”‚   └── main.jsx             # Application entry
β”œβ”€β”€ .env.example             # Environment template
└── package.json             # Dependencies

Make Commands (Backend)

make build        # Build the application
make run          # Run the application
make test         # Run tests

πŸ”’ Security

  • βœ… JWT-based authentication with 24-hour token expiration
  • βœ… Bcrypt password hashing (no plaintext storage)
  • βœ… Environment-based configuration (no hardcoded secrets)
  • βœ… CORS protection with configurable origins
  • βœ… Password fields excluded from JSON responses
  • βœ… .env files properly gitignored

Important: Read SECURITY.md before deploying to production.

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License.

πŸ‘¨β€πŸ’» Author

Rishi Shanbhag


Built with ❀️ by Rishi

About

Real-time video chat application built with React, Go, and WebRTC. Features multi-user meetings, live chat, JWT authentication, and peer-to-peer video/audio streaming with WebSocket signaling.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published