Deployment Guide
Relevant source files
The following files were used as context for generating this wiki page:
This guide provides comprehensive instructions for setting up and deploying the E-Commerce-Website-With-Sentiment-Analysis-For-Reviews project. The application is a full-stack e-commerce platform featuring user management, product and order handling, real-time chat, and sentiment analysis of product reviews.
The project is architecturally divided into three main, independently runnable services: a React frontend, a Node.js/Express backend API, and a dedicated Socket.io server for real-time communication. Successful deployment requires configuring and running all three services simultaneously.
Architecture Overview
The system consists of a frontend application, a backend server, and a socket server, which interact with each other, databases, and various external services.
This diagram illustrates the high-level architecture, showing the separation of the frontend, backend, and socket services and their connections to data stores and external APIs.
Sources: README.md
System Requirements
Before starting the installation, ensure your system meets the following requirements.
| Requirement | Details - |
|---|---|
| Node.js | 18.10.0 or higher. - |
| Databases | Running instances of MongoDB and MySQL. - |
- |
| External Accounts & Keys | - Cloudinary account for image storage.
- Stripe account for credit card payments.
- PayPal Developer account for PayPal payments.
- OpenAI API Key for sentiment analysis.
- Google Cloud Translate API Key (optional). |
Sources: README.md:121-129, backend/package.json:6
Installation and Setup
The setup process involves cloning the repository and then installing dependencies and configuring each of the three services separately.
This flowchart outlines the sequential steps for setting up the entire project.
Sources: README.md:131-180
1. Clone Repository
First, clone the project from GitHub.
git clone https://github.com/vophuthinh/E-Commerce-Website-With-Sentiment-Analysis-For-Reviews.git
cd E-Commerce-Website-With-Sentiment-Analysis-For-Reviews
Sources: README.md:132-135
2. Backend Setup
The backend is a Node.js/Express server that handles business logic, API endpoints, and database interactions.
Installation
Navigate to the backend directory and install the required npm packages.
cd backend
npm install
Sources: README.md:137-140, backend/package.json
Environment Configuration
Create a .env file inside the backend/config/ directory. This file stores sensitive information and configuration variables.
| Variable | Description | Example Value |
|---|---|---|
PORT | Port for the backend server. | 8000 |
DB_URI | Connection string for MongoDB. | your_mongodb_connection_string |
DB_HOST | Host for the MySQL database. | localhost |
DB_USER | Username for the MySQL database. | root |
DB_PASSWORD | Password for the MySQL database. | |
DB_NAME | Name of the MySQL database. | new-nodejs |
JWT_SECRET | Secret key for signing JSON Web Tokens. | your_jwt_secret_key |
JWT_EXPIRE | Expiration time for JWT. | 7d |
COOKIE_EXPIRE | Expiration time for cookies. | 5 |
CLOUDINARY_NAME | Your Cloudinary account name. | your_cloudinary_name |
CLOUDINARY_API_KEY | Your Cloudinary API key. | your_cloudinary_api_key |
CLOUDINARY_API_SECRET | Your Cloudinary API secret. | your_cloudinary_api_secret |
STRIPE_SECRET_KEY | Your Stripe secret key. | your_stripe_secret_key |
STRIPE_API_KEY | Your Stripe publishable key. | your_stripe_api_key |
OPENAI_API_KEY | Your OpenAI API key. | your_openai_api_key |
GOOGLE_APPLICATION_CREDENTIALS | Path to Google credentials JSON file. | path_to_google_credentials.json |
FRONTEND_URL | URL of the running frontend application for CORS. | http://localhost:3000 |
Sources: README.md:142-162, backend/app.js:15-18
Backend Middleware Configuration
The backend/app.js file configures several important middleware for security and functionality.
| Middleware | Purpose |
|---|---|
cors | Enables Cross-Origin Resource Sharing for the specified FRONTEND_URL. |
express-rate-limit | Limits repeated requests to public APIs to prevent brute-force attacks. |
helmet | Sets various HTTP headers to secure the Express app. |
express-mongo-sanitize | Sanitizes user-supplied data to prevent NoSQL query injection. |
cookie-parser | Parses Cookie header and populates req.cookies. |
body-parser | Parses incoming request bodies. |
Sources: backend/app.js:4-35
Running the Backend
Start the backend server using one of the following commands. The server will run on the port specified in your .env file (default: 8000).
# For development with nodemon
npm run dev
# For production
npm start
Sources: README.md:164-169, backend/package.json:9-10
3. Frontend Setup
The frontend is a React application built with Create React App.
Installation
Navigate to the frontend directory and install dependencies.
cd frontend
npm install
Sources: README.md:171-174, frontend/package.json
Environment Configuration
Create a .env file in the root of the frontend/ directory to connect it with the backend and socket servers.
| Variable | Description | Example Value |
|---|---|---|
REACT_APP_SERVER_URL | URL of the running backend server. | http://localhost:8000 |
REACT_APP_SOCKET_URL | URL of the running socket server. | http://localhost:4000 |
REACT_APP_STRIPE_PUBLISHABLE_KEY | Your Stripe publishable key for the client. | your_stripe_publishable_key |
Sources: README.md:176-181
Running the Frontend
Start the React development server. It will be accessible at http://localhost:3000.
npm start
Sources: README.md:183-186, frontend/package.json:44
4. Socket Server Setup
A separate Node.js server manages real-time chat functionality using Socket.io.
Installation
Navigate to the socket directory and install dependencies.
cd socket
npm install
Sources: README.md:188-191
Environment Configuration
Create a .env file in the socket/ directory.
| Variable | Description | Example Value |
|---|---|---|
PORT | Port for the socket.io server. | 4000 |
Sources: README.md:193-197
Running the Socket Server
Start the socket server. It will run on port 4000 by default.
npm start
Sources: README.md:199-202
Running the Project
To run the full application, you must start all three servers concurrently in separate terminal windows.
- Terminal 1 (Backend):
cd backend npm start - Terminal 2 (Frontend):
cd frontend npm start - Terminal 3 (Socket Server):
cd socket npm start
Once all services are running, you can access the application by navigating to http://localhost:3000 in your web browser.
Sources: README.md:204-220