Skip to content

Anubha0308/fullstack-chat-app

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

394 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation


Render Node.js React Socket.io MongoDB MIT License

Stars Forks Issues


A blazing-fast, WhatsApp-inspired real-time chat app β€” Web Push Notifications, Voice Notes, Socket.io events, emoji reactions, reply threads, image sharing, and 32 switchable themes. Zero polling. Pure vibes.


πŸš€ Live Demo Β Β·Β  πŸ› Report Bug Β Β·Β  ✨ Request Feature



πŸ“Έ Preview

Chat Interface Demo


✨ Features

πŸ’¬ Messaging

  • πŸ”΄πŸŸ’ Real-time presence β€” see who's online the instant they log in

  • ⚑ Instant messaging β€” delivered in milliseconds via Socket.io, zero polling

  • 🎀 Voice Notes β€” record and send native audio messages directly in the chat

  • πŸ”” Web Push Notifications β€” get native OS alerts via Service Workers even when offline

  • ↩️ Reply threads β€” reply with a quoted preview embedded in the bubble

  • πŸ—‘οΈ Live deletion β€” deleted messages vanish from both sides instantly

  • 😊 Emoji picker β€” 6 categorized tabs (Smileys, Gestures, Hearts, Activities, Food, Nature) with cursor-aware insertion

🎨 Experience

  • πŸ–±οΈ WhatsApp-style context menu β€” right-click for reactions, reply, copy, delete

  • πŸ–ΌοΈ Image attachments β€” Cloudinary upload with client-side preview before sending

  • πŸ“± Fully mobile responsive β€” single-panel on phone, dual-panel on desktop

  • πŸ” New Chat search β€” find any registered user by name

  • 🎨 32 switchable themes β€” DaisyUI grid, persisted across sessions

  • πŸ” JWT & Google OAuth β€” HTTP-only cookies, secure password hashing, and Google sign-in

  • πŸ›‘οΈ Security Hardening β€” Helmet headers, auth endpoint rate-limiting, and server-side input validation


πŸ›  Tech Stack

Frontend

Tool Version Purpose
React 19 UI framework
Vite 8 Build tool & dev server
TailwindCSS v4 Utility-first styling
DaisyUI v5 Component library + 32 themes
Zustand latest Lightweight global state
Socket.io 4.x Real-time event handling
React Router v7 Client-side routing
Axios latest HTTP client with interceptors

Backend

Tool Version Purpose
Node.js v24 Runtime
Express 5 HTTP server + API routing
Socket.io 4.x WebSocket server
Mongoose latest MongoDB ODM
JWT latest Session tokens
Google OAuth latest google-auth-library
Helmet latest Security headers middleware
Rate Limit latest brute-force prevention
Cloudinary latest Image storage & CDN

Infrastructure

Service Role
MongoDB Atlas Cloud database
Cloudinary Media CDN
Render Full-stack deployment

πŸ“¦ Installation

Prerequisites

Before you begin, make sure you have:

βœ… Node.js >= 18
βœ… A MongoDB Atlas account  (free tier works great)
βœ… A Cloudinary account     (free tier works great)

1. Clone the repository

git clone https://github.com/UTKARSHH20/fullstack-chat-app.git
cd fullstack-chat-app

2. Install dependencies

# Backend
npm install --prefix backend

# Frontend
npm install --prefix frontend

βš™οΈ Environment Variables

Create a .env file inside the backend/ directory:

# ── Database ──────────────────────────────────────────
MONGODB_URL=your_mongodb_atlas_connection_string

# ── Server ────────────────────────────────────────────
PORT=5001
NODE_ENV=development

# ── Auth ──────────────────────────────────────────────
JWT_SECRETKEY=your_super_secret_key
GOOGLE_CLIENT_ID=your_google_client_id

# ── Cloudinary ────────────────────────────────────────
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret

# ── Web Push Notifications ────────────────────────────
VAPID_PUBLIC_KEY=your_vapid_public_key
VAPID_PRIVATE_KEY=your_vapid_private_key
VAPID_SUBJECT=mailto:test@example.com

Create a .env file inside the frontend/ directory:

VITE_VAPID_PUBLIC_KEY=your_vapid_public_key
VITE_GOOGLE_CLIENT_ID=your_google_client_id

⚠️ Never commit .env to version control. It is already listed in .gitignore.


▢️ Running the Project

Development

Open two terminals and run:

# Terminal 1 β€” Backend (http://localhost:5001)
cd backend && npm run dev

# Terminal 2 β€” Frontend (http://localhost:5173)
cd frontend && npm run dev

Then visit http://localhost:5173 πŸŽ‰

Production Build

# From the project root
npm run build   # installs deps + builds the React app
npm start       # starts Express, which serves the built frontend

🌐 Deployment

This app deploys as a single service on Render β€” the Express backend serves the compiled React frontend in production. No separate static hosting needed.

πŸ“‹ Render Configuration (click to expand)
Setting Value
Build Command npm install --prefix backend && npm install --prefix frontend && npm run build --prefix frontend
Start Command npm run start --prefix backend
Node Version 24
Environment Variables (set all variables from the .env section above)

The backend uses express.static to serve frontend/dist and a catch-all app.use() handler for SPA routing. Note: app.get("*") is intentionally avoided due to an Express 5 + path-to-regexp v8 incompatibility.


πŸ“ Folder Structure

fullstack-chat-app/
β”‚
β”œβ”€β”€ πŸ“‚ backend/
β”‚   └── src/
β”‚       β”œβ”€β”€ controllers/
β”‚       β”‚   β”œβ”€β”€ auth.controller.js
β”‚       β”‚   └── message.controller.js
β”‚       β”œβ”€β”€ lib/
β”‚       β”‚   β”œβ”€β”€ cloudinary.js
β”‚       β”‚   β”œβ”€β”€ db.js
β”‚       β”‚   β”œβ”€β”€ socket.js
β”‚       β”‚   β”œβ”€β”€ webpush.js
β”‚       β”‚   └── utils.js
β”‚       β”œβ”€β”€ middleware/
β”‚       β”‚   └── auth.middleware.js
β”‚       β”œβ”€β”€ models/
β”‚       β”‚   β”œβ”€β”€ message.model.js
β”‚       β”‚   └── user.model.js
β”‚       β”œβ”€β”€ routes/
β”‚       β”‚   β”œβ”€β”€ auth.route.js
β”‚       β”‚   └── message.route.js
β”‚       └── index.js
β”‚
β”œβ”€β”€ πŸ“‚ frontend/
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── service-worker.js
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   └── Navbar.jsx
β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”œβ”€β”€ axios.js
β”‚   β”‚   └── socket.js
β”‚   β”œβ”€β”€ pages/
β”‚   β”‚   β”œβ”€β”€ ChatPage.jsx
β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx
β”‚   β”‚   β”œβ”€β”€ ProfilePage.jsx
β”‚   β”‚   β”œβ”€β”€ SettingsPage.jsx
β”‚   β”‚   └── SignUpPage.jsx
β”‚   └── src/
β”‚       β”œβ”€β”€ store/
β”‚       β”‚   β”œβ”€β”€ useAuthStore.js
β”‚       β”‚   β”œβ”€β”€ useChatStore.js
β”‚       β”‚   └── useThemeStore.js
β”‚       β”œβ”€β”€ App.jsx
β”‚       └── main.jsx
β”‚
β”œβ”€β”€ .gitignore
└── package.json

πŸ” Authentication & Security Flow

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     hash pw      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    JWT cookie    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Local Auth  β”‚ ───────────────► β”‚   bcryptjs   β”‚ ───────────────► β”‚  HTTP-only     β”‚
β”‚  (User/Pass) β”‚                  β”‚  (10 rounds) β”‚                  β”‚  Secure Cookie β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                            β–²
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     ID Token     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                          β”‚
β”‚ Google OAuth β”‚ ───────────────► β”‚ google-auth  β”‚ β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚  (One-tap)   β”‚                  β”‚  validator   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  1. Local Authentication: User signs up β†’ password hashed with bcryptjs (10 salt rounds). On login, a JWT is signed with 15-day expiry and set as an HTTP-only, secure, SameSite=Strict cookie.
  2. Google OAuth: User logs in/signs up via Google Identity Services β†’ ID token verified server-side via google-auth-library β†’ user account created/resolved β†’ JWT cookie issued.
  3. Session Persistence: On page refresh, checkAuth() re-validates the session cookie and reconnects the WebSockets.
  4. Security Middleware: All authentication endpoints are rate-limited (max 20 requests per 15 minutes), and express inputs are validated using custom middleware. All response headers are secured via Helmet.

🧠 Key Engineering Highlights

⚑ Real-time Architecture

Express and Socket.io share a single HTTP server instance. A userId β†’ socketId map held in memory enables direct message routing to specific clients β€” no broadcasting to everyone, no unnecessary noise.

πŸ”” Web Push Integration

A robust implementation of the Web Push API using Service Workers and VAPID keys. If the recipient is offline (no active Socket connection), the backend automatically triggers a native OS-level push notification to alert them.

↩️ Reply Threading

Replied messages store a replyTo snapshot (sender name + message text) directly on the message document. The thread context is always preserved even if the original message is later deleted β€” no orphaned threads.

πŸ”§ Express 5 Wildcard Fix

path-to-regexp v8 (used internally by Express 5) rejects bare "*" route patterns at startup. The SPA catch-all fallback uses app.use() instead, which bypasses the regex engine entirely and works perfectly.

πŸ” Sidebar Privacy Design

Instead of listing all registered users (which would expose your entire user base), the sidebar only shows people you've already messaged. A dedicated GET /api/messages/search?q= endpoint powers the "New Chat" modal for discovering new people.

πŸ“± Mobile Layout

No framework tricks needed β€” a simple hidden md:flex toggle on the sidebar and chat panel gives a native-feeling single-panel experience on mobile, with proper back navigation on small screens.


🀝 Contributors



  • Pratikshya32 β€” Frontend Developer 🎨
  • Utkarsh β€” Backend Developer βš™οΈ

Want to contribute?

# Fork the repo, then:
git checkout -b feature/your-feature-name
git commit -m "feat: describe your change"
git push origin feature/your-feature-name
# Open a Pull Request βœ…

Please keep PRs focused β€” avoid mixing unrelated changes in a single PR.


πŸ“œ License

Distributed under the MIT License. See LICENSE for more information.



Built with β˜• and way too many Stack Overflow tabs


⭐ If this project helped you, consider dropping a star β€” it genuinely means a lot! ⭐

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 99.1%
  • Other 0.9%