Skip to content

AMANkumar0004/ChatApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

55 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ChatApp

A production-grade real-time chat application built with the MERN stack and Socket.io, featuring a custom 5-layer Redis architecture for scale, security, and performance.

🔗 Live Demo: https://chat-app-psi-teal.vercel.app/ 📦 Repo: github.com/AMANkumar0004


Overview

ChatApp is a full-stack real-time messaging platform designed to go beyond a typical CRUD chat app. It implements production-style patterns for rate limiting, session control, caching, and push notifications — all backed by a self-designed Redis layer.


Tech Stack

Layer Tech
Frontend React, Socket.io-client
Backend Node.js, Express
Real-time Socket.io
Database MongoDB
Cache / Infra Redis (Upstash)
Hosting Vercel (frontend), Render (backend), Upstash (Redis)
Notifications Web Push (VAPID)

🧠 The 5-Layer Redis Architecture

This is the core differentiator of the project — Redis isn't just used for caching, it powers five distinct subsystems:

  1. Sliding Window Rate Limiting Protects API and socket endpoints from abuse using a sliding window counter implemented with Redis INCR / EXPIRE.

  2. Single-Device Session Control Each user's active JWT session is tracked in Redis (activeSession:userId), so logging in on a new device invalidates the old session and emits a session_kicked event over the socket connection.

  3. Bloom Filters for Signup Availability Username/email availability checks are pre-filtered with a Redis-backed Bloom Filter before hitting MongoDB, cutting down unnecessary DB reads during signup.

  4. Message Caching Recent conversation history is cached in Redis to reduce read load on MongoDB and speed up chat load times.

  5. Web Push Notifications (VAPID) Offline users receive push notifications via the Web Push protocol, with subscription data managed through Redis.


Features

  • 🔐 JWT-based authentication with single active session per user
  • 💬 Real-time 1:1 messaging via Socket.io
  • 🟢 Online/offline presence tracking (Redis Hashes)
  • 🚦 API rate limiting to prevent abuse
  • 🔔 Push notifications for offline users
  • ⚡ Cached message history for fast chat loading
  • 🧩 Bloom filter–backed signup validation

Architecture

Client (React)
   │
   ├── REST API ──────► Express Server ──────► MongoDB (persistent data)
   │                          │
   │                          └────► Redis (Upstash)
   │                                   ├── Rate limiting
   │                                   ├── Session store
   │                                   ├── Bloom filter
   │                                   ├── Message cache
   │                                   └── Push subscriptions
   │
   └── WebSocket ─────► Socket.io Server ──► Presence + real-time events

Getting Started

Prerequisites

  • Node.js (v18+)
  • MongoDB instance (local or Atlas)
  • Redis instance (Upstash recommended)
  • VAPID keys for Web Push

Installation

# Clone the repo
git clone https://github.com/AMANkumar0004/chatapp.git
cd chatapp

# Install dependencies
cd server && npm install
cd ../client && npm install

Environment Variables

Create a .env file in /server:

PORT=5000
MONGO_URI=your_mongodb_uri
JWT_SECRET=your_jwt_secret
REDIS_URL=your_upstash_redis_url
VAPID_PUBLIC_KEY=your_vapid_public_key
VAPID_PRIVATE_KEY=your_vapid_private_key
CLIENT_URL=http://localhost:3000

Run Locally

# Start backend
cd server && npm run dev

# Start frontend
cd client && npm start

Deployment

Service Platform
Frontend Vercel
Backend Render
Redis Upstash
Database MongoDB Atlas

Roadmap

  • Group chat support
  • Message read receipts
  • End-to-end encryption
  • Typing indicators

Author

Aman Kumar GitHub: @AMANkumar0004 LinkedIn: aman-kumar-ak004


License

MIT

About

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors