What Chatter IS? Chatter is a focused communication tool for organizations. It's built to facilitate efficient and effective communication within a professional setting. When a new member joins your company, they get a Chatter account to connect and collaborate with their colleagues. It's about streamlining workflows, sharing updates, and fostering a sense of community within the workplace.
What Chatter is NOT? Chatter is not your typical social media platform or instant messaging app. It's not about building a network of friends, sending friend requests, or accumulating followers. It's not designed for casual conversations or social interactions with people outside your organization.
- Secure registration form with unique email and username creation.
- Seamless transition from registration to sign-in.
- Access to all members of the organization.
- Responsive design that adapts to different screen sizes.
- Full CRUD (Create, Read, Update, Delete) capabilities for messages.
- Real-time tracking and display of online/offline status for users.
- Four color themes: Light Blue, Dark, Pink, and Orange.
- Next.js (Front/Server Side).
- Tailwind CSS (Styling).
- Node.js (Back-end runtime).
- Express.js (API framework).
- MongoDB (Database).
- Socket-IO (WebSocket Connection).
- NextAuth.js (Authentication).
- Clone this repository.
npm ito install dependencies.- Create a
.envfile based on the provided.env.exampletemplate. npm run startto run application.
The Chatter application utilizes a MongoDB database to store and manage user data and messages. The database chatter contains the following collections:
This collection stores temporary user data during the registration process. New users create an account using this collection. After a successful registration, the following fields are transferred to the users collection:
fullnameusernameemailphonepasswordHash(A hashed version of the user's password)
This collection stores the permanent user data for registered and active users. It contains the following fields:
fullnameusernameimageemailphonepasswordHash(A hashed version of the user's password)timestamps(Timestamps for creation and updates)
This collection stores the chat messages exchanged between users. It contains the following fields:
sender(User ID or other identifier of the message sender)senderUsernamerecipientUsernamecontent(The message text)timestampimage(Optional image associated with the message)timestamps(Timestamps for creation and updates)
The users collection represents the core entity in the application. The messages collection has a relationship with the users collection through the sender field and through senderUsername and recipientUsername for easier querying. This allows the application to retrieve messages associated with specific users. The relationship is conceptually similar to a one-to-many relationship in a relational database, where one user can send multiple messages. The registrations collection serves as a temporary staging area, and its data gets transferred to users, so it does not have a direct relationship with messages.
This structure enables the application to manage user registration, authentication, and chat functionality. New users are first created in the registrations collection. Upon successful registration, their information is moved to the users collection, granting them access to the application. Users can then send messages to each other, which are stored in the messages collection.
This application uses NextAuth.js for authentication. NextAuth.js is a complete open-source authentication solution for Next.js applications. It provides a simple and flexible way to implement various authentication strategies, including credentials-based authentication, social logins, and more.
The application utilizes the Credentials Provider from NextAuth.js to enable users to log in with their username and password credentials. This provider allows you to define your own authentication logic, giving you full control over the process.
- User enters credentials: The user enters their username and password in the sign-in form.
- Credentials are sent to the server: The frontend sends a POST request to the
/api/auth/[...nextauth]/route.jsendpoint with the user's credentials. - NextAuth.js handles authentication: NextAuth.js intercepts this request and uses the
authorizefunction defined in your NextAuth.js configuration to verify the credentials. - Credentials are verified: The
authorizefunction queries yourMongoDBdatabase to find the user with the given username. If the user is found, it compares the provided password with the stored password hash using bcrypt. - Session is created: If the credentials are valid, NextAuth.js creates a new session for the user and stores it securely using JWT (JSON Web Tokens).
- User is redirected: The user is redirected to the chat interface, where they can now access protected routes and features.
useSessionhook: This hook is used inChatApp.jsx,ChatFeed.jsx, andChatList.jsxto access the user's session information, including their authentication status and user details. Thedataproperty of theuseSessionhook returns the current session object, which includes theuserproperty if the user is authenticated.status === "authenticated"check: InChatList.jsx, thestatus === "authenticated"check is used to determine if the user is currently logged in. If the user is authenticated, thesession?.userproperty will be available, and you can access the user's information.SignOutIcon: This icon in theChatSettings.jsxhandles the sign-out functionality. It uses thesignOutfunction fromnext-auth/reactto log out the user and redirect them to the sign-in page.
To make session data accessible throughout the application, we wrap the root layout with the SessionProvider component from next-auth/react.
This component acts as a wrapper for the SessionProvider. It receives the children prop, which represents the rest of the application's UI, and wraps it with the SessionProvider.
This file defines the root layout of the application. It imports the Provider component and wraps the entire application's content ({children}) with it. Wrapping the application with SessionProvider makes the session data accessible to any component that needs it, without having to manually pass it down as props.
NextAuth.js handles session management automatically, including creating, updating, and expiring sessions. This simplifies the authentication process and reduces boilerplate code.The SessionProvider can be customized with various options, such as the session strategy (JWT, database, etc.) and cookie settings.
This document outlines the Node Package Manager (NPM) dependencies used in this project.
-
mongodb: The official MongoDB driver for Node.js:
npm i mongodb
-
mongoose: An Object Data Modeling (ODM) library for MongoDB and Node.js:
npm i mongoose
-
bcrypt: Used for securely hashing passwords:
npm i bcrypt
-
socket-io: Enables real-time, bidirectional communication between web clients and servers:
npm i socket.io
-
socket.io-client: The client-side library for socket-io:
npm i socket.io-client
-
next-auth: Provides authentication for Next.js applications:
npm i next-auth
-
express.js: Simplifies the process of building web applications and APIs by providing tools for routing, middleware (functions that can access and modify requests and responses), and handling HTTP requests and responses.
npm i express
-
cors: Controls how a web page from one origin (domain, protocol, port) can access resources from another origin. CORS helps prevent potential malicious activity by restricting cross-origin requests unless explicitly allowed by the server.
npm i cors
-
dotenv: Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env.
npm i dotenv
-
react-toastify: Provides notification functionality (e.g., toast messages) for user feedback.
npm i react-toastify
-
tsparticles & tsparticles/react : are npm packages that work together to enable you to create beautiful particle animations in your applications. tsparticles is the core library that powers the particle animations. tsparticles/react is a React-specific wrapper that makes it simple to use tsParticles within your applications.
npm i @tsparticles/react
npm i tsparticles
-
concurrently : A utility for running multiple commands concurrently. Install it for development purposes with the -D flag:
npm i concurrently -D
-
tailwindcss: A utility-first CSS framework for rapidly building custom user interfaces.
npm i tailwindcss
This project is licensed under the MIT License - see the See the LICENSE file for details file for details.
