Skip to main content
Long Tran
💬
0 discussions

Transportation Server

I. Introduction

The Transportation Server is a critical component of the Qranty system, responsible for managing data flow between different components. It serves as a central hub that handles API requests from both the Admin Site and Client Site, interacts with the Primary Database to store and retrieve data, interfaces with the Queue based on Redis for managing tasks, communicates with the QR Processing Server for generating QR codes, and connects with third-party services and CRM systems via API to ensure seamless integration and data synchronization.

II. Packages

1. Dependencies

Package NameDescriptionLinkVersion
@shortcm/qr-imageQR Code image generation library@shortcm/qr-image^9.0.4
adm-zipA Javascript implementation of zip for nodejsadm-zip^0.5.12
axiosPromise based HTTP client for the browser and node.jsaxios^1.6.7
bcryptA library to help you hash passwordsbcrypt^5.1.1
bullPremium Queue package for handling distributed jobs and messages in NodeJSbull^4.12.2
canvasNode canvas is a Cairo backed Canvas implementation for NodeJScanvas^2.11.2
corsNode.js CORS middlewarecors^2.8.5
crypto-jsJavaScript library of crypto standardscrypto-js^4.2.0
exceljsExcel Workbook Manager for JavaScriptexceljs^4.4.0
expressFast, unopinionated, minimalist web framework for nodeexpress^4.18.2
jsonwebtokenJSON Web Token implementation for node.jsjsonwebtoken^9.0.2
jspdfPDF Document creation from JavaScriptjspdf^2.5.1
mongooseElegant MongoDB object modeling for Node.jsmongoose^8.2.0
multerNode.js middleware for handling multipart/form-datamulter^1.4.5-lts.1
nodemailerEasy as cake e-mail sending from your Node.js applicationsnodemailer^6.9.12
pdf-libCreate and modify PDF documents in JavaScriptpdf-lib^1.17.1
pdfkitA JavaScript PDF generation library for Node and the browserpdfkit^0.14.0
qrcodeQR code generatorqrcode^1.5.3
redisRedis client libraryredis^4.6.13
sharpHigh-performance image processing in Node.jssharp^0.32.6

2. Dev Dependencies

Package NameDescriptionLinkVersion
@babel/cliBabel command line@babel/cli^7.23.4
@babel/coreBabel compiler core@babel/core^7.23.7
@babel/nodeBabel command line for Node.js@babel/node^7.22.19
@babel/plugin-proposal-class-propertiesBabel plugin for class properties@babel/plugin-proposal-class-properties^7.18.6
@babel/plugin-proposal-object-rest-spreadBabel plugin for object rest/spread@babel/plugin-proposal-object-rest-spread^7.20.7
@babel/preset-envBabel preset for compiling ES2015+@babel/preset-env^7.23.7
@types/adm-zipTypeScript definitions for adm-zip@types/adm-zip^0.5.5
@types/bcryptTypeScript definitions for bcrypt@types/bcrypt^5.0.2
@types/bullTypeScript definitions for bull@types/bull^4.10.0
@types/corsTypeScript definitions for cors@types/cors^2.8.17
@types/crypto-jsTypeScript definitions for crypto-js@types/crypto-js^4.2.2
@types/expressTypeScript definitions for express@types/express^4.17.21
@types/jsonwebtokenTypeScript definitions for jsonwebtoken@types/jsonwebtoken^9.0.5
@types/multerTypeScript definitions for multer@types/multer^1.4.11
@types/nodemailerTypeScript definitions for nodemailer@types/nodemailer^6.4.14
@types/pdfkitTypeScript definitions for pdfkit@types/pdfkit^0.13.4
@types/qrcodeTypeScript definitions for qrcode@types/qrcode^1.5.5
dotenvLoads environment variables from .env filedotenv^16.3.1
nodemonSimple monitor script for use during development of a node.js appnodemon^3.0.2
pm2Production process manager for Node.js applications with a built-in load balancerpm2^5.3.1
rimrafA deep deletion module for noderimraf^5.0.5

III. Environment Variables

Variable NameDescriptionExample Value
PORTPort number for the server3999
MONGODB_URLURL for the MongoDB databasemongodb://localhost:27017/qrantty?authsource=admin
REDIS_HOSTHostname for the Redis serverlocalhost
REDIS_PORTPort number for the Redis server6379
REDIS_PASSWORDPassword for the Redis server
API_KEYSecret key for API authentication, only use for validating config setting routeshhhhh
QR_PROCESSING_SERVERURL for the QR Processing Server, if deploy this server in another server at the same network change localhost to local ip, else if deploy in another network remember change domainhttp://localhost:3998
PRIVATE_KEYPrivate key for JWT token same as the private key in QR Processing SERVERGcalls2023
SECRET_KEYSecret key for hash pasword or serect value input from client siteGcalls2023
MAIL_HOSTHostname for the email serversmtp.bizflycloud.vn
MAIL_USEREmail address for sending emails
MAIL_PASSPassword for the email server
MAIL_PORTPort number for the email server587
MAIL_SECUREEnable/disable SSL/TLS for email serverfalse
SMS_HOSTHostname for the SMS serverhttps://cloudsms4.vietguys.biz:4438/api/index.php
SMS_USERUsername for the SMS server
SMS_PASSPassword for the SMS server
SMS_METHODHTTP method for sending SMSPOST
SMS_FROMSender ID for SMS messages

IV. Source Tree

.
├── assets - Contains subdirectories for backgrounds, excels, images, PDFs, and temporary files.
│ ├── backgrounds/ - Stores background images or files.
│ ├── excels/ - Stores uploaded Excel files.
│ ├── images/ - Stores image files.
│ ├── pdfs/ - Stores PDF files.
│ └── tmp/ - Temporary files storage.
├── ecosystem.config.js - Configuration file for PM2 process manager
├── error.log - Log file for recording runtime errors.
├── example.env - Example environment configuration file for setting environment variables.
├── nodemon.json - Configuration file for Nodemon to manage file watching and automatic server restarts.
├── package.json - File defining the project's dependencies, scripts, and metadata.
├── package-lock.json - Auto-generated file that locks the dependencies to specific versions.
├── README.md - Markdown file containing the project's overview and instructions.
├── src - Source code directory.
│ ├── 3rd - Third-party integrations.
│ │ ├── CRM - Contains CRM-related scripts.
│ │ │ └── brother.js
│ │ └── SMS - Contains SMS-related scripts.
│ │ └── vietguy.js
│ ├── app.js - Main application file.
│ ├── assets - Asset files used in the application.
│ │ └── 3rd
│ │ └── brother
│ │ ├── mail.json
│ │ └── sms.json
│ ├── configs - Configuration files for the application.
│ │ └── index.js
│ ├── logos - Stores logo images.
│ │ ├── bomber.jpeg
│ │ ├── brother.png
│ │ └── index.js
│ ├── middlewares - Middleware functions for handling requests and processing.
│ │ ├── excelStorage.js
│ │ ├── imageStorage.js
│ │ ├── storeFile.js
│ │ ├── verifyAuthConfig.js
│ │ └── verify.js
│ ├── models - Database models.
│ │ ├── Company.js
│ │ ├── Excels.js
│ │ ├── File.js
│ │ └── Models.js
│ ├── routes - API route handlers.
│ │ ├── Admin.js
│ │ ├── Auth.js
│ │ ├── Client.js
│ │ ├── Configs.js
│ │ ├── Excel.js
│ │ ├── index.js
│ │ ├── QR.js
│ │ ├── Test.js
│ │ └── Warranty.js
│ ├── services - Service layer for business logic.
│ │ ├── Excel.js
│ │ ├── QR.js
│ │ └── WarrantyFile.js
│ ├── Storage - Storage-related functions and configurations.
│ │ └── index.js
│ └── utils - Utility functions and helper scripts.
│ ├── axiosClient.js
│ ├── Base64Encoding.js
│ ├── CacheManager.js
│ ├── genAdminPassword.js
│ ├── getDomainFromUrl.js
│ ├── hashPassword.js
│ ├── index.js
│ ├── PasswordManagement.js
│ ├── PDFConvert.js
│ ├── Queue
│ │ ├── 3rdQueue.js
│ │ ├── ExcelQueue.js
│ │ ├── MailQueue.js
│ │ ├── QrQueue.js
│ │ ├── SMSQueue.js
│ │ └── ZipQueue.js
│ ├── splitToChunks.js
│ └── validateDomain.js

V. Data flow diagram

alt text