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 Name | Description | Link | Version |
|---|---|---|---|
| @shortcm/qr-image | QR Code image generation library | @shortcm/qr-image | ^9.0.4 |
| adm-zip | A Javascript implementation of zip for nodejs | adm-zip | ^0.5.12 |
| axios | Promise based HTTP client for the browser and node.js | axios | ^1.6.7 |
| bcrypt | A library to help you hash passwords | bcrypt | ^5.1.1 |
| bull | Premium Queue package for handling distributed jobs and messages in NodeJS | bull | ^4.12.2 |
| canvas | Node canvas is a Cairo backed Canvas implementation for NodeJS | canvas | ^2.11.2 |
| cors | Node.js CORS middleware | cors | ^2.8.5 |
| crypto-js | JavaScript library of crypto standards | crypto-js | ^4.2.0 |
| exceljs | Excel Workbook Manager for JavaScript | exceljs | ^4.4.0 |
| express | Fast, unopinionated, minimalist web framework for node | express | ^4.18.2 |
| jsonwebtoken | JSON Web Token implementation for node.js | jsonwebtoken | ^9.0.2 |
| jspdf | PDF Document creation from JavaScript | jspdf | ^2.5.1 |
| mongoose | Elegant MongoDB object modeling for Node.js | mongoose | ^8.2.0 |
| multer | Node.js middleware for handling multipart/form-data | multer | ^1.4.5-lts.1 |
| nodemailer | Easy as cake e-mail sending from your Node.js applications | nodemailer | ^6.9.12 |
| pdf-lib | Create and modify PDF documents in JavaScript | pdf-lib | ^1.17.1 |
| pdfkit | A JavaScript PDF generation library for Node and the browser | pdfkit | ^0.14.0 |
| qrcode | QR code generator | qrcode | ^1.5.3 |
| redis | Redis client library | redis | ^4.6.13 |
| sharp | High-performance image processing in Node.js | sharp | ^0.32.6 |
2. Dev Dependencies
| Package Name | Description | Link | Version |
|---|---|---|---|
| @babel/cli | Babel command line | @babel/cli | ^7.23.4 |
| @babel/core | Babel compiler core | @babel/core | ^7.23.7 |
| @babel/node | Babel command line for Node.js | @babel/node | ^7.22.19 |
| @babel/plugin-proposal-class-properties | Babel plugin for class properties | @babel/plugin-proposal-class-properties | ^7.18.6 |
| @babel/plugin-proposal-object-rest-spread | Babel plugin for object rest/spread | @babel/plugin-proposal-object-rest-spread | ^7.20.7 |
| @babel/preset-env | Babel preset for compiling ES2015+ | @babel/preset-env | ^7.23.7 |
| @types/adm-zip | TypeScript definitions for adm-zip | @types/adm-zip | ^0.5.5 |
| @types/bcrypt | TypeScript definitions for bcrypt | @types/bcrypt | ^5.0.2 |
| @types/bull | TypeScript definitions for bull | @types/bull | ^4.10.0 |
| @types/cors | TypeScript definitions for cors | @types/cors | ^2.8.17 |
| @types/crypto-js | TypeScript definitions for crypto-js | @types/crypto-js | ^4.2.2 |
| @types/express | TypeScript definitions for express | @types/express | ^4.17.21 |
| @types/jsonwebtoken | TypeScript definitions for jsonwebtoken | @types/jsonwebtoken | ^9.0.5 |
| @types/multer | TypeScript definitions for multer | @types/multer | ^1.4.11 |
| @types/nodemailer | TypeScript definitions for nodemailer | @types/nodemailer | ^6.4.14 |
| @types/pdfkit | TypeScript definitions for pdfkit | @types/pdfkit | ^0.13.4 |
| @types/qrcode | TypeScript definitions for qrcode | @types/qrcode | ^1.5.5 |
| dotenv | Loads environment variables from .env file | dotenv | ^16.3.1 |
| nodemon | Simple monitor script for use during development of a node.js app | nodemon | ^3.0.2 |
| pm2 | Production process manager for Node.js applications with a built-in load balancer | pm2 | ^5.3.1 |
| rimraf | A deep deletion module for node | rimraf | ^5.0.5 |
III. Environment Variables
| Variable Name | Description | Example Value |
|---|---|---|
| PORT | Port number for the server | 3999 |
| MONGODB_URL | URL for the MongoDB database | mongodb://localhost:27017/qrantty?authsource=admin |
| REDIS_HOST | Hostname for the Redis server | localhost |
| REDIS_PORT | Port number for the Redis server | 6379 |
| REDIS_PASSWORD | Password for the Redis server | |
| API_KEY | Secret key for API authentication, only use for validating config setting route | shhhhh |
| QR_PROCESSING_SERVER | URL 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 domain | http://localhost:3998 |
| PRIVATE_KEY | Private key for JWT token same as the private key in QR Processing SERVER | Gcalls2023 |
| SECRET_KEY | Secret key for hash pasword or serect value input from client site | Gcalls2023 |
| MAIL_HOST | Hostname for the email server | smtp.bizflycloud.vn |
| MAIL_USER | Email address for sending emails | |
| MAIL_PASS | Password for the email server | |
| MAIL_PORT | Port number for the email server | 587 |
| MAIL_SECURE | Enable/disable SSL/TLS for email server | false |
| SMS_HOST | Hostname for the SMS server | https://cloudsms4.vietguys.biz:4438/api/index.php |
| SMS_USER | Username for the SMS server | |
| SMS_PASS | Password for the SMS server | |
| SMS_METHOD | HTTP method for sending SMS | POST |
| SMS_FROM | Sender 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
