Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ ChatSphere

Encrypted. Private. Real-time.

A full-stack real-time chat application with end-to-end encryption, voice/video calls, group chats, social features, and more β€” built with the MERN stack and Socket.IO.

🌐 Live: chatsphere-omega.vercel.app


πŸ“Έ Features

πŸ’¬ Messaging

  • Real-time 1-on-1 and group messaging via Socket.IO
  • End-to-End Encryption (E2E) β€” all messages encrypted with AES using CryptoJS
  • Voice messages (hold-to-record)
  • Image & file sharing
  • Message unsend (for everyone)
  • Message seen/delivered receipts (βœ“βœ“)
  • Typing indicators β€” shows who is typing in real time
  • WhatsApp-style clear chat (only clears for you)

πŸ‘₯ Groups

  • Create groups with custom name and photo
  • Group admin controls β€” add/remove members
  • Group E2E encryption
  • Real-time typing indicators in groups
  • Group voice & video calls

πŸ“ž Calls

  • 1-on-1 voice calls (WebRTC)
  • 1-on-1 video calls (WebRTC)
  • Group calls
  • Incoming call banner with accept/reject

πŸ” Auth & Security

  • Register with email OTP verification (Resend)
  • Login with email or @username
  • JWT authentication (7-day tokens)
  • Forgot password / reset via OTP
  • Password hashing with bcryptjs (12 rounds)
  • Rate limiting on messages and search

🌐 Social (Instagram-style)

  • Ping = Follow / Send follow request
  • Unping = Unfollow
  • Private accounts β€” require approval before following
  • Accept / Decline follow requests
  • Block / Unblock users
  • Posts visible only to followers
  • Notifications for pings, requests, and messages

πŸ‘€ Profile

  • Avatar upload
  • Bio (150 chars)
  • Edit name, username
  • View other user profiles

πŸ› οΈ Tech Stack

Layer Technology
Frontend React 19, Vite, Socket.IO Client
Backend Node.js, Express.js
Database MongoDB Atlas + Mongoose
Real-time Socket.IO
Auth JWT + bcryptjs
Encryption CryptoJS (AES E2E)
Email Resend
File uploads Multer
Calls WebRTC
Deployment Vercel (frontend) + Render (backend)

⚑ DSA & Performance

ChatSphere uses real Data Structures & Algorithms for maximum performance:

DSA Usage
HashMap O(1) userId β†’ socketId online map, socket reverse lookup, DM dedup
LRU Cache Message caching β€” invalidated on send/unsend/clear
Trie User search β€” O(log n) prefix search, rebuilt on server start
FIFO Queue Offline message delivery β€” flushed on reconnect
Token Bucket Rate limiting β€” messages and search per user
Debounce HashMap Typing indicators β€” 800ms debounce per user pair
Multi-tab Set Each user has a Set<socketId> β€” supports multiple browser tabs

πŸ“ Project Structure

chat-app/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── db.js               # MongoDB connection
β”‚   β”œβ”€β”€ dsa/
β”‚   β”‚   β”œβ”€β”€ LRUCache.js         # Message cache
β”‚   β”‚   β”œβ”€β”€ MessageQueue.js     # Offline message queue
β”‚   β”‚   β”œβ”€β”€ RateLimiter.js      # Token bucket rate limiter
β”‚   β”‚   └── TrieSearch.js       # User search trie
β”‚   β”œβ”€β”€ middleware/
β”‚   β”‚   └── authMiddleware.js   # JWT verification
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”œβ”€β”€ Chat.js
β”‚   β”‚   β”œβ”€β”€ ConnectionRequest.js
β”‚   β”‚   β”œβ”€β”€ Group.js
β”‚   β”‚   β”œβ”€β”€ Message.js
β”‚   β”‚   β”œβ”€β”€ Post.js
β”‚   β”‚   └── User.js
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   β”œβ”€β”€ admin.js
β”‚   β”‚   β”œβ”€β”€ auth.js             # Register, login, OTP, reset
β”‚   β”‚   β”œβ”€β”€ chat.js             # DMs, clear chat, file upload
β”‚   β”‚   β”œβ”€β”€ connections.js
β”‚   β”‚   β”œβ”€β”€ group.js            # Groups, members, avatar
β”‚   β”‚   β”œβ”€β”€ posts.js
β”‚   β”‚   β”œβ”€β”€ profile.js
β”‚   β”‚   └── user.js             # Ping, unping, block, follow
β”‚   β”œβ”€β”€ utils/
β”‚   β”‚   └── encryption.js       # AES encrypt/decrypt helpers
β”‚   └── server.js               # Express + Socket.IO server
β”‚
└── frontend/
    β”œβ”€β”€ public/
    └── src/
        β”œβ”€β”€ components/
        β”‚   β”œβ”€β”€ AdminPanel.jsx
        β”‚   β”œβ”€β”€ Call.jsx
        β”‚   β”œβ”€β”€ ChatList.jsx     # Sidebar β€” DMs, groups, users
        β”‚   β”œβ”€β”€ ChatWindow.jsx   # Message view, voice, calls
        β”‚   β”œβ”€β”€ Feed.jsx         # Posts feed
        β”‚   β”œβ”€β”€ Login.jsx
        β”‚   β”œβ”€β”€ Notifications.jsx
        β”‚   β”œβ”€β”€ Profile.jsx
        β”‚   β”œβ”€β”€ Register.jsx
        β”‚   β”œβ”€β”€ UserProfile.jsx
        β”‚   └── VideoCall.jsx
        β”œβ”€β”€ services/
        β”‚   └── api.js           # Axios instance
        β”œβ”€β”€ App.jsx
        β”œβ”€β”€ crypto.js            # CryptoJS E2E helpers
        β”œβ”€β”€ main.jsx
        β”œβ”€β”€ socket.js            # Socket.IO client
        └── style.css

πŸš€ Local Development

Prerequisites

  • Node.js 18+
  • MongoDB (local or Atlas)

1. Clone the repo

git clone https://github.com/Sainikhil070304/chatsphere.git
cd chatsphere

2. Backend setup

cd backend
npm install

Create backend/.env

Start backend:

node server.js

3. Frontend setup

cd frontend
npm install

Create frontend/.env

Start frontend:

npm run dev

Open http://localhost:


☁️ Deployment

Backend β†’ Render

  1. Connect GitHub repo to Render
  2. Set Root Directory to backend
  3. Set Start Command to node server.js
  4. Add environment variables:
    • MONGO_URI
    • JWT_SECRET
    • CHAT_SECRET
    • RESEND_API_KEY
    • NODE_ENV=production

Frontend β†’ Vercel

  1. Connect GitHub repo to Vercel
  2. Set Root Directory to frontend
  3. Add environment variables

πŸ”’ Encryption

All messages are encrypted before being sent to the server:

Sender β†’ AES encrypt(message, CHAT_SECRET) β†’ Server β†’ Receiver β†’ AES decrypt
  • Server never sees plaintext messages
  • Group messages use the same shared secret
  • Audio/image messages are stored encrypted

πŸ“‘ Socket Events

Event Direction Description
online client→server User comes online
send client→server Send a message
receive server→client Receive a message
typing client→server User is typing
stopTyping client→server User stopped typing
seen client→server Message seen
unsend client→server Unsend a message
call:offer client→server Initiate a call
call:incoming server→client Notify callee
call:answer client→server Accept call
call:end client→server End call

πŸ—ΊοΈ Roadmap

  • Real-time messaging with E2E encryption
  • Group chats with admin controls
  • Voice & video calls (WebRTC)
  • Voice messages
  • OTP email verification
  • Social features (ping/unping/block/follow)
  • Group photo upload
  • Typing indicators
  • Message seen/delivered
  • Clear chat
  • Deploy to Vercel + Render
  • Push notifications
  • Message reactions
  • Stories
  • Admin dashboard

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

Sai Nikhil Nallela


About

ChatSphere is a real-time messaging application built with React, Node.js, Socket.IO, and MongoDB, supporting encrypted chats, groups, file sharing, and live presence.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages