A modern, real-time chat application built with the MERN stack, featuring secure authentication, instant messaging, and a beautiful UI.
Try HiChat Live π
- π 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
- 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
- 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
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
- Node.js 20 or higher
- MongoDB database (local or MongoDB Atlas)
- Cloudinary account (for image uploads)
- Resend account (for emails)
- Arcjet account (for security)
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=developmentNote: 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.
- Clone the repository
git clone https://github.com/yourusername/hichat.git
cd hichat- Install dependencies
# Install backend dependencies
cd backend
npm install
# Install frontend dependencies
cd ../frontend
npm install- Set up environment variables
# Create .env file in backend directory
cd backend
cp .env.example .env
# Edit .env with your credentials- Start MongoDB
# If using local MongoDB
mongod
# Or use MongoDB Atlas (cloud)- Run the application
Development mode (separate terminals):
# Terminal 1 - Backend
cd backend
npm run dev
# Terminal 2 - Frontend
cd frontend
npm run devProduction mode:
# Build frontend
cd frontend
npm run build
# Start backend (serves frontend)
cd ../backend
npm startPOST /api/auth/signup- Register new userPOST /api/auth/login- Login userPOST /api/auth/logout- Logout userGET /api/auth/check- Check authentication statusPUT /api/auth/update-profile- Update user profile
GET /api/messages/contacts- Get all contactsGET /api/messages/chats- Get chat partnersGET /api/messages/:id- Get messages with specific userPOST /api/messages/send/:id- Send message to user
connection- Client connectsdisconnect- Client disconnectsnewMessage- New message receivedgetOnlineUsers- Get list of online users
- 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
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License.
Your Name
- GitHub: @dhruv-38
- LinkedIn: Dhruv Choudhary
For support, email dhruvchoudhay38@gmail.com or open an issue on GitHub.
Made with β€οΈ by Dhruv Choudhary