Skip to content

nrbnayon/TalkTalk

Repository files navigation

Real-Time Chat App

Connect instantly with friends and communities through our feature-rich real-time messaging platform

A modern, scalable real-time chat application built with the MERN stack, featuring instant messaging, file sharing, group chats, and advanced communication features for seamless user interactions.

✨ Features

Core Messaging

  • Real-time Messaging - Instant message delivery using Socket.IO
  • Group Chats - Create and manage group conversations
  • Private Messages - Secure one-on-one conversations
  • Message History - Persistent chat history with pagination
  • Typing Indicators - See when others are typing
  • Online Status - Real-time user presence indicators

Advanced Features

  • File Sharing - Share images, documents, and media files
  • Message Reactions - React to messages with emojis
  • Message Search - Find messages across all conversations
  • Push Notifications - Stay updated with desktop and mobile notifications
  • Message Encryption - End-to-end encryption for secure communications
  • Dark/Light Theme - Customizable UI themes

User Management

  • User Authentication - Secure login/register with JWT
  • Profile Management - Customizable user profiles with avatars
  • Friend System - Add, remove, and manage contacts
  • User Search - Find and connect with other users
  • Blocking System - Block unwanted users

πŸš€ Tech Stack

Frontend

Backend

  • Node.js - JavaScript runtime environment
  • Express.js - Fast, unopinionated web framework
  • MongoDB - NoSQL database for scalable data storage
  • Mongoose - MongoDB object modeling for Node.js
  • Socket.IO - Real-time engine for WebSocket connections
  • JWT - JSON Web Tokens for authentication
  • Bcrypt - Password hashing
  • Multer - File upload handling
  • Cloudinary - Cloud-based image and video management

πŸ› οΈ Installation & Setup

Prerequisites

  • Node.js (v18 or higher)
  • MongoDB (local installation or MongoDB Atlas)
  • npm or yarn package manager

Backend Setup

  1. Clone the repository

    git clone https://github.com/nrbnayon/talktalk.git
    cd talktalk
  2. Install backend dependencies

    cd backend
    npm install
  3. Set up environment variables

    cp .env.example .env

    Configure your .env file:

    # Server Configuration
    PORT=5000
    NODE_ENV=development
    
    # Database
    MONGODB_URI=mongodb://localhost:27017/chatapp
    # or MongoDB Atlas: mongodb+srv://username:password@cluster.mongodb.net/chatapp
    
    # JWT Secret
    JWT_SECRET=your-super-secret-jwt-key
    JWT_EXPIRES_IN=7d
    
    # Cloudinary (for file uploads)
    CLOUDINARY_CLOUD_NAME=your-cloud-name
    CLOUDINARY_API_KEY=your-api-key
    CLOUDINARY_API_SECRET=your-api-secret
    
    # CORS Origin (Frontend URL)
    CORS_ORIGIN=http://localhost:3000
  4. Start the backend server

    npm run dev
    # Server will run on http://localhost:5000

Frontend Setup

  1. Install frontend dependencies

    cd ../frontend
    npm install
  2. Set up environment variables

    cp .env.example .env

    Configure your .env file:

    VITE_API_URL=http://localhost:5000
    VITE_SOCKET_URL=http://localhost:5000
    VITE_APP_NAME=ChatApp
  3. Start the frontend development server

    npm run dev
    # Frontend will run on http://localhost:3000

πŸ“ Project Structure

realtime-chat-app/
β”œβ”€β”€ backend/                    # Node.js/Express backend
β”‚   β”œβ”€β”€ controllers/           # Route controllers
β”‚   β”‚   β”œβ”€β”€ authController.js
β”‚   β”‚   β”œβ”€β”€ chatController.js
β”‚   β”‚   β”œβ”€β”€ messageController.js
β”‚   β”‚   └── userController.js
β”‚   β”œβ”€β”€ middleware/            # Custom middleware
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ upload.js
β”‚   β”‚   └── validation.js
β”‚   β”œβ”€β”€ models/               # MongoDB models
β”‚   β”‚   β”œβ”€β”€ User.js
β”‚   β”‚   β”œβ”€β”€ Chat.js
β”‚   β”‚   └── Message.js
β”‚   β”œβ”€β”€ routes/               # API routes
β”‚   β”‚   β”œβ”€β”€ auth.js
β”‚   β”‚   β”œβ”€β”€ chats.js
β”‚   β”‚   β”œβ”€β”€ messages.js
β”‚   β”‚   └── users.js
β”‚   β”œβ”€β”€ socket/               # Socket.IO configuration
β”‚   β”‚   └── socketHandler.js
β”‚   β”œβ”€β”€ utils/                # Utility functions
β”‚   β”‚   β”œβ”€β”€ cloudinary.js
β”‚   β”‚   β”œβ”€β”€ generateToken.js
β”‚   β”‚   └── encryption.js
β”‚   β”œβ”€β”€ config/               # Configuration files
β”‚   β”‚   └── database.js
β”‚   └── server.js             # Entry point
β”‚
β”œβ”€β”€ frontend/                  # React frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/       # Reusable UI components
β”‚   β”‚   β”‚   β”œβ”€β”€ Chat/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatList.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ ChatWindow.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ MessageInput.tsx
β”‚   β”‚   β”‚   β”‚   └── MessageBubble.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Auth/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ LoginForm.tsx
β”‚   β”‚   β”‚   β”‚   └── RegisterForm.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Layout/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Sidebar.tsx
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ Header.tsx
β”‚   β”‚   β”‚   β”‚   └── Layout.tsx
β”‚   β”‚   β”‚   └── UI/           # Common UI components
β”‚   β”‚   β”‚       β”œβ”€β”€ Button.tsx
β”‚   β”‚   β”‚       β”œβ”€β”€ Modal.tsx
β”‚   β”‚   β”‚       └── Avatar.tsx
β”‚   β”‚   β”œβ”€β”€ pages/            # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Login.tsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Register.tsx
β”‚   β”‚   β”‚   └── Profile.tsx
β”‚   β”‚   β”œβ”€β”€ hooks/            # Custom React hooks
β”‚   β”‚   β”‚   β”œβ”€β”€ useSocket.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ useAuth.ts
β”‚   β”‚   β”‚   └── useChat.ts
β”‚   β”‚   β”œβ”€β”€ store/            # State management
β”‚   β”‚   β”‚   β”œβ”€β”€ authStore.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ chatStore.ts
β”‚   β”‚   β”‚   └── uiStore.ts
β”‚   β”‚   β”œβ”€β”€ services/         # API services
β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ authService.ts
β”‚   β”‚   β”‚   └── chatService.ts
β”‚   β”‚   β”œβ”€β”€ types/            # TypeScript definitions
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ chat.ts
β”‚   β”‚   β”‚   └── user.ts
β”‚   β”‚   β”œβ”€β”€ utils/            # Utility functions
β”‚   β”‚   β”‚   β”œβ”€β”€ formatTime.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ encryption.ts
β”‚   β”‚   β”‚   └── constants.ts
β”‚   β”‚   └── styles/           # Global styles
β”‚   β”‚       └── globals.css
β”‚   β”œβ”€β”€ public/               # Static assets
β”‚   └── package.json
β”‚
β”œβ”€β”€ README.md
β”œβ”€β”€ docker-compose.yml        # Docker configuration
└── .gitignore

πŸ”§ API Endpoints

Authentication

POST   /api/auth/register     # User registration
POST   /api/auth/login        # User login
POST   /api/auth/logout       # User logout
GET    /api/auth/me           # Get current user
PUT    /api/auth/profile      # Update profile

Users

GET    /api/users             # Get all users
GET    /api/users/search      # Search users
POST   /api/users/friend      # Send friend request
PUT    /api/users/friend      # Accept/decline friend request
DELETE /api/users/friend/:id  # Remove friend

Chats

GET    /api/chats             # Get user's chats
POST   /api/chats             # Create new chat
GET    /api/chats/:id         # Get chat details
PUT    /api/chats/:id         # Update chat
DELETE /api/chats/:id         # Delete chat

Messages

GET    /api/messages/:chatId  # Get chat messages
POST   /api/messages          # Send message
PUT    /api/messages/:id      # Edit message
DELETE /api/messages/:id      # Delete message
POST   /api/messages/upload   # Upload file

πŸ”Œ Socket.IO Events

Client to Server

// Connection
'join-room'              // Join a chat room
'leave-room'             // Leave a chat room

// Messaging
'send-message'           // Send a new message
'edit-message'           // Edit existing message
'delete-message'         // Delete a message
'typing-start'           // Start typing indicator
'typing-stop'            // Stop typing indicator

// Status
'user-online'            // User comes online
'user-offline'           // User goes offline

Server to Client

// Messaging
'new-message'            // Receive new message
'message-edited'         // Message was edited
'message-deleted'        // Message was deleted

// Typing
'user-typing'            // Someone is typing
'user-stopped-typing'    // Someone stopped typing

// Status
'user-status'            // User status update
'message-delivered'      // Message delivery confirmation
'message-read'           // Message read confirmation

🎨 Key Components

Frontend Components

ChatWindow Component

interface ChatWindowProps {
  chatId: string;
  messages: Message[];
  onSendMessage: (content: string) => void;
}

MessageBubble Component

interface MessageBubbleProps {
  message: Message;
  isOwnMessage: boolean;
  onEdit?: (messageId: string, content: string) => void;
  onDelete?: (messageId: string) => void;
}

πŸ›‘οΈ Security Features

  • JWT Authentication - Secure token-based authentication
  • Password Hashing - Bcrypt for secure password storage
  • Input Validation - Comprehensive request validation
  • Rate Limiting - Prevent spam and abuse
  • CORS Configuration - Secure cross-origin requests
  • File Upload Security - Safe file handling and validation
  • XSS Protection - Input sanitization and output encoding

πŸ“Š Available Scripts

Backend Scripts

npm run dev          # Start development server with nodemon
npm run start        # Start production server
npm run test         # Run test suite
npm run lint         # Run ESLint
npm run build        # Build for production

Frontend Scripts

npm run dev          # Start Vite development server
npm run build        # Build for production
npm run preview      # Preview production build
npm run test         # Run Vitest tests
npm run lint         # Run ESLint
npm run type-check   # Run TypeScript compiler check

πŸš€ Deployment

Using Docker

  1. Build and run with Docker Compose

    docker-compose up --build
  2. Environment variables for production

    NODE_ENV=production
    MONGODB_URI=your-production-mongodb-uri
    CORS_ORIGIN=https://your-frontend-domain.com

Manual Deployment

Backend (Node.js)

  1. Build the application

    cd backend
    npm run build
  2. Deploy to platforms like:

    • Heroku: git push heroku main
    • Railway: Connect GitHub repository
    • DigitalOcean: Use App Platform
    • AWS: EC2 or Elastic Beanstalk

Frontend (React)

  1. Build the application

    cd frontend
    npm run build
  2. Deploy to platforms like:

    • Vercel: vercel --prod
    • Netlify: Drag and drop dist folder
    • AWS S3: Upload build files to S3 bucket
    • GitHub Pages: Use GitHub Actions

Production Environment Variables

Backend (.env)

NODE_ENV=production
PORT=5000
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/chatapp
JWT_SECRET=your-super-secure-jwt-secret-for-production
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret
CORS_ORIGIN=https://your-frontend-domain.com

Frontend (.env)

VITE_API_URL=https://your-backend-domain.com
VITE_SOCKET_URL=https://your-backend-domain.com
VITE_APP_NAME=ChatApp

πŸ§ͺ Testing

Backend Testing

cd backend
npm run test

# Run specific test files
npm run test -- --grep "Auth"
npm run test -- --grep "Chat"

Frontend Testing

cd frontend
npm run test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

πŸ” Performance Optimization

Backend Optimizations

  • Database Indexing - Optimized MongoDB queries
  • Connection Pooling - Efficient database connections
  • Caching - Redis for session and data caching
  • Compression - Gzip compression for responses
  • Rate Limiting - Prevent excessive requests

Frontend Optimizations

  • Code Splitting - Lazy loading of components
  • Bundle Optimization - Tree shaking and minification
  • Image Optimization - WebP format and lazy loading
  • Memoization - React.memo for expensive components
  • Virtual Scrolling - Efficient rendering of large lists

🀝 Contributing

We welcome contributions! Please follow these guidelines:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Make your changes
    • Follow the existing code style
    • Add tests for new features
    • Update documentation as needed
  4. Commit your changes
    git commit -m 'Add some amazing feature'
  5. Push to the branch
    git push origin feature/amazing-feature
  6. Open a Pull Request

Development Guidelines

  • Use TypeScript for type safety
  • Follow ESLint rules
  • Write meaningful commit messages
  • Add tests for new functionality
  • Update README for significant changes

πŸ“š Documentation

πŸ”§ Troubleshooting

Common Issues

Backend Issues

  • MongoDB Connection: Ensure MongoDB is running and connection string is correct
  • Port Conflicts: Change PORT in .env if 5000 is occupied
  • JWT Errors: Check JWT_SECRET is set correctly

Frontend Issues

  • API Connection: Verify VITE_API_URL matches backend URL
  • Socket Connection: Check VITE_SOCKET_URL configuration
  • Build Errors: Clear node_modules and reinstall dependencies

Socket.IO Issues

  • Connection Failures: Check CORS configuration
  • Message Delays: Verify WebSocket support
  • Room Joining: Ensure proper authentication

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

πŸ“ž Support & Community

πŸ—ΊοΈ Roadmap

  • Mobile Apps - React Native iOS and Android apps
  • Video Calls - WebRTC integration for video chat
  • Voice Messages - Audio message support
  • Message Translation - Multi-language support
  • Bot Integration - Chatbot and automation features
  • Screen Sharing - Share screen during conversations
  • Advanced Moderation - Admin tools and content filtering
  • Custom Themes - User-customizable chat themes

Built with ❀️ using the MERN Stack

⭐ Star us on GitHub | 🐦 Follow us on Twitter | 🌐 Visit our website

About

A modern, scalable real-time chat application built with the MERN stack, featuring instant messaging, file sharing, group chats, and advanced communication features for seamless user interactions.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors