Skip to content

Basant1Saini/Real-time-chat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Real-time-chat

Tech Stack

  • MongoDB - Database
  • Express.js - Backend Framework
  • React - Frontend Library
  • Vite - Build Tool
  • Node.js - Runtime Environment

Note: This project strictly avoids deprecated libraries and outdated methods, utilizing modern versions of React, Express, and Mongoose for stability and security.

Project Plan

Phase 1: Backend Development

1. Project Initialization

  • Create Node.js project with npm init
  • Install dependencies: express, mongoose, socket.io, bcryptjs, jsonwebtoken, cors, dotenv
  • Set up project structure with controllers, models, routes, and middleware folders
  • Configure environment variables for database and JWT secrets

2. Database Setup

  • Connect to MongoDB using Mongoose
  • Create User schema with username, email, password, and timestamps
  • Create Message schema with sender, content, room, and timestamp
  • Create Room schema with name, participants, and creation date
  • Implement database connection with error handling

3. Authentication System

  • Create user registration endpoint with password hashing
  • Implement login endpoint with JWT token generation
  • Add middleware for token verification
  • Create password validation and user existence checks

4. API Endpoints

  • /api/auth/register - User registration
  • /api/auth/login - User login
  • /api/messages - Get message history
  • /api/rooms - Get available rooms
  • /api/rooms/create - Create new room
  • /api/users/online - Get online users

5. Socket.io Integration

  • Set up Socket.io server with CORS configuration
  • Handle user connection and disconnection events
  • Implement real-time message broadcasting
  • Add room joining and leaving functionality
  • Track online users and emit status updates

Phase 2: Frontend Development

1. React App Setup

  • Create Vite React project with TypeScript
  • Install dependencies: socket.io-client, axios, react-router-dom
  • Set up folder structure: components, pages, hooks, utils, types
  • Configure Vite proxy for API calls

2. Authentication Components

  • Create Login component with form validation
  • Create Register component with password confirmation
  • Implement AuthContext for user state management
  • Add protected routes and authentication guards
  • Create token storage and automatic login

3. Chat Interface

  • Build ChatRoom component with message list
  • Create MessageInput component with send functionality
  • Implement UserList component showing online users
  • Add RoomSelector component for switching rooms
  • Create responsive layout with sidebar and main chat area

4. Real-time Features

  • Set up Socket.io client connection
  • Implement message sending and receiving
  • Add typing indicators
  • Show user join/leave notifications
  • Display online/offline status indicators

5. UI/UX Enhancements

  • Add message timestamps and sender information
  • Implement auto-scroll to latest messages
  • Create loading states and error handling
  • Add emoji support and message formatting
  • Implement responsive design for mobile devices

Phase 3: Advanced Features

1. Message Management

  • Message persistence in MongoDB
  • Message history pagination
  • Search functionality within messages
  • Message deletion and editing
  • File and image sharing capabilities

2. Room Features

  • Private messaging between users
  • Room creation and management
  • Room member permissions
  • Room invitation system
  • Public and private room types

3. User Experience

  • User profile management
  • Avatar upload and display
  • Custom themes and dark mode
  • Notification system
  • Sound alerts for new messages

Phase 4: Deployment & Testing

1. Testing

  • Unit tests for API endpoints
  • Integration tests for Socket.io events
  • Frontend component testing
  • End-to-end testing with Cypress

2. Deployment

  • Set up production MongoDB database
  • Deploy backend to Heroku/Railway/DigitalOcean
  • Deploy frontend to Vercel/Netlify
  • Configure environment variables
  • Set up CI/CD pipeline

Technical Requirements

  • Node.js: v18+ for backend runtime
  • MongoDB: v6+ for data persistence
  • React: v18+ with hooks and functional components
  • Socket.io: v4+ for real-time communication
  • JWT: For secure authentication
  • bcryptjs: For password hashing
  • Vite: For fast development and building

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published