OpenChat is a modern, full-stack real-time chat application designed to facilitate seamless communication between users. Built with a robust MERN (MongoDB, Express.js, React, Node.js) stack and enhanced with Socket.IO for instant messaging, OpenChat provides a dynamic and interactive user experience.
OpenChat offers a comprehensive set of features for a rich messaging experience:
- Secure User Authentication: Users can securely register and log in using JWT (JSON Web Tokens) for session management.
- Real-time Messaging: Leverage Socket.IO for instant, bidirectional communication, ensuring messages are delivered and received in real-time.
- Intuitive Conversation Management: Easily create new conversations, view existing chat histories, and manage participants.
- User Discovery: Browse a list of registered users to initiate new chats.
- Responsive User Interface: A clean and responsive design built with React, providing a smooth experience across various devices.
This project is built using a combination of powerful and modern technologies:
- React: A declarative, component-based JavaScript library for building dynamic user interfaces.
- React Router DOM: For efficient client-side routing and navigation within the single-page application.
- Socket.IO Client: The client-side library for establishing real-time, event-driven communication with the backend.
- Font Awesome: Provides a comprehensive set of scalable vector icons that can be customized with CSS.
- Node.js: A powerful JavaScript runtime environment for building scalable network applications.
- Express.js: A fast, unopinionated, and minimalist web framework for Node.js, used for building robust APIs.
- MongoDB: A flexible NoSQL document database, ideal for handling large volumes of unstructured data.
- Mongoose: An elegant MongoDB object modeling tool for Node.js, simplifying data interaction.
- Socket.IO: The server-side library enabling real-time, low-latency communication between the server and connected clients.
- JSON Web Tokens (JWT): A compact, URL-safe means of representing claims to be transferred between two parties, used for secure authentication.
- Bcrypt: A library for hashing passwords, ensuring secure storage of user credentials.
- CORS: Middleware to enable Cross-Origin Resource Sharing, allowing the frontend to communicate with the backend.
- Dotenv: A module that loads environment variables from a
.envfile, keeping sensitive configuration separate from the codebase.
To get a copy of OpenChat up and running on your local machine, follow these steps.
Ensure you have the following software installed:
- Node.js: (LTS version recommended) - Download from nodejs.org
- npm: (Comes bundled with Node.js)
- MongoDB: A running instance of MongoDB (local or cloud-based like MongoDB Atlas). - Download from mongodb.com
-
Clone the repository:
git clone https://github.com/your-username/OpenChat.git cd OpenChat(Remember to replace
your-usernamewith the actual GitHub username if you fork this project.) -
Install Backend Dependencies: Navigate to the
backenddirectory and install the required Node.js packages:cd backend npm install -
Install Frontend Dependencies: Navigate to the
frontend/chat-appdirectory and install the required Node.js packages:cd ../frontend/chat-app npm install
-
Backend Environment Variables: Create a
.envfile in thebackenddirectory with the following content:MONGO_URI=your_mongodb_connection_string JWT_SECRET=your_jwt_secret_key PORT=5000
MONGO_URI: Replace with your MongoDB connection URI (e.g.,mongodb://localhost:27017/openchatfor a local instance, or your MongoDB Atlas connection string).JWT_SECRET: Provide a strong, random string for JWT token signing. You can generate one online or use a tool.PORT: The port on which the backend server will run. Default is5000.
-
Frontend Environment Variables: Create a
.envfile in thefrontend/chat-appdirectory with the following content:REACT_APP_BACKEND_URL=http://localhost:5000
REACT_APP_BACKEND_URL: This should match thePORTyou set for your backend server.
Once all dependencies are installed and environment variables are configured, you can start the application from the project root:
npm startThis command uses concurrently to start both the backend server and the React development server simultaneously.
- The backend server will be accessible at
http://localhost:5000(or your configuredPORT). - The frontend React application will typically open in your browser at
http://localhost:3000.
The OpenChat backend exposes a set of RESTful API endpoints for managing users, conversations, and messages.
POST /auth/signup: Register a new user account.POST /auth/login: Authenticate user credentials and receive a JSON Web Token.
POST /conversation/:userId: Create a new conversation, typically with another user.GET /conversation/:conversationId: Retrieve details and messages of a specific conversation.DELETE /conversation/:conversationId: Delete an existing conversation.
POST /message/:conversationId: Send a new message within a specified conversation.GET /message/:conversationId: Fetch all messages belonging to a particular conversation.
GET /users/: Retrieve a list of all registered users in the system.
OpenChat/
├── backend/ # Node.js/Express.js backend services and API
│ ├── .env # Environment variables for backend
│ ├── server.js # Main entry point for the backend server
│ ├── middleware/ # Express middleware functions (e.g., authentication, error handling)
│ ├── models/ # Mongoose schemas defining MongoDB document structures
│ └── routes/ # API route definitions and their respective handlers
├── frontend/
│ └── chat-app/ # React single-page application (SPA)
│ ├── public/ # Static assets served directly by the web server
│ ├── src/ # Source code for the React application
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Top-level components representing different views/pages
│ │ └── styles/ # CSS stylesheets for styling components and pages
│ └── package.json # Frontend project metadata, dependencies, and scripts
├── package.json # Root project dependencies and scripts (for concurrently)
├── .gitignore # Specifies intentionally untracked files to ignore
├── plan.js # Development notes or planning details
├── request.http # HTTP client request definitions (for testing APIs)
└── README.md # Project documentation (this file)
Contributions are welcome! If you have suggestions for improvements or find a bug, please open an issue or submit a pull request.
This project is licensed under the MIT License - see the LICENSE file for details. (Note: A LICENSE file is not included in the current directory structure, you may want to add one.)