File size: 2,882 Bytes
fcf8749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# πŸš› Hyper-Local Logistics & Relay Optimizer

An advanced, end-to-end logistics orchestration platform designed to maximize truck utilization and driver efficiency. This project features a unique **Driver Relay (Handshake) System** and an automated, API-free **e-Way Bill Generator**.

---

## 🌟 Key Features

### πŸ”„ Driver Relay & Workload Balancing
Intelligent assignment logic based on custom business rules:
* **Experience-Based Assignment:** Automatically matches long-haul missions (e.g., >300km) with experienced drivers (high historical `totalDistanceKm`).
* **Workload Balancing:** Assigns shorter missions to newer drivers to ensure a fair and safe distribution of labor.
* **ID Resolution:** Dispatchers use "Human-Readable" identifiers like **Phone Numbers** and **License Plates** instead of complex Database UUIDs.

### 🀝 Absorption Handshake System
A peer-to-peer "handover" mechanism allowing trucks to exchange goods at virtual hubs:
* **Offline Verification:** Supports a "Digital Handshake" via cryptographic QR codes for areas with zero cellular connectivity.
* **Dual-Bill Updates:** Automatically handles the transfer of responsibility between an "Exporter" driver and an "Importer" driver.

### πŸ“„ Dynamic e-Way Bill Mimicry
Generates professional e-Way Bills using **Node.js & Puppeteer**:
* **No External APIs:** Mimics the official government layout purely via HTML/CSS.
* **Auto-Data Resolution:** Fetches GSTINs (Supplier/Recipient), License Plates, and Phone Numbers automatically from the database.
* **Dual Generation:** Produces two updated PDFs (for both trucks) instantly during an absorption event, delivered in a single `.zip` file.

---

## πŸ—οΈ Technical Architecture



### **Tech Stack**
* **Backend:** Node.js, Express.js
* **Database:** PostgreSQL (Optimized with Prisma ORM)
* **PDF Engine:** Puppeteer (Headless Chrome for high-fidelity rendering)
* **Auth:** JWT with Role-Based Access Control (RBAC)
* **File Handling:** `archiver` for ZIP generation and `qrcode` for local QR generation.

---

## πŸ“‚ Project Structure

```text
β”œβ”€β”€ config/
β”‚   └── prisma.js               # Prisma Client initialization
β”œβ”€β”€ controllers/
β”‚   β”œβ”€β”€ routeController.js      # Relay logic & assignment
β”‚   └── ewayBillController.js   # PDF generation & absorption logic
β”œβ”€β”€ services/
β”‚   β”œβ”€β”€ puppeteer.service.js    # PDF rendering engine (Virtual Printer)
β”‚   └── qr.service.js           # Base64 QR code generation
β”œβ”€β”€ templates/
β”‚   └── ewayBill.html           # HTML layout mimicking official format
β”œβ”€β”€ public/
β”‚   └── css/ewayBill.css        # Print-optimized styles (@media print)
β”œβ”€β”€ routes/
β”‚   └── api.js                  # Protected API endpoints
└── prisma/
    └── schema.prisma           # Relational Database Models