- Project Overview
- Features
- Tech Stack
- Project Workflow
- Folder Structure
- Installation & Setup
- Running the Application
- API Endpoints
- Environment Variables
- Contributing
SnapTalk is a modern, real-time messaging application designed to provide seamless, secure, and interactive communication across devices. It allows users to connect with friends, family, or colleagues instantly, offering a blend of personal and professional messaging features.
The application features a robust full-stack architecture with a React-based frontend and Node.js/Express backend, enabling real-time bidirectional communication through WebSockets (Socket.io).
Live Demo: https://chat-app-controlcoder.vercel.app/
- Real-Time Messaging: Instant message delivery using WebSocket technology
- User Authentication: Secure JWT-based authentication with bcrypt password hashing
- User Profiles: View and manage user information with avatar support
- Friend Management: Add, remove, and manage connections
- Message History: Persistent message storage with MongoDB
- Typing Indicators: Real-time typing status notifications
- Online Status: Track user availability in real-time
- Media Support: Cloud-based image uploads using Cloudinary
- Responsive Design: Mobile-friendly UI with Tailwind CSS
- Toast Notifications: User-friendly feedback with React Hot Toast
- Secure Communication: CORS-enabled, JWT-protected endpoints
| Technology | Version | Purpose |
|---|---|---|
| React | 19.2.0 | UI Library |
| Vite | 7.3.1 | Build Tool & Dev Server |
| React Router DOM | 7.13.1 | Client-side Routing |
| Socket.io Client | 4.8.3 | Real-time Communication |
| Tailwind CSS | 4.2.1 | Utility-first CSS Framework |
| Axios | 1.13.6 | HTTP Client |
| React Hot Toast | 2.6.0 | Toast Notifications |
| ESLint | 9.39.1 | Code Quality |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | Latest | JavaScript Runtime |
| Express | 5.2.1 | Web Framework |
| Socket.io | 4.8.3 | Real-time Communication |
| MongoDB/Mongoose | 9.3.3 | Database & ODM |
| JWT | 9.0.3 | Authentication Token |
| Bcrypt | 6.0.0 | Password Hashing |
| CORS | 2.8.6 | Cross-Origin Resource Sharing |
| Dotenv | 17.3.1 | Environment Configuration |
| Cloudinary | 2.9.0 | Cloud Image Storage |
| Cookie Parser | 1.4.7 | Cookie Parsing |
| Technology | Purpose |
|---|---|
| Vercel | Frontend Hosting |
| Concurrently | Run multiple dev servers |
| Nodemon | Auto-restart server during development |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT (React + Vite) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Pages: Auth, Chat, Profile, Dashboard β β
β β Components: MessageBox, UserList, ChatWindow β β
β β Context API: User, Chat, Socket State Management β β
β β Routing: React Router (Login β Chat β Profile) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β (HTTP + WebSocket) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β Socket.io & REST API Communication Layer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β SERVER (Node.js + Express) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Routes: Auth, Chat, Users, Messages β β
β β Controllers: Logic for auth, messaging, user mgmt β β
β β Models: User, Message, Conversation (MongoDB) β β
β β Middleware: JWT Verify, CORS, Error Handling β β
β β Socket Events: message, typing, online status β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β (MongoDB Queries) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β DATABASE (MongoDB Atlas) β
β Collections: users, messages, conversations, tokens β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. AUTHENTICATION FLOW
ββββββββββββββ
β Login β β Credentials Sent to Backend
ββββββββββββββ
β
βββββββββββββββββββββββ
β Server Verification β β Bcrypt Password Check
βββββββββββββββββββββββ
β
ββββββββββββββββββ
β JWT Generated β β Token Stored in Cookies
ββββββββββββββββββ
β
ββββββββββββββββββββ
β User Redirected β β Dashboard/Chat View
ββββββββββββββββββββ
2. MESSAGE SENDING FLOW
ββββββββββββββββ
β User Types β
ββββββββββββββββ
β
ββββββββββββββββββββββββββββββ
β Client Emits Socket Event β β "message:send"
ββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββββββββ
β Server Receives Message β β Validates JWT
ββββββββββββββββββββββββββββββββ
β
ββββββββββββοΏ½οΏ½βββββββββββββββββββββ
β Saves to MongoDB β β Message Stored
ββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββ
β Broadcasts to Recipient β β Real-time Delivery
βββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββ
β Updates UI Dynamically β β Message Appears
βββββββββββββββββββββββββββββββββββ
3. REAL-TIME UPDATES
βββββββββββββββββββββββ
β Typing Indicator β β Socket Event Emission
βββββββββββββββββββββββ
ββββββββββββββββββββββββ
β Online Status Update β β Connection Events
ββββββββββββββββββββββββ
ββββββββββββββββββββββββ
β Message Seen Status β β Acknowledgment Events
ββββββββββββββββββββββββ
chat-app/
β
βββ client/ # Frontend Application (React + Vite)
β βββ public/ # Static assets
β βββ src/
β β βββ assets/ # Images, icons, media files
β β βββ components/ # Reusable React components
β β β βββ MessageBox.jsx # Message rendering component
β β β βββ UserList.jsx # User list display
β β β βββ ChatWindow.jsx # Main chat interface
β β β βββ Header.jsx # Navigation header
β β β βββ ... # Other UI components
β β βββ pages/ # Page-level components (Routes)
β β β βββ Login.jsx # Authentication page
β β β βββ Signup.jsx # Registration page
β β β βββ Chat.jsx # Main chat interface
β β β βββ Profile.jsx # User profile page
β β β βββ Dashboard.jsx # Dashboard/Home page
β β β βββ ... # Other page components
β β βββ context/ # Context API for state management
β β β βββ UserContext.jsx # User authentication state
β β β βββ ChatContext.jsx # Chat messages state
β β β βββ SocketContext.jsx # WebSocket connection state
β β β βββ ... # Other contexts
β β βββ config/ # Configuration files
β β β βββ api.js # API base configuration
β β β βββ socket.js # Socket.io configuration
β β β βββ constants.js # Constants and settings
β β βββ lib/ # Utility functions and helpers
β β β βββ auth.js # Authentication utilities
β β β βββ validators.js # Form validation functions
β β β βββ formatters.js # Data formatting utilities
β β β βββ ... # Other helpers
β β βββ App.jsx # Root component with routing
β β βββ App.css # Global styles
β β βββ main.jsx # React entry point
β β βββ index.css # Global CSS/Tailwind imports
β βββ .gitignore # Git ignore rules
β βββ eslint.config.js # ESLint configuration
β βββ vite.config.js # Vite configuration
β βββ vercel.json # Vercel deployment config
β βββ package.json # Frontend dependencies
β βββ package-lock.json # Locked dependency versions
β βββ index.html # HTML entry point
β βββ README.md # Frontend documentation
β
βββ server/ # Backend Application (Node.js + Express)
β βββ src/
β β βββ config/ # Configuration files
β β β βββ database.js # MongoDB connection
β β β βββ cloudinary.js # Cloudinary setup
β β β βββ constants.js # Backend constants
β β βββ controllers/ # Business logic layer
β β β βββ authController.js # Login, signup, logout logic
β β β βββ chatController.js # Message handling
β β β βββ userController.js # User operations
β β β βββ ... # Other controllers
β β βββ middleware/ # Express middleware
β β β βββ authMiddleware.js # JWT verification
β β β βββ errorHandler.js # Error handling
β β β βββ validation.js # Input validation
β β β βββ ... # Other middleware
β β βββ models/ # MongoDB Schemas (Mongoose)
β β β βββ User.js # User schema
β β β βββ Message.js # Message schema
β β β βββ Conversation.js # Conversation schema
β β β βββ ... # Other models
β β βββ routes/ # API route definitions
β β β βββ authRoutes.js # Auth endpoints
β β β βββ chatRoutes.js # Chat endpoints
β β β βββ userRoutes.js # User endpoints
β β β βββ ... # Other routes
β β βββ app.js # Express app setup
β βββ server.js # Server entry point
β βββ seeds/ # Database seeding scripts
β β βββ seedData.js # Sample data for testing
β βββ .env # Environment variables (local)
β βββ .env.example # Environment variables template
β βββ .gitignore # Git ignore rules
β βββ package.json # Backend dependencies
β βββ package-lock.json # Locked dependency versions
β βββ README.md # Backend documentation
β
βββ package.json # Root package.json (monorepo setup)
βββ package-lock.json # Root dependencies lock
βββ .gitignore # Root git ignore
βββ README.md # This file
- pages/: Route-level components for different views (login, chat, profile)
- components/: Reusable UI components used across pages
- context/: Global state management using React Context API
- config/: Configuration for API endpoints and Socket.io
- lib/: Utility functions and helper methods
- assets/: Static files like images and icons
- controllers/: Contains all business logic separated by feature
- models/: MongoDB schema definitions using Mongoose
- routes/: API endpoint definitions with HTTP methods
- middleware/: Functions that process requests (auth, validation)
- config/: Database and service configurations
- seeds/: Test data for development
- Node.js (v16 or higher)
- npm or yarn
- MongoDB Atlas account (or local MongoDB)
- Cloudinary account (for image uploads)
- Git
git clone https://github.com/controlcoder/chat-app.git
cd chat-appnpm installcd server
npm installCreate a .env file in the server directory:
PORT=5000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_secret_key
CLOUDINARY_NAME=your_cloudinary_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret
NODE_ENV=developmentcd ../client
npm installCreate a .env.local file in the client directory:
VITE_API_URL=http://localhost:5000
VITE_SOCKET_URL=http://localhost:5000From the root directory:
npm run devThis runs both server and client simultaneously using concurrently.
# Terminal 1: Run backend
npm run server
# Terminal 2: Run frontend
npm run client# Build frontend
cd client
npm run build
# Run production server
cd ../server
npm run devPOST /api/auth/signup - Register new user
POST /api/auth/login - User login
POST /api/auth/logout - User logout
POST /api/auth/refresh - Refresh JWT token
GET /api/auth/verify - Verify token validity
GET /api/users/profile - Get user profile
PUT /api/users/profile - Update user profile
GET /api/users/search - Search users
GET /api/users/:id - Get user by ID
DELETE /api/users/:id - Delete user account
GET /api/chats - Get all conversations
GET /api/chats/:id - Get conversation details
POST /api/chats/send - Send message
GET /api/chats/:id/messages - Get conversation messages
DELETE /api/chats/:id/messages - Delete message
Client β Server:
- connect : Establish connection
- message:send : Send a message
- typing:start : User started typing
- typing:stop : User stopped typing
- user:online : User came online
- user:offline : User went offline
Server β Client:
- message:received : New message received
- typing:start : Someone typing
- typing:stop : Someone stopped typing
- users:online : Updated online users list
| Variable | Description | Example |
|---|---|---|
| PORT | Server port | 5000 |
| MONGODB_URI | MongoDB connection string | mongodb+srv://user:pass@cluster.mongodb.net/dbname |
| JWT_SECRET | Secret key for JWT signing | your_super_secret_key_123 |
| JWT_EXPIRE | JWT expiration time | 7d |
| CLOUDINARY_NAME | Cloudinary account name | your_cloudinary_name |
| CLOUDINARY_API_KEY | Cloudinary API key | your_api_key |
| CLOUDINARY_API_SECRET | Cloudinary API secret | your_api_secret |
| NODE_ENV | Environment type | development/production |
| CORS_ORIGIN | Allowed CORS origins | http://localhost:3000 |
| Variable | Description | Example |
|---|---|---|
| VITE_API_URL | Backend API URL | http://localhost:5000 |
| VITE_SOCKET_URL | Socket.io server URL | http://localhost:5000 |
| VITE_APP_NAME | Application name | SnapTalk |
- JWT Authentication: Secure token-based authentication
- Password Hashing: Bcrypt for secure password storage
- CORS Protection: Configured CORS for controlled access
- Environment Variables: Sensitive data in .env files
- Cookie Parsing: Secure HTTP-only cookies for tokens
- Input Validation: Middleware for request validation
- Error Handling: Centralized error management
# Root level
npm run dev # Run both server and client
npm run server # Run backend only
npm run client # Run frontend only
# Frontend commands (from client/)
npm run dev # Start Vite dev server
npm run build # Build for production
npm run preview # Preview production build
npm run lint # Run ESLint
# Backend commands (from server/)
npm run dev # Start with nodemonContributions are welcome! Follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see LICENSE file for details.
controlcoder
- GitHub: @controlcoder
- Live Demo: https://chat-app-controlcoder.vercel.app/
For issues and questions:
- Create an issue on GitHub
- Check existing documentation
- Review the codebase comments
- React & Vite for modern frontend development
- Express.js & Node.js for robust backend
- MongoDB for flexible data storage
- Socket.io for real-time communication
- Tailwind CSS for styling
- All open-source contributors
Last Updated: June 6, 2026
Repository: controlcoder/chat-app