Skip to content

21aansh06/chatify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Chatify – Real Time Scalable Chat Application

Chatify is a production-ready real-time chat application built using the MERN stack. It features instant messaging, reactions, OTP-based authentication, rate limiting, and a scalable architecture powered by Redis and Socket.IO.


πŸš€ Features

πŸ” Authentication

  • OTP via Phone: Integrated with Twilio.
  • OTP via Email: Integrated with SendGrid.
  • Secure auth via header: Implemented using JWT (JSON Web Tokens).

πŸ’¬ Messaging

  • Real-Time: 1-to-1 chat using Socket.IO.
  • Reactions: Full emoji support for messages.
  • Presence: Online/Offline status.
  • Anti-Spam: Redis-based message rate limiting.

⚑ Performance & Security

  • Optimized Queries: MongoDB indexing for fast data retrieval.
  • Scalability: Logic designed for scalable socket management. Implemented Cursor-based pagination.
  • Security: Secure environment variable handling and middleware protection.

πŸ“œ Cursor-Based Pagination

  • Efficient message loading using cursor-based pagination.
  • Loads messages in chunks instead of fetching entire chat history.
  • Uses MongoDB _id as a cursor for consistent ordering.

How it works:

  • Messages are fetched in reverse chronological order.
  • Each request returns:
    • messages
    • nextCursor
    • hasMore
  • Older messages are loaded when the user scrolls up.

Benefits:

  • Faster initial load
  • Reduced database load
  • Scales well for long conversations

πŸ–Ό Media Support

  • File Handling: Image and file uploads via Multer.

πŸ›  Tech Stack

Layer Technologies
Frontend React.js, Zustand, Tailwind CSS, Socket.IO Client, Yup
Backend Node.js, Express.js, Socket.IO, Redis, JWT, Cloudinary (Media Storage)
Database MongoDB + Mongoose
Services Twilio (Phone), SendGrid (Email), Upstash (Cloud Redis)

🚦 Rate Limiting Strategy

Chatify uses a two-layer Redis-based rate limiting system to prevent spam while keeping the chat experience smooth.

1️⃣ Per User Rate Limit (Global)

Limits how frequently a user can send messages overall.

  • Purpose: Prevents abuse, bot behavior, and accidental message floods
  • Key: msg:{senderID}
  • Example: Max 30 messages in 60 seconds per user

2️⃣ Per User Per Conversation Rate Limit

Applies stricter limits within a single conversation.

  • Purpose: Stops spamming in individual chats without blocking the user globally
  • Key: msg:{senderId}:{conversationId}
  • Example: Max 15 messages in 10 seconds per user per conversation

βš™οΈ Implementation

  • Built using Redis INCR + EXPIRE
  • Executed before message persistence
  • Avoids unnecessary MongoDB writes and file uploads

βœ… Benefits

  • Fine-grained abuse control
  • High performance (in-memory operations)
  • Scales efficiently for real-time messaging

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

Aansh Malhotra (Full Stack Developer)


πŸ“ Final Note

Thank you for checking out Chatify! This project was built to demonstrate the power of real-time communication using the MERN stack and Redis.

If you have any questions or just want to connect, feel free to reach out.

Don't forget to give this project a ⭐ if you found it useful!

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages