QR Processing Server
I. Introduction
The QR Processing Server is a critical component of the Qranty system, responsible for generating QR codes for product tracking and warranty registration. This document provides an overview of the QR Processing Server, detailing its architecture, functionality, and interactions with other components of the system.
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 |
| archiver | A library for creating zip and tar archives | archiver | ^7.0.1 |
| 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 |
| exceljs | Excel Workbook Manager for JavaScript | exceljs | ^4.4.0 |
| express | Fast, unopinionated, minimalist web framework for node | express | ^4.18.2 |
| fix-esm | A utility to fix ESM import/export issues | fix-esm | ^1.0.1 |
| get-stream | Get a stream as a string, buffer, or array | get-stream | ^9.0.1 |
| 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 |
| 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 |
| tar-stream | Streaming tar parser and generator | tar-stream | ^3.1.7 |
| zip-stream | Create zip archives on-the-fly | zip-stream | ^6.0.1 |
| zlib | A library for handling zip archives | zlib | ^1.0.5 |
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.24.3 |
| @types/adm-zip | TypeScript definitions for adm-zip | @types/adm-zip | ^0.5.5 |
| @types/archiver | TypeScript definitions for archiver | @types/archiver | ^6.0.2 |
| @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/pdfkit | TypeScript definitions for pdfkit | @types/pdfkit | ^0.13.4 |
| @types/qrcode | TypeScript definitions for qrcode | @types/qrcode | ^1.5.5 |
| @types/tar-stream | TypeScript definitions for tar-stream | @types/tar-stream | ^3.1.3 |
| 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 | Default Value |
|---|---|---|
| NODE_ENV | Environment mode | development |
| PORT | Port number for the server | 3998 |
| MONGODB_URL | MongoDB connection URL | mongodb://localhost:27017/qrantty?authsource=admin |
| REDIS_HOST | Redis host | localhost |
| REDIS_PORT | Redis port | 6379 |
| REDIS_PASSWORD | Redis password | |
| PRIVATE_KEY | Private key for JWT token same as the private key in Transportation Server | Gcalls2023 |
IV. Source Tree
.
├── ecosystem.config.js - Configuration file for PM2 process manager
├── 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.
└── src - Source code directory.
├── app.js - Main application file.
├── 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
│ └── verify.js
├── models - Database models.
│ ├── Company.js
│ ├── Excels.js
│ ├── File.js
│ └── Models.js
├── routes - API route handlers.
│ └── Excel.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.
├── CacheManager.js
├── index.js
├── PDFConvert.js
├── Queue
│ ├── CompressQueue.js
│ ├── ExcelQueue.js
│ ├── ExportQueue.js
│ ├── QrQueue.js
│ └── ZipQueue.js
├── reducePDF.js
├── splitToChunks.js
└── validateDomain.js
V. Data Flow Diagram
