- Introduction
- Directory Structure
- Prerequisites
- Installation
- Running the Project
- Frontend
- Backend
- Contributing
- License
This project is a Chat application consisting of a frontend built with React and a backend built using Node.js and MongoDB. The application allows users to chat between users and agents.
The project has the following directory structure:
.
├── frontend
│ ├── public
│ ├── src
│ ├── package.json
│ └── ...
├── backend
│ ├── public
│ ├── src
│ ├── index.ts
│ ├── package.json
│ └── ...
└── README.md
- Node.js (version 14.x or higher)
- npm (version 6.x or higher) or yarn
- MongoDB (local or Atlas)
- Redis
-
Install dependencies for both frontend and backend:
-
Frontend:
cd frontend npm install -
Backend:
cd ../backend npm install
-
To deploy the frontend , follow these steps:
- Set the
baseUrlof the frontend project. For example, if the base URL ishttps://www.alegralabs.com/ANY_FOLDER_NAME, then thebaseUrlwill beANY_FOLDER_NAME. - Add
base: "/ANY_FOLDER_NAME"in thevite.config.tsfile and in./src/config.tsx, add the basename to the Router tag:<Router basename='/ANY_FOLDER_NAME'>. - Open the terminal and run
npm run buildto build the app for production, which will create thedistfolder. - Copy the contents of the
distfolder to theANY_FOLDER_NAMEor the desired folder on the server.
To update the icon, title, and other metadata of the application, go to the ./src/config.tsx file in the frontend folder and make the necessary changes.
The backend is built using Node.js with Express, Redis, and MongoDB.
In the backend directory:
- Open the terminal and run the command
npx tsc. This will create adistfolder containing all the compiled files. - Copy the
.envfile to thedistfolder. - Copy the entire backend folder to the server or use
git pullif the code is updated in GitHub. - (Optional) Depending on the server and the type of deployment, run the
NAME.servicefile. Note: use Node version16.20.2.
Create a .env file in the backend directory and add the following variables:
EMAIL_PASSWORD=your-gmail-app-password-for-sending-chat-transcript
EMAIL_ID=your-email-for-sending-chat-transcript
DB=chats
MONGO_URI=your-mongodb-uri
ACCESS_TOKEN_SECRET=your-accesstoken-secret-key
ACCESS_TOKEN_EXPIRY=1h
REFRESH_TOKEN_SECRET=your-refreshtoken-secret-key
REFRESH_TOKEN_EXPIRY=12h
SOCKET_AUTH_CODE=your-secret-code-distinguishing-between-users-and-agents
FILE_URL="your-path-to-the-stored-files"
PORT=5005
The backend provides the following API endpoints:
POST /api/user/login- User login.POST /api/admin/login- Agent/Admin login.POST /api/admin/register- New Agent/Admin registration.GET /api/logout- User/Admin logout.POST /api/refresh-token- Refresh access token.POST /api/send-transcript- Send chat transcript.POST /api/upload- Upload files.GET /api/logs- Check console logs of the file.