This is the backend server for the E-Commerce Trust Score Chrome Extension, which provides trust scores, feedback, and reviews for e-commerce websites. The server is built using Node.js, Express, and MongoDB, and integrates with OpenAI for AI-generated feedback.
- Website Verification: Check if a website is verified and retrieve its trust score.
- Feedback Management: Add user feedback and calculate ratings using Bayesian and time-decay algorithms.
- AI-Generated Feedback: Use OpenAI to analyze review messages and categorize feedback.
- Error Handling: Comprehensive error handling for validation, database, and runtime errors.
.env
.env.example
.gitignore
.prettierrc.json
eslint.config.mjs
package.json
README.md
src/
app.ts
server.ts
app/
configaration/
index.ts
errors/
AppError.ts
handleCastError.ts
handleDuplicateError.ts
handleValidationError.ts
handleZodError.ts
interface/
error.ts
index.d.ts
website.ts
middlewares/
globalErrorHandler.ts
notFound.ts
validateRequests.ts
modules/
verifiedWebsite/
verifiedwebsite.controller.ts
verifiedwebsite.route.ts
verifiedwebsite.services.ts
verifiedwebsite.model.ts
verifiedwebsite.interface.ts
verifiedWebsite.consts.ts
routes/
index.ts
utils/
sendResponse.ts
extractValues.ts
catchAsync.ts
calculateRating.ts
-
Clone the repository:
git clone https://github.com/wolfiee42/E-CommerceTrustScoreChromeExtensionServer.git cd E-CommerceTrustScoreChromeExtensionServer -
Install dependencies:
npm install
-
Create a
.envfile in the root directory and configure the following variables:NODE_ENVIRONMENT=development PORT=8080 DATABASE_URL=<your_mongodb_connection_string> OPENAI_API_KEY=<your_openai_api_key>
-
Build the project:
npm run build
-
Start the server:
- Development mode:
npm run dev
- Production mode:
npm start
- Development mode:
- URL:
/api/v1/website/check - Method:
GET - Query Parameters:
name(string): The website URL to check.
- Response:
{ "success": true, "message": "The website has been successfully retrieved.", "data": { "website": { "verified": true, "rating": 4.5 }, "recentReviews": [...], "mostCommonFeedback": [...] } }
- URL:
/api/v1/website/review - Method:
POST - Body:
{ "reviewMessage": "The website is beautiful, but the quality of their clothes is not good.", "siteId": "677bdcdad3ad95823e4eda0b", "feedback": { "ProductQuality": [{ "name": "Durability", "baseRating": 4 }], "CustomerServices": [{ "name": "Responsiveness", "baseRating": 5 }], "PlatformExperience": [{ "name": "Ease of Use", "baseRating": 5 }] } } - Response:
{ "success": true, "message": "The website feedback has been successfully retrieved.", "data": { ... } }
- URL:
/api/v1/website/ai-generated-feedback/:id - Method:
GET - Response:
{ "success": true, "message": "The website feedback has been successfully retrieved.", "data": { "ProductQuality": [...], "CustomerServices": [...], "PlatformExperience": [...] } }
- Node.js: Backend runtime environment.
- Express: Web framework for building APIs.
- MongoDB: NoSQL database for storing website, feedback, and review data.
- OpenAI: AI integration for analyzing review messages.
- TypeScript: Strongly typed JavaScript for better code quality.
- Zod: Schema validation for request payloads.
- Day.js: Lightweight library for date manipulation.
- Start Development Server:
npm run dev
- Build Project:
npm run build
- Run Linter:
npm run lint
- Fix Linter Issues:
npm run lint:fix
- Format Code:
npm run format
The server includes a global error handler to manage various types of errors:
- Validation Errors: Handled using
Zodand Mongoose validation. - Duplicate Errors: Managed for unique constraints in MongoDB.
- Unhandled Rejections: Gracefully shuts down the server.
- Uncaught Exceptions: Ensures the server exits safely.
| Variable | Description |
|---|---|
NODE_ENVIRONMENT |
Application environment (e.g., development, production). |
PORT |
Port number for the server. |
DATABASE_URL |
MongoDB connection string. |
OPENAI_API_KEY |
API key for OpenAI integration. |
This project is licensed under the MIT License.
Developed by Saif.