A modern real-time chat application built with React, Node.js, and Socket.IO. This project provides a WhatsApp-like experience with user authentication, real-time messaging, and user management features.
- Real-time messaging with Socket.IO
- User authentication with JWT tokens
- User registration and login with email verification
- User profile management with avatar upload
- User search functionality
- Online/offline status tracking
- Typing indicators in real-time
- Emoji picker for message composition
- Responsive design for desktop and mobile
- Secure authentication with access and refresh tokens
- File upload for user avatars
- Email verification for new accounts
- CORS configuration for cross-origin requests
- Error handling with custom API errors
- Input validation with express-validator
- State management with Zustand
- React 18 - UI framework
- TypeScript - Type safety
- Vite - Build tool and dev server
- React Router DOM - Client-side routing
- Socket.IO Client - Real-time communication
- Axios - HTTP client
- Zustand - State management
- SCSS - Styling with CSS modules
- Emoji Picker React - Emoji selection
- React Icons - Icon library
- Node.js - Runtime environment
- Express.js - Web framework
- Socket.IO - Real-time WebSocket server
- MongoDB - Database
- Mongoose - ODM for MongoDB
- JWT - Authentication tokens
- bcryptjs - Password hashing
- Multer - File upload handling
- Nodemailer - Email sending
- Express Validator - Input validation
- CORS - Cross-origin resource sharing
chat/
βββ client/ # Frontend application
β βββ src/
β β βββ components/ # React components
β β βββ store/ # Zustand stores
β β βββ services/ # API services
β β βββ models/ # TypeScript interfaces
β β βββ assets/ # Icons and images
β β βββ UI/ # Reusable UI components
β βββ package.json
βββ server/ # Backend application
β βββ controllers/ # Route controllers
β βββ routes/ # API routes
β βββ models/ # Database models
β βββ service/ # Business logic
β βββ middlewares/ # Express middlewares
β βββ package.json
βββ README.md
- Node.js (v16 or higher)
- MongoDB database
- SMTP server for email verification
-
Clone the repository
git clone <repository-url> cd chat
-
Install dependencies
# Install frontend dependencies cd client npm install # Install backend dependencies cd ../server npm install
-
Environment Setup
β οΈ SECURITY WARNING: Never commit.envfiles to version control. Use.env.examplefiles as templates.Create
.envfiles in bothclient/andserver/directories by copying the example files:# Copy example files cp server/.env.example server/.env cp client/.env.example client/.envServer (.env) - Update with your actual values:
NODE_ENV=development VITE_DB_URL=mongodb://localhost:27017/chat VITE_CLIENT_URL=http://localhost:5173 VITE_PORT=5001 VITE_SECRET_JWT_ACCESS_CODE=your_access_secret VITE_SECRET_JWT_REFRESH_CODE=your_refresh_secret VITE_SMTP_HOST=smtp.gmail.com VITE_SMTP_PORT=587 VITE_SMTP_USER=your_email@gmail.com VITE_SMTP_PASSWORD=your_app_password
Client (.env) - Update with your actual values:
VITE_API_URL=http://localhost:5001 VITE_SOCKET_URL=http://localhost:5001
-
Start the development servers
Backend
cd server npm run devFrontend
cd client npm run dev -
Access the application
- Frontend: http://localhost:5173
- Backend API: http://localhost:5001
Register a new user
{
"username": "string",
"email": "string",
"password": "string"
}Login user
{
"email": "string",
"password": "string"
}Logout user (requires authentication)
Refresh access token (requires refresh token in cookies)
Activate user account via email link
Get all users (requires authentication)
Find user by username (requires authentication)
Add user to friends list (requires authentication)
Update user profile (requires authentication)
Delete user account (requires authentication)
Get all messages (requires authentication)
Create new message (requires authentication)
{
"text": "string"
}Update message (requires authentication)
Delete message (requires authentication)
Frontend (client/)
npm run dev- Start development servernpm run build- Build for productionnpm run preview- Preview production build
Backend (server/)
npm run dev- Start development server with nodemonnpm run build- Build TypeScript to JavaScriptnpm start- Start production servernpm run prod- Build and start production
- TypeScript for type safety
- ESLint for code linting
- Prettier for code formatting
- SCSS modules for styling
This project is licensed under the ISC License.
Created by betterhell
Note: Make sure to configure your MongoDB database and SMTP settings before running the application in production.