Skip to content

Latest commit

Β 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

HiChat! πŸ’¬

A modern, real-time chat application built with the MERN stack, featuring secure authentication, instant messaging, and a beautiful UI.

Node.js React MongoDB Socket.io

🌐 My Live Website

Try HiChat Live πŸš€

✨ Features

  • πŸ” Secure Authentication - JWT-based auth with bcrypt password hashing
  • πŸ’¬ Real-time Messaging - Instant message delivery with Socket.io
  • πŸ‘€ User Profiles - Customizable profile pictures with Cloudinary integration
  • 🎨 Modern UI - Beautiful interface with Tailwind CSS and DaisyUI
  • πŸ”’ Rate Limiting - Arcjet protection against brute force attacks
  • πŸ“§ Email Integration - Welcome emails via Resend( Only for testing purpose, not active in live website )
  • 🌐 Responsive Design - Works seamlessly on desktop and mobile
  • πŸš€ Production Ready - Optimized builds and deployment configuration

πŸ› οΈ Tech Stack

Frontend

  • React 19 - Latest React with modern hooks
  • Vite - Lightning-fast build tool
  • Zustand - Lightweight state management
  • Tailwind CSS - Utility-first CSS framework
  • DaisyUI - Beautiful UI components
  • Axios - HTTP client
  • React Router - Client-side routing
  • Socket.io Client - Real-time communication
  • Lucide React - Beautiful icons

Backend

  • Node.js 20+ - JavaScript runtime
  • Express - Fast, minimalist web framework
  • MongoDB - NoSQL database
  • Mongoose - MongoDB object modeling
  • Socket.io - Real-time bidirectional communication
  • JWT - JSON Web Tokens for authentication
  • Bcrypt - Password hashing
  • Cloudinary - Image upload and management
  • Resend - Email service
  • Arcjet - Security and rate limiting
  • CORS - Cross-origin resource sharing

πŸ“ Project Structure

HiChat/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/      # Route controllers
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.controller.js
β”‚   β”‚   β”‚   └── message.controller.js
β”‚   β”‚   β”œβ”€β”€ emails/            # Email templates and handlers
β”‚   β”‚   β”‚   β”œβ”€β”€ emailHandlers.js
β”‚   β”‚   β”‚   └── emailTemplates.js
β”‚   β”‚   β”œβ”€β”€ lib/               # Utility libraries
β”‚   β”‚   β”‚   β”œβ”€β”€ arcjet.js
β”‚   β”‚   β”‚   β”œβ”€β”€ cloudinary.js
β”‚   β”‚   β”‚   β”œβ”€β”€ db.js
β”‚   β”‚   β”‚   β”œβ”€β”€ env.js
β”‚   β”‚   β”‚   β”œβ”€β”€ resend.js
β”‚   β”‚   β”‚   β”œβ”€β”€ socket.js
β”‚   β”‚   β”‚   └── utils.js
β”‚   β”‚   β”œβ”€β”€ middleware/        # Custom middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ arcjet.middleware.js
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.middleware.js
β”‚   β”‚   β”‚   └── socket.auth.middleware.js
β”‚   β”‚   β”œβ”€β”€ models/            # Database models
β”‚   β”‚   β”‚   β”œβ”€β”€ Message.js
β”‚   β”‚   β”‚   └── User.js
β”‚   β”‚   β”œβ”€β”€ routes/            # API routes
β”‚   β”‚   β”‚   β”œβ”€β”€ auth.route.js
β”‚   β”‚   β”‚   └── message.route.js
β”‚   β”‚   └── server.js          # Entry point
β”‚   └── package.json
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ public/
β”‚   β”‚   └── sounds/            # Notification sounds
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/        # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ ActiveTabSwitch.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ BorderAnimatedContainer.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatContainer.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatHeader.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatsList.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ContactList.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MessageInput.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ MessagesLoadingSkeleton.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ NoChatHistoryPlaceholder.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ NoChatsFound.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ NoConversationPlaceholder.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ PageLoader.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ProfileHeader.jsx
β”‚   β”‚   β”‚   └── UsersLoadingSkeleton.jsx
β”‚   β”‚   β”œβ”€β”€ hooks/             # Custom React hooks
β”‚   β”‚   β”‚   └── useKeyboardSound.js
β”‚   β”‚   β”œβ”€β”€ lib/               # Utilities
β”‚   β”‚   β”‚   └── axios.js
β”‚   β”‚   β”œβ”€β”€ pages/             # Page components
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatPage.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx
β”‚   β”‚   β”‚   └── SignUpPage.jsx
β”‚   β”‚   β”œβ”€β”€ store/             # Zustand stores
β”‚   β”‚   β”‚   β”œβ”€β”€ useAuthStore.js
β”‚   β”‚   β”‚   └── useChatStore.js
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   β”œβ”€β”€ main.jsx
β”‚   β”‚   └── index.css
β”‚   β”œβ”€β”€ index.html
β”‚   β”œβ”€β”€ vite.config.js
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── package.json
β”‚
β”œβ”€β”€ package.json               # Root package.json
└── README.md

πŸš€ Getting Started(To setup Locally)

Prerequisites

  • Node.js 20 or higher
  • MongoDB database (local or MongoDB Atlas)
  • Cloudinary account (for image uploads)
  • Resend account (for emails)
  • Arcjet account (for security)

Environment Variables

Create .env file in the backend directory:

# Server Configuration
NODE_ENV=development
PORT=3000
CLIENT_URL=http://localhost:5173

# Database
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/hichat?retryWrites=true&w=majority

# JWT
JWT_SECRET=your-super-secret-jwt-key-here

# Cloudinary
CLOUDINARY_CLOUD_NAME=your-cloud-name
CLOUDINARY_API_KEY=your-api-key
CLOUDINARY_API_SECRET=your-api-secret

# Resend Email
RESEND_API_KEY=your-resend-api-key
EMAIL_FROM=onboarding@resend.dev
EMAIL_FROM_NAME="Your Name"

# Arcjet Security
ARCJET_KEY=your-arcjet-key
ARCJET_ENV=development

Note: If using Postman for API testing, add "POSTMAN" to the Allow category in your arcjet.js to prevent it from being identified as a bot during development.

Installation

  1. Clone the repository
git clone https://github.com/yourusername/hichat.git
cd hichat
  1. Install dependencies
# Install backend dependencies
cd backend
npm install

# Install frontend dependencies
cd ../frontend
npm install
  1. Set up environment variables
# Create .env file in backend directory
cd backend
cp .env.example .env
# Edit .env with your credentials
  1. Start MongoDB
# If using local MongoDB
mongod

# Or use MongoDB Atlas (cloud)
  1. Run the application

Development mode (separate terminals):

# Terminal 1 - Backend
cd backend
npm run dev

# Terminal 2 - Frontend
cd frontend
npm run dev

Production mode:

# Build frontend
cd frontend
npm run build

# Start backend (serves frontend)
cd ../backend
npm start

πŸ“ API Endpoints

Authentication

  • POST /api/auth/signup - Register new user
  • POST /api/auth/login - Login user
  • POST /api/auth/logout - Logout user
  • GET /api/auth/check - Check authentication status
  • PUT /api/auth/update-profile - Update user profile

Messages

  • GET /api/messages/contacts - Get all contacts
  • GET /api/messages/chats - Get chat partners
  • GET /api/messages/:id - Get messages with specific user
  • POST /api/messages/send/:id - Send message to user

WebSocket Events

  • connection - Client connects
  • disconnect - Client disconnects
  • newMessage - New message received
  • getOnlineUsers - Get list of online users

πŸ”’ Security Features

  • JWT Authentication - Secure token-based authentication
  • Password Hashing - Bcrypt with salt rounds
  • Rate Limiting - Arcjet protection against abuse
  • Input Validation - Sanitized and validated inputs
  • HTTP-only Cookies - Secure token storage
  • CORS Protection - Configured CORS policies
  • XSS Prevention - Input sanitization
  • MongoDB Injection Protection - Mongoose schema validation

🀝 Contributing

Contributions are welcome! Please follow these steps:

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

πŸ“„ License

This project is licensed under the MIT License.

πŸ‘¨β€πŸ’» Author

Your Name

πŸ“§ Support

For support, email dhruvchoudhay38@gmail.com or open an issue on GitHub.


Made with ❀️ by Dhruv Choudhary

About

Real-time chat application built with MERN stack, Socket.io, JWT authentication, and Arcjet security. Features instant messaging, profile customization, and responsive design.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages