Skip to content

๐Ÿš€ FlowChat is a modern, enterprise-grade real-time messaging application designed for scalability, security, and exceptional user experience

License

Notifications You must be signed in to change notification settings

AHMAD-JX/FlowChat-RealTime-Chat-Application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

FlowChat - Enterprise-Grade Real-Time Chat Application

FlowChat Logo Version License

A production-ready, scalable real-time messaging platform built with enterprise standards

Next.js TypeScript Express MongoDB Socket.io Redis

๐ŸŒ€ Animations

GIF 1 GIF 1 GIF 1 GIF 1

๐ŸŒ€ IMG

GIF 1 GIF 1

Features โ€ข Architecture โ€ข Quick Start โ€ข API Documentation โ€ข Deployment โ€ข Contributing


๐Ÿ“‹ Table of Contents


๐ŸŽฏ Overview

FlowChat is a modern, enterprise-grade real-time messaging application designed for scalability, security, and exceptional user experience. Built with cutting-edge technologies, FlowChat provides a WhatsApp-like interface with advanced features including real-time messaging, media sharing, presence management, and multi-language support.

Key Highlights

  • โšก Real-Time Communication - Instant messaging with WebSocket technology
  • ๐Ÿ”’ Enterprise Security - JWT authentication, rate limiting, input sanitization
  • ๐Ÿ“ฑ Responsive Design - Seamless experience across all devices
  • ๐ŸŒ Multi-Language Support - Full RTL support for Arabic and other languages
  • ๐Ÿ“ธ Media Sharing - High-quality image and video sharing
  • ๐Ÿš€ Scalable Architecture - Built for high performance and scalability
  • ๐Ÿ’ผ Production Ready - Battle-tested code with comprehensive error handling

โœจ Features

Core Features

๐Ÿ’ฌ Real-Time Messaging

  • โœ… Instant Messaging - Send and receive messages in real-time
  • โœ… Message History - Persistent message storage with MongoDB
  • โœ… Message Status - Sent, Delivered, and Read receipts
  • โœ… Message Reply - Reply to specific messages in conversations
  • โœ… Message Deletion - Delete individual messages or entire chats
  • โœ… Multi-line Messages - Support for formatted text with line breaks
  • โœ… RTL Support - Automatic right-to-left text direction for Arabic

๐Ÿ‘ฅ User Management

  • โœ… User Registration - Secure account creation with validation
  • โœ… Multiple Login Methods - Login with email or phone number
  • โœ… Profile Management - Update username, email, bio, and avatar
  • โœ… Avatar Upload - Profile picture upload with image optimization
  • โœ… User Search - Find users by username or phone number
  • โœ… Contact Management - Add and manage contacts easily

๐Ÿ’ผ Chat Management

  • โœ… One-on-One Chats - Private conversations between users
  • โœ… Chat Search - Search through chat history
  • โœ… Chat Deletion - Delete entire conversations with all messages
  • โœ… Chat List - View all active conversations
  • โœ… Last Message Preview - See last message in chat list
  • โœ… Unread Message Indicators - Visual indicators for unread messages

Real-Time Features

โšก WebSocket Communication

  • โœ… Socket.io Integration - Bidirectional real-time communication
  • โœ… Connection Management - Automatic reconnection and connection pooling
  • โœ… Room-Based Messaging - Efficient chat room management
  • โœ… Event-Driven Architecture - Real-time events for all actions

๐Ÿ‘๏ธ Presence Management

  • โœ… Online/Offline Status - Real-time user presence indicators
  • โœ… Redis-Based Presence - Scalable presence tracking with Redis
  • โœ… Typing Indicators - See when users are typing
  • โœ… Auto-Timeout - Automatic offline status after inactivity

๐Ÿ”” Real-Time Notifications

  • โœ… New Message Alerts - Instant notifications for new messages
  • โœ… Typing Notifications - Real-time typing indicators
  • โœ… Status Updates - Live updates for online/offline status
  • โœ… Message Delivery - Real-time delivery confirmations

Media Features

๐Ÿ“ธ Image & Video Sharing

  • โœ… Image Upload - Share high-quality images (up to 10MB)
  • โœ… Video Upload - Share videos (up to 50MB)
  • โœ… Multiple Formats - Support for JPEG, PNG, GIF, WebP, MP4, MOV, AVI, MKV, WebM
  • โœ… Image Preview - Preview images before sending
  • โœ… Image Lightbox - Full-screen image viewing
  • โœ… Video Playback - Inline video player with controls
  • โœ… Media Optimization - Automatic file compression and optimization

๐ŸŽจ Media Management

  • โœ… File Validation - Type and size validation before upload
  • โœ… Secure Storage - Files stored securely on server
  • โœ… CDN Ready - Architecture supports CDN integration
  • โœ… Thumbnail Generation - Automatic thumbnail creation (future)

User Experience

๐ŸŽจ Modern UI/UX

  • โœ… WhatsApp-Like Interface - Familiar and intuitive design
  • โœ… Responsive Design - Perfect on desktop, tablet, and mobile
  • โœ… Smooth Animations - Fluid transitions powered by Framer Motion
  • โœ… Dark Mode Ready - Architecture supports theme switching
  • โœ… Loading States - Elegant loading indicators
  • โœ… Error Handling - User-friendly error messages
  • โœ… Accessibility - WCAG compliant components

๐ŸŒ Internationalization

  • โœ… RTL Support - Full right-to-left text support for Arabic
  • โœ… Auto-Detection - Automatic text direction detection
  • โœ… Multi-Language Ready - Architecture supports i18n (future)

๐Ÿ“ฑ Mobile Experience

  • โœ… Touch Optimized - Optimized for touch interactions
  • โœ… Mobile Navigation - Sidebar navigation for mobile
  • โœ… Responsive Layout - Adaptive layout for all screen sizes
  • โœ… Performance - Optimized for mobile networks

๐Ÿ›  Technology Stack

Frontend

Technology Version Purpose
Next.js 16.0.1 React framework with SSR and routing
React 19.2.0 UI library with hooks and context
TypeScript 5.5 Type-safe JavaScript
Tailwind CSS 4.0 Utility-first CSS framework
Framer Motion 12.23 Animation library
Socket.io Client 4.8.1 Real-time WebSocket client
Axios 1.13 HTTP client for API calls
Lucide React 0.552 Icon library
React Globe 2.37 3D globe visualization

Backend

Technology Version Purpose
Node.js 18+ JavaScript runtime
Express.js 4.21 Web application framework
TypeScript 5.3 Type-safe JavaScript
Socket.io 4.8.1 WebSocket server for real-time
MongoDB 8.0 NoSQL database
Mongoose 8.0 MongoDB object modeling
Redis (ioredis) 5.8 In-memory cache and presence
JWT 9.0 Authentication tokens
Bcrypt 2.4 Password hashing
Multer 2.0 File upload handling
Helmet 7.1 Security headers
Express Validator 7.0 Input validation
Express Rate Limit 7.1 Rate limiting

Infrastructure

  • MongoDB - Primary database for persistent storage
  • Redis - Caching and presence management
  • File System - Media file storage (CDN-ready)
  • WebSocket - Real-time communication protocol

๐Ÿ— Architecture

System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Frontend      โ”‚         โ”‚     Backend     โ”‚         โ”‚   Databases     โ”‚
โ”‚   (Next.js)     โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚   (Express)     โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚   (MongoDB)     โ”‚
โ”‚                 โ”‚  HTTP   โ”‚                 โ”‚         โ”‚                 โ”‚
โ”‚  โ€ข React UI     โ”‚         โ”‚  โ€ข REST API     โ”‚         โ”‚  โ€ข User Data    โ”‚
โ”‚  โ€ข Socket.io    โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚  โ€ข Socket.io    โ”‚         โ”‚  โ€ข Messages     โ”‚
โ”‚    Client       โ”‚  WS     โ”‚    Server       โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–บโ”‚  โ€ข Chats        โ”‚
โ”‚  โ€ข State Mgmt   โ”‚         โ”‚  โ€ข Controllers  โ”‚         โ”‚                 โ”‚
โ”‚  โ€ข Services     โ”‚         โ”‚  โ€ข Middleware   โ”‚         โ”‚   (Redis)       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜         โ”‚  โ€ข Presence     โ”‚
                                                          โ”‚  โ€ข Cache        โ”‚
                                                          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Data Flow

  1. Authentication Flow

    User โ†’ Frontend โ†’ Backend API โ†’ MongoDB โ†’ JWT Token โ†’ Frontend Storage
    
  2. Message Flow

    User โ†’ Frontend โ†’ Socket.io โ†’ Backend โ†’ MongoDB โ†’ Socket.io โ†’ Recipient
    
  3. Presence Flow

    User Online โ†’ Socket.io โ†’ Redis โ†’ Socket.io โ†’ All Connected Clients
    

Folder Structure

FlowChat - RealTime Chat Application/
โ”œโ”€โ”€ frontend/                          # Next.js Frontend Application
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ app/                      # Next.js App Router
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx              # Landing page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ login/                # Login page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ signup/               # Signup page
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ chat/                 # Chat application
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ page.tsx          # Main chat interface
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx            # Root layout
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ globals.css           # Global styles
โ”‚   โ”‚   โ”œโ”€โ”€ components/                # Reusable components
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ui/                   # Base UI components
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ ...
โ”‚   โ”‚   โ”œโ”€โ”€ lib/                      # Utilities and configs
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ api.ts                # Axios instance
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ socket.ts             # Socket.io client
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ utils.ts              # Helper functions
โ”‚   โ”‚   โ”œโ”€โ”€ services/                 # API services
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.service.ts       # Authentication
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ chat.service.ts       # Chat operations
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/                    # Custom React hooks
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ useChat.ts            # Chat state management
โ”‚   โ”‚   โ””โ”€โ”€ context/                  # React contexts
โ”‚   โ”‚       โ””โ”€โ”€ SocketContext.tsx     # Socket provider
โ”‚   โ”œโ”€โ”€ public/                       # Static assets
โ”‚   โ”‚   โ””โ”€โ”€ images/                   # Images
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ tsconfig.json
โ”‚   โ”œโ”€โ”€ tailwind.config.ts
โ”‚   โ””โ”€โ”€ .env.local
โ”‚
โ”œโ”€โ”€ backend/                           # Express.js Backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ config/                   # Configuration files
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ database.ts           # MongoDB connection
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ redis.ts              # Redis connection
โ”‚   โ”‚   โ”œโ”€โ”€ controllers/              # Request handlers
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.controller.ts    # Authentication logic
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ chat.controller.ts    # Chat operations
โ”‚   โ”‚   โ”œโ”€โ”€ middleware/               # Express middleware
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.middleware.ts   # JWT verification
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ errorHandler.ts       # Error handling
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ rateLimiter.ts        # Rate limiting
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ upload.middleware.ts  # File upload
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ validation.middleware.ts
โ”‚   โ”‚   โ”œโ”€โ”€ models/                   # Mongoose schemas
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ User.model.ts         # User schema
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Chat.model.ts         # Chat schema
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Message.model.ts       # Message schema
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Friend.model.ts       # Friend schema
โ”‚   โ”‚   โ”œโ”€โ”€ routes/                   # API routes
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ auth.routes.ts        # Auth endpoints
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ chat.routes.ts        # Chat endpoints
โ”‚   โ”‚   โ”œโ”€โ”€ socket/                   # Socket.io handlers
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ socket.ts             # WebSocket logic
โ”‚   โ”‚   โ”œโ”€โ”€ utils/                    # Utility functions
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ AppError.ts           # Custom errors
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ catchAsync.ts         # Async wrapper
โ”‚   โ”‚   โ””โ”€โ”€ server.ts                 # Express app entry
โ”‚   โ”œโ”€โ”€ public/                       # Static files
โ”‚   โ”‚   โ””โ”€โ”€ uploads/                  # User uploads
โ”‚   โ”‚       โ”œโ”€โ”€ avatars/              # Profile pictures
โ”‚   โ”‚       โ””โ”€โ”€ chat-media/           # Chat media files
โ”‚   โ”œโ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ tsconfig.json
โ”‚   โ””โ”€โ”€ .env
โ”‚
โ””โ”€โ”€ README.md                          # This file

๐Ÿš€ Getting Started

Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js (v18.0 or higher) - Download
  • npm (v9.0 or higher) or yarn
  • MongoDB (v6.0 or higher) - Download
  • Redis (v7.0 or higher) - Download

Quick Start

  1. Clone the repository

    git clone https://github.com/yourusername/flowchat.git
    cd flowchat
  2. Install dependencies

    # Frontend
    cd frontend
    npm install
    
    # Backend
    cd ../backend
    npm install
  3. Configure environment variables

    Create .env.local in frontend/:

    NEXT_PUBLIC_API_URL=http://localhost:5000/api
    NEXT_PUBLIC_SOCKET_URL=http://localhost:5000

    Create .env in backend/:

    PORT=5000
    NODE_ENV=development
    
    MONGODB_URI=mongodb://localhost:27017/FlowChat
    REDIS_URL=redis://localhost:6379
    
    JWT_SECRET=your-super-secret-jwt-key-change-in-production
    JWT_EXPIRE=7d
    JWT_COOKIE_EXPIRE=7
    
    FRONTEND_URL=http://localhost:3000
    
    RATE_LIMIT_WINDOW_MS=900000
    RATE_LIMIT_MAX_REQUESTS=100
  4. Start MongoDB and Redis

    # MongoDB
    mongod
    
    # Redis
    redis-server
  5. Start the application

    # Terminal 1 - Backend
    cd backend
    npm run dev
    
    # Terminal 2 - Frontend
    cd frontend
    npm run dev
  6. Access the application


๐Ÿ’ป Frontend Setup

Detailed Setup Instructions

  1. Navigate to frontend directory

    cd frontend
  2. Install dependencies

    npm install
  3. Environment configuration

    Create .env.local:

    NEXT_PUBLIC_API_URL=http://localhost:5000/api
    NEXT_PUBLIC_SOCKET_URL=http://localhost:5000
  4. Development server

    npm run dev

    Access at: http://localhost:3000

  5. Production build

    npm run build
    npm start

Frontend Features

  • Server-Side Rendering (SSR) - Fast initial page loads
  • Code Splitting - Optimized bundle sizes
  • Image Optimization - Automatic image optimization
  • Hot Module Replacement - Instant updates during development

๐Ÿ”ง Backend Setup

Detailed Setup Instructions

  1. Navigate to backend directory

    cd backend
  2. Install dependencies

    npm install
  3. Environment configuration

    Create .env:

    # Server
    PORT=5000
    NODE_ENV=development
    
    # Database
    MONGODB_URI=mongodb://localhost:27017/FlowChat
    REDIS_URL=redis://localhost:6379
    
    # Authentication
    JWT_SECRET=your-super-secret-jwt-key-min-32-chars
    JWT_EXPIRE=7d
    JWT_COOKIE_EXPIRE=7
    
    # CORS
    FRONTEND_URL=http://localhost:3000
    
    # Rate Limiting
    RATE_LIMIT_WINDOW_MS=900000
    RATE_LIMIT_MAX_REQUESTS=100
  4. Start MongoDB

    # Windows
    net start MongoDB
    
    # macOS/Linux
    sudo systemctl start mongod
    # or
    mongod
  5. Start Redis

    # Windows (if installed)
    redis-server
    
    # macOS
    brew services start redis
    
    # Linux
    sudo systemctl start redis
  6. Development server

    npm run dev

    Access at: http://localhost:5000

  7. Production build

    npm run build
    npm start

๐Ÿ“ก API Documentation

Base URL

Development: http://localhost:5000/api
Production: https://api.flowchat.com/api

Authentication API

Register User

POST /api/auth/register
Content-Type: application/json

{
  "username": "johndoe",
  "email": "john@example.com",
  "phone": "+1234567890",
  "password": "SecurePass123!",
  "confirmPassword": "SecurePass123!",
  "countryCode": "+1"
}

Response:

{
  "success": true,
  "message": "User registered successfully",
  "data": {
    "user": {
      "id": "65f1234567890abcdef12345",
      "username": "johndoe",
      "email": "john@example.com",
      "username": "johndoe",
      "isEmailVerified": false,
      "createdAt": "2024-01-01T00:00:00.000Z"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Login User

POST /api/auth/login
Content-Type: application/json

{
  "emailOrPhone": "john@example.com",
  "password": "SecurePass123!"
}

Response:

{
  "success": true,
  "message": "Login successful",
  "data": {
    "user": {
      "id": "65f1234567890abcdef12345",
      "username": "johndoe",
      "email": "john@example.com",
      "avatar": "/uploads/avatars/avatar-123.jpg",
      "lastLogin": "2024-01-01T00:00:00.000Z"
    },
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
  }
}

Get Current User

GET /api/auth/me
Authorization: Bearer YOUR_JWT_TOKEN

Upload Profile Avatar

POST /api/auth/upload-avatar
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data

avatar: [binary file]

Update Profile

PATCH /api/auth/update-profile
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "username": "newusername",
  "bio": "My bio",
  "email": "newemail@example.com"
}

Update Password

PATCH /api/auth/update-password
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "currentPassword": "OldPass123!",
  "newPassword": "NewPass123!",
  "confirmNewPassword": "NewPass123!"
}

Chat API

Search Users

GET /api/chat/search/users?query=johndoe
Authorization: Bearer YOUR_JWT_TOKEN

Create or Get Chat

POST /api/chat
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: application/json

{
  "userId": "65f1234567890abcdef12345"
}

Get All Chats

GET /api/chat
Authorization: Bearer YOUR_JWT_TOKEN

Get Chat by ID

GET /api/chat/:id
Authorization: Bearer YOUR_JWT_TOKEN

Get Chat Messages

GET /api/chat/:id/messages?page=1&limit=50
Authorization: Bearer YOUR_JWT_TOKEN

Delete Chat

DELETE /api/chat/:id
Authorization: Bearer YOUR_JWT_TOKEN

Media API

Upload Media File

POST /api/chat/upload-media
Authorization: Bearer YOUR_JWT_TOKEN
Content-Type: multipart/form-data

media: [binary file (image or video)]

Response:

{
  "success": true,
  "data": {
    "url": "/uploads/chat-media/media-1234567890.jpg",
    "type": "image",
    "filename": "media-1234567890.jpg",
    "size": 1024000,
    "mimetype": "image/jpeg"
  }
}

WebSocket API

Connection

const socket = io('http://localhost:5000', {
  auth: {
    token: 'YOUR_JWT_TOKEN'
  }
});

Events

Client โ†’ Server:

  • chat:join - Join a chat room

    socket.emit('chat:join', chatId);
  • chat:leave - Leave a chat room

    socket.emit('chat:leave', chatId);
  • message:send - Send a message

    socket.emit('message:send', {
      chatId: 'chat_id',
      content: 'Hello!',
      type: 'text', // 'text' | 'image' | 'video'
      fileUrl: '/uploads/chat-media/media.jpg', // optional
      replyTo: 'message_id' // optional
    });
  • typing:start - Start typing indicator

    socket.emit('typing:start', chatId);
  • typing:stop - Stop typing indicator

    socket.emit('typing:stop', chatId);
  • message:read - Mark message as read

    socket.emit('message:read', {
      messageId: 'message_id',
      chatId: 'chat_id'
    });

Server โ†’ Client:

  • message:receive - New message received

    socket.on('message:receive', (data) => {
      console.log('New message:', data.message);
    });
  • typing:update - Typing status update

    socket.on('typing:update', (data) => {
      console.log('User typing:', data.userId, data.chatId);
    });
  • user:online - User came online

    socket.on('user:online', (data) => {
      console.log('User online:', data.userId);
    });
  • user:offline - User went offline

    socket.on('user:offline', (data) => {
      console.log('User offline:', data.userId);
    });
  • message:error - Message error

    socket.on('message:error', (data) => {
      console.error('Message error:', data.error);
    });

๐Ÿ” Security

Authentication & Authorization

  • JWT Tokens - Secure, stateless authentication
  • HttpOnly Cookies - Protection against XSS attacks
  • Token Expiration - 7-day token expiry with refresh capability
  • Password Hashing - Bcrypt with 12 salt rounds

Security Headers (Helmet.js)

  • X-DNS-Prefetch-Control
  • X-Frame-Options: DENY
  • X-Content-Type-Options: nosniff
  • X-XSS-Protection: 1; mode=block
  • Content-Security-Policy
  • Strict-Transport-Security

Input Validation & Sanitization

  • Express Validator - Server-side validation
  • NoSQL Injection Prevention - Express Mongo Sanitize
  • XSS Protection - Input sanitization
  • File Upload Validation - Type and size validation

Rate Limiting

  • General API: 100 requests per 15 minutes
  • Authentication: 5 attempts per 15 minutes
  • File Upload: 10 uploads per hour

Password Requirements

  • Minimum 8 characters
  • At least one uppercase letter
  • At least one lowercase letter
  • At least one number
  • At least one special character (recommended)

CORS Configuration

  • Whitelist-based origin validation
  • Credentials support
  • Method and header restrictions

โšก Performance

Frontend Optimizations

  • Server-Side Rendering - Fast initial page loads
  • Code Splitting - Route-based code splitting
  • Image Optimization - Next.js Image component
  • Lazy Loading - Dynamic imports for heavy components
  • Memoization - React.memo and useMemo for expensive operations
  • Virtual Scrolling - Efficient message list rendering (future)

Backend Optimizations

  • Database Indexing - Optimized MongoDB queries
  • Redis Caching - Presence and session caching
  • Connection Pooling - MongoDB connection pooling
  • Async Operations - Non-blocking I/O operations
  • File Compression - Gzip compression for responses

Scalability Features

  • Horizontal Scaling - Stateless architecture
  • Load Balancing Ready - Session-less design
  • CDN Integration - Static asset delivery
  • Database Sharding - MongoDB sharding support
  • Redis Clustering - Redis cluster support

๐Ÿ“ Project Structure

See Architecture section for detailed structure.


๐Ÿš€ Deployment

Environment Variables

Frontend (.env.local)

NEXT_PUBLIC_API_URL=https://api.flowchat.com/api
NEXT_PUBLIC_SOCKET_URL=https://api.flowchat.com

Backend (.env)

PORT=5000
NODE_ENV=production

MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/FlowChat
REDIS_URL=redis://redis-server:6379

JWT_SECRET=production-secret-key-min-32-characters
JWT_EXPIRE=7d
JWT_COOKIE_EXPIRE=7

FRONTEND_URL=https://flowchat.com

RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

Deployment Options

Vercel (Frontend)

cd frontend
vercel deploy

Railway / Render (Backend)

  1. Connect your repository
  2. Set environment variables
  3. Deploy automatically

Docker (Optional)

# Dockerfile example
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
CMD ["npm", "start"]

Production Checklist

  • Update JWT_SECRET to strong random string
  • Set NODE_ENV=production
  • Configure MongoDB connection string
  • Configure Redis connection
  • Set up CDN for media files
  • Configure SSL certificates
  • Set up monitoring and logging
  • Configure backups
  • Set up error tracking (Sentry)
  • Configure rate limiting
  • Set up CI/CD pipeline

๐Ÿงช Testing

Manual Testing

Authentication Flow

# Register
curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "testuser",
    "email": "test@example.com",
    "password": "Test123456!",
    "confirmPassword": "Test123456!"
  }'

# Login
curl -X POST http://localhost:5000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "emailOrPhone": "test@example.com",
    "password": "Test123456!"
  }'

API Testing

Use tools like:

  • Postman - API testing and documentation
  • Insomnia - REST client
  • Thunder Client - VS Code extension

Socket.io Testing

// Test socket connection
const socket = io('http://localhost:5000', {
  auth: { token: 'YOUR_TOKEN' }
});

socket.on('connect', () => {
  console.log('Connected!');
});

๐Ÿ—บ Roadmap

โœ… Phase 1: Core Features (Completed)

  • User authentication and registration
  • Real-time messaging with Socket.io
  • One-on-one chats
  • Message status (sent, delivered, read)
  • Typing indicators
  • Online/offline status
  • Profile management
  • Avatar upload

โœ… Phase 2: Enhanced Features (Completed)

  • Media sharing (images and videos)
  • Message reply functionality
  • Chat deletion
  • User search
  • RTL language support
  • Multi-line messages
  • Image lightbox

๐Ÿšง Phase 3: Advanced Features (In Progress)

  • Group chats
  • Message reactions
  • Message forwarding
  • Voice messages
  • Video calls
  • Screen sharing
  • File sharing (documents)

๐Ÿ“‹ Phase 4: Enterprise Features (Planned)

  • End-to-end encryption
  • Message search
  • Message archiving
  • Push notifications
  • Email notifications
  • Two-factor authentication
  • Admin dashboard
  • Analytics and reporting

๐Ÿ”ฎ Phase 5: Future Enhancements

  • AI chatbot integration
  • Voice-to-text transcription
  • Message translation
  • Custom themes
  • Stickers and emoji packs
  • Bot API
  • Webhooks
  • API for third-party integrations

๐Ÿ‘ฅ Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
  3. Commit your changes
    git commit -m 'Add amazing feature'
  4. Push to the branch
    git push origin feature/amazing-feature
  5. Open a Pull Request

Contribution Guidelines

  • Follow TypeScript best practices
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation
  • Follow code style guidelines
  • Ensure all tests pass

๐Ÿ“„ License

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


๐Ÿ’ฌ Support

For support and questions:


๐Ÿ™ Acknowledgments

  • Next.js Team - Amazing React framework
  • Express.js - Robust web framework
  • Socket.io - Real-time communication
  • MongoDB - Flexible database solution
  • Redis - Fast in-memory data store
  • Framer Motion - Beautiful animations
  • Tailwind CSS - Utility-first CSS
  • All Contributors - Who made this project possible

๐Ÿ“Š Statistics

  • โญ Stars: Growing daily
  • ๐Ÿด Forks: Active development
  • ๐Ÿ‘ฅ Contributors: Welcoming new contributors
  • ๐Ÿ“ฆ Downloads: Increasing adoption
  • ๐Ÿ› Issues Resolved: 100% response rate

Made with โค๏ธ by the FlowChat Team

โญ Star us on GitHub if you find this project helpful!

GitHub stars GitHub forks

Built for Enterprise | Production Ready | Scalable | Secure

About

๐Ÿš€ FlowChat is a modern, enterprise-grade real-time messaging application designed for scalability, security, and exceptional user experience

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages