This is the frontend client for the real-time chat application. It provides a modern, responsive, and soft user interface for seamless communication.
Live URL: https://fastidious-shortbread-79399d.netlify.app
- React: UI Library for building components and managing application state.
- Vite: Next Generation Frontend Tooling for fast development and optimized builds.
- Socket.io-client: Enables real-time, bi-directional communication with the backend websocket server.
- Axios: Promise-based HTTP client for making API requests.
- React Hot Toast: Lightweight library for elegant and responsive toast notifications.
- Lucide React: Beautiful and consistent iconography.
- Date-fns: Modern JavaScript date utility library.
Follow these steps to set up and run the client locally.
Ensure you have Node.js installed. In the client directory, run:
npm installCreate a .env file in the root of the client directory to store your environment variables (e.g., API URL, Socket URL). Example:
VITE_API_URL=http://localhost:5000/api
VITE_SOCKET_URL=http://localhost:5000To start the local development server with hot-module replacement (HMR), run:
npm run devTo create an optimized production build, run:
npm run buildThe output will be placed in the dist directory, ready to be deployed.
To preview the production build locally before deployment, run:
npm run previewThe backend of this application is built with scalability and real-time performance in mind. Here is an overview of the server-side architecture and technology stack:
- Node.js: JavaScript runtime built on Chrome's V8 JavaScript engine.
- Express.js: Fast, unopinionated, minimalist web framework for building the REST API.
- MongoDB & Mongoose: NoSQL database for persistent data storage (users, chats, messages) and ODM for elegant data modeling.
- Socket.io: Enables robust, bi-directional, real-time event-based communication between the server and connected clients.
- Redis (via
ioredis): Used primarily as a Pub/Sub adapter for Socket.io. This is a critical component for horizontal scalability, ensuring that when the application runs on multiple instances, messages broadcasted from one instance reach clients connected to a different instance.
- JSON Web Tokens (JWT): Used for stateless, secure user authentication and authorization.
- Bcrypt.js: Library used for hashing passwords before storing them in the database.
- CORS: Cross-Origin Resource Sharing middleware for restricting API access to authorized domains.
- Cookie Parser: Middleware to parse cookies attached to the client request object.
- REST API (Express): Handles standard CRUD operations such as user registration, login (JWT issuing), fetching historical messages, and retrieving the list of available rooms/users.
- WebSocket Layer (Socket.io): Handles real-time events. When a user connects, they authenticate and join specific Socket rooms corresponding to their chats.
- Message Broadcast (Redis): When a user sends a message, it is emitted to the server. The server saves it to MongoDB and then broadcasts it to the relevant Socket room. If the server is scaled horizontally, Redis Pub/Sub ensures the message is propagated to all instances so all users in the room receive the update instantly.