A full-stack real-time chat and video calling application built with React, TypeScript, Node.js, Express, Socket.io, and MongoDB. This application enables users to create workspaces, channels, and communicate in real-time with rich text messaging capabilities.
- User Authentication: Secure signup and signin with JWT-based authentication
- Email Verification: Optional email verification system for new users
- Workspace Management: Create and manage multiple workspaces
- Channel System: Create channels within workspaces for organized communication
- Real-time Messaging: Instant messaging using Socket.io for real-time updates
- Rich Text Editor: Quill-based rich text editor with formatting options
- Image Upload: Support for image attachments via Cloudinary integration
- Member Management: Add members to workspaces with role-based access (admin/member)
- Join Codes: Workspace join codes for easy member invitation
- Real-time Video Calling: High-quality peer-to-peer video conferencing within workspaces
- Real-time Updates: Live message delivery and channel updates
- Queue System: Bull/BullMQ for background job processing (email notifications)
- Redis Integration: Redis for queue management and caching
- RESTful API: Well-structured REST API endpoints
- WebSocket Support: Socket.io for bidirectional real-time communication
- Responsive Design: Modern UI built with Tailwind CSS and Radix UI components
- Type Safety: Full TypeScript implementation across frontend and backend
- WebRTC Integration: Seamless video and audio communication using PeerJS
- React 19 - UI library
- TypeScript - Type safety
- Vite - Build tool and dev server
- React Router - Client-side routing
- Socket.io Client - Real-time communication
- React Query (TanStack Query) - Server state management
- Quill Editor - Rich text editing
- Tailwind CSS - Styling
- Radix UI - Accessible component primitives
- Axios - HTTP client
- Zod - Schema validation
- PeerJS - WebRTC peer-to-peer communication
- Node.js - Runtime environment
- Express 5 - Web framework
- TypeScript - Type safety
- MongoDB - Database (via Mongoose)
- Socket.io - WebSocket server
- JWT - Authentication
- Bcrypt - Password hashing
- Bull/BullMQ - Job queue management
- Redis - Queue backend and caching
- Nodemailer - Email service
- Zod - Schema validation
- ExpressPeerServer - PeerJS server for WebRTC signaling
- MongoDB - Primary database
- Redis - Queue backend
- Cloudinary - Image hosting (frontend integration)
chat-application/
βββ backend/ # Backend server
β βββ src/
β β βββ auth/ # JWT authentication utilities
β β βββ config/ # Configuration files (DB, Redis, Mail, Server)
β β βββ controllers/ # Request handlers (REST + Socket)
β β βββ middlewares/ # Express middlewares (auth, validation)
β β βββ processors/ # Queue job processors
β β βββ producers/ # Queue job producers
β β βββ queues/ # Queue definitions
β β βββ repository/ # Data access layer
β β βββ routes/ # API route definitions
β β βββ schema/ # Mongoose schemas
β β βββ services/ # Business logic layer
β β βββ types/ # TypeScript type definitions
β β βββ utils/ # Utility functions
β β βββ index.ts # Application entry point
β βββ package.json
β βββ tsconfig.json
β
βββ frontend/ # Frontend React application
β βββ src/
β β βββ apis/ # API client functions
β β βββ atoms/ # Atomic components
β β βββ components/ # Reusable UI components
β β βββ config/ # Configuration files
β β βββ context/ # React context providers
β β βββ hooks/ # Custom React hooks
β β βββ lib/ # Utility libraries
β β βββ molecules/ # Composite components
β β βββ organisms/ # Complex components
β β βββ pages/ # Page components
β β βββ utils/ # Utility functions
β β βββ App.tsx # Root component
β β βββ Routes.tsx # Route definitions
β β βββ main.tsx # Application entry point
β βββ package.json
β βββ vite.config.ts
β
βββ common/ # Shared package
βββ src/
β βββ index.ts # Shared types and schemas
βββ package.json
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- npm or pnpm (package manager)
- MongoDB (local or cloud instance)
- Redis (for queue management)
-
Clone the repository
git clone <repository-url> cd chat-application
-
Install dependencies for each package
Backend:
cd backend npm install # or pnpm install
Frontend:
cd frontend npm install # or pnpm install
Common (if needed):
cd common npm install # or pnpm install
Create a .env file in the backend/ directory:
# Server Configuration
PORT=3000
NODE_ENV=development
# Database
DEV_DB_URL=mongodb://localhost:27017/chat-app
PROD_DB_URL=mongodb://your-production-mongodb-url
# JWT
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
JWT_EXPIRY=1d
# Application URL
APP_URL=http://localhost:3000
# Email Configuration (Optional)
ENABLE_EMAIL_VERIFICATION=false
MAIL_ID=your-email@gmail.com
MAIL_PASSWORD=your-app-password
# Redis Configuration
REDIS_URL=redis://localhost:6379
REDIS_PORT=6379Create a .env file in the frontend/ directory:
VITE_API_URL=http://localhost:3000/api
VITE_SOCKET_URL=http://localhost:3000
VITE_CLOUDINARY_CLOUD_NAME=your-cloudinary-cloud-name
VITE_CLOUDINARY_UPLOAD_PRESET=your-upload-preset
# PeerJS Configuration
VITE_PEERJS_HOST=localhost
VITE_PEERJS_PORT=3000
VITE_PEERJS_PATH=/peerjs-
Start MongoDB (if running locally)
mongod
-
Start Redis (if running locally)
redis-server
-
Start the Backend Server
cd backend npm run dev # or pnpm dev
The backend will start on
http://localhost:3000 -
Start the Frontend Development Server
cd frontend npm run dev # or pnpm dev
The frontend will start on
http://localhost:5173(or the next available port)
Backend:
cd backend
npm run start
# or
pnpm startFrontend:
cd frontend
npm run build
# or
pnpm buildThe production build will be in frontend/dist/
POST /api/v1/user/signup- Register a new userPOST /api/v1/user/signin- Sign in existing user
GET /api/v1/workspace- Get all workspaces for authenticated userPOST /api/v1/workspace- Create a new workspaceGET /api/v1/workspace/:id- Get workspace detailsPUT /api/v1/workspace/:id- Update workspaceDELETE /api/v1/workspace/:id- Delete workspacePOST /api/v1/workspace/:id/join- Join workspace with join codeGET /api/v1/workspace/:id/members- Get workspace members
GET /api/v1/channel/workspace/:workspaceId- Get all channels in workspacePOST /api/v1/channel- Create a new channelGET /api/v1/channel/:id- Get channel detailsPUT /api/v1/channel/:id- Update channelDELETE /api/v1/channel/:id- Delete channel
GET /api/v1/messages/channel/:channelId- Get messages in a channelPOST /api/v1/messages- Create a new message (REST fallback)
GET /api/v1/member/workspace/:workspaceId- Get workspace membersPOST /api/v1/member/workspace/:workspaceId- Add member to workspaceDELETE /api/v1/member/:memberId- Remove member from workspace
GET /health- Server health check
GET /verify/:token- Verify user email
GET /ui- Bull queue dashboard (for monitoring jobs)
newMessage- Send a new message{ messageBody: string, image?: string, channelId: string, workspaceId: string, senderId: string }
joinChannel- Join a channel roomleaveChannel- Leave a channel roomcreateChannel- Create a new channelupdateChannel- Update channel detailsdeleteChannel- Delete a channelcreate-room- Initialize a video call roomjoined-room- Join an existing video call roomready- Signal that the peer is ready for connections
messageReceived- New message broadcastchannelCreated- Channel creation notificationchannelUpdated- Channel update notificationchannelDeleted- Channel deletion notificationuser-joined- Notification when a new peer joins the video calluser-left- Notification when a peer leaves the video callroom-created- Confirmation of video room creation
- MVC Pattern: Controllers handle requests, Services contain business logic, Repositories handle data access
- Queue System: Bull/BullMQ for asynchronous job processing (emails)
- Socket Handlers: Separate controllers for Socket.io event handling
- Middleware Chain: Authentication and validation middlewares
- Schema Validation: Zod schemas for request validation
- Component Hierarchy: Atomic Design (atoms β molecules β organisms)
- State Management: React Context + React Query for server state
- Real-time Updates: Socket.io client integration
- Routing: React Router with protected routes
- API Layer: Axios-based API client with interceptors
The application uses JWT (JSON Web Tokens) for authentication:
- User signs up/signs in
- Server generates JWT token
- Token is stored in localStorage (frontend)
- Token is sent in
Authorizationheader for protected routes - Middleware validates token on each request
email(unique, required)username(unique, required)password(hashed)avatar(auto-generated)isVerified(boolean)verificationToken(string)verificationTokenExpiry(number)
name(unique, required)description(string)members(array of { memberId, role })joinCode(required)channels(array of channel IDs)
name(required)workspaceId(reference to Workspace)createdAt,updatedAt(timestamps)
messageBody(required)image(optional)channelId(reference to Channel)workspaceId(reference to Workspace)senderId(reference to User)createdAt,updatedAt(timestamps)
# Backend
cd backend
npm run format
# Frontend
cd frontend
npm run format# Backend
cd backend
npm run lint
npm run lint:fix
# Frontend
cd frontend
npm run lint- Set
NODE_ENV=production - Update
PROD_DB_URLwith production MongoDB URL - Set secure
JWT_SECRET - Configure Redis URL for production
- Deploy to your preferred hosting (Heroku, AWS, DigitalOcean, etc.)
- Update environment variables for production API URLs
- Run
npm run build - Deploy
dist/folder to static hosting (Vercel, Netlify, etc.)
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License.
- Mustafa Mubashir
Note: Make sure to update environment variables and secrets before deploying to production. Never commit .env files to version control.