ES
ESRAILHAQUE/parcel-delivery-system
π Parcel Delivery System - Node.js/Express/TypeScript backend API with MongoDB for parcel management, vehicle tracking, route optimization, and analytics dashboard.
π Parcel Delivery System API
A comprehensive, enterprise-grade backend API for managing parcel delivery operations with advanced route optimization, real-time tracking, and analytics dashboard.
ποΈ Project Architecture
Modular Architecture with MVC Pattern
src/
βββ app/
β βββ config/ # Environment configuration
β βββ middlewares/ # Authentication & error handling
β βββ modules/ # Feature-based modules
β β βββ auth/ # Authentication & user management
β β βββ parcel/ # Parcel management system
β β βββ vehicle/ # Fleet management system
β β βββ route/ # Route optimization & planning
β β βββ analytics/ # Analytics & reporting dashboard
β βββ types/ # TypeScript type definitions
β βββ utils/ # Utility functions & algorithms
βββ app.ts # Express application setup
βββ server.ts # Server entry point
π Getting Started
Prerequisites
- Node.js (v16 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn
Installation
-
Clone the repository:
git clone <repository-url> cd parcel-delivery-system
-
Install dependencies:
npm install
-
Environment setup:
cp env.example .env
-
Configure environment variables:
# .env file NODE_ENV=development PORT=5000 MONGODB_URI=mongodb://localhost:27017/parcel-delivery-system JWT_SECRET=your-super-secret-jwt-key JWT_EXPIRES_IN=7d -
Start the development server:
npm run dev
-
Build for production:
npm run build npm start
π Complete API Documentation
π Authentication Endpoints
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/api/v1/auth/register |
User registration | Public |
POST |
/api/v1/auth/login |
User login | Public |
GET |
/api/v1/auth/profile |
Get user profile | Authenticated |
PUT |
/api/v1/auth/profile |
Update user profile | Authenticated |
PUT |
/api/v1/auth/change-password |
Change password | Authenticated |
GET |
/api/v1/auth/users |
Get all users | Admin |
PUT |
/api/v1/auth/users/:id/role |
Change user role | Admin |
DELETE |
/api/v1/auth/users/:id |
Delete user | Admin |
π¦ Parcel Management Endpoints
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/api/v1/parcels |
Create new parcel | Customer |
GET |
/api/v1/parcels |
Get all parcels | Admin/DeliveryMan |
GET |
/api/v1/parcels/:id |
Get parcel by ID | Admin/DeliveryMan |
GET |
/api/v1/parcels/track/:trackingNumber |
Track parcel | Public |
PUT |
/api/v1/parcels/:id/assign |
Assign delivery man | Admin |
PUT |
/api/v1/parcels/:id/status |
Update parcel status | Admin/DeliveryMan |
GET |
/api/v1/parcels/my-parcels |
Get customer parcels | Customer |
GET |
/api/v1/parcels/my-assignments |
Get delivery assignments | DeliveryMan |
GET |
/api/v1/parcels/admin/statistics |
Get parcel statistics | Admin |
DELETE |
/api/v1/parcels/:id |
Delete parcel | Admin |
π Vehicle Management Endpoints
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/api/v1/vehicles |
Create new vehicle | Admin |
GET |
/api/v1/vehicles |
Get all vehicles | Admin/DeliveryMan/Customer |
GET |
/api/v1/vehicles/:id |
Get vehicle by ID | Admin/DeliveryMan/Customer |
PUT |
/api/v1/vehicles/:id |
Update vehicle | Admin |
POST |
/api/v1/vehicles/:id/assign-driver |
Assign driver | Admin |
DELETE |
/api/v1/vehicles/:id/remove-driver |
Remove driver | Admin |
PATCH |
/api/v1/vehicles/:id/status |
Update vehicle status | Admin/DeliveryMan |
PATCH |
/api/v1/vehicles/:id/location |
Update vehicle location | Admin/DeliveryMan |
PATCH |
/api/v1/vehicles/:id/load |
Update vehicle load | Admin/DeliveryMan |
GET |
/api/v1/vehicles/find/nearest |
Find nearest vehicle | Admin/DeliveryMan |
GET |
/api/v1/vehicles/statistics/overview |
Vehicle statistics | Admin |
DELETE |
/api/v1/vehicles/:id |
Delete vehicle | Admin |
πΊοΈ Route Optimization Endpoints
| Method | Endpoint | Description | Access |
|---|---|---|---|
POST |
/api/v1/routes/optimize |
Generate optimal routes | Admin |
POST |
/api/v1/routes/assign |
Assign parcels to vehicles | Admin |
GET |
/api/v1/routes/efficiency |
Get delivery efficiency | Admin/DeliveryMan |
GET |
/api/v1/routes/status |
Real-time delivery status | Admin/DeliveryMan |
POST |
/api/v1/routes/optimize-specific |
Optimize specific parcels | Admin |
π Analytics Dashboard Endpoints
| Method | Endpoint | Description | Access |
|---|---|---|---|
GET |
/api/v1/analytics/dashboard |
Comprehensive dashboard | Admin |
GET |
/api/v1/analytics/realtime |
Real-time status | Admin/DeliveryMan |
GET |
/api/v1/analytics/performance |
Performance metrics | Admin |
GET |
/api/v1/analytics/fleet |
Fleet analytics | Admin |
GET |
/api/v1/analytics/report |
Generate delivery report | Admin |
π User Roles & Permissions
π Admin
- Full system access
- User management
- Vehicle management
- Route optimization
- Analytics dashboard
- Parcel assignment
- System configuration
π€ Customer
- Create parcels
- Track deliveries
- View own parcels
- Update profile
- View available vehicles
π DeliveryMan
- View assigned parcels
- Update parcel status
- Update vehicle location
- View delivery statistics
- Access route information
π οΈ Technology Stack
Backend Technologies
- Node.js - Runtime environment
- Express.js - Web framework
- TypeScript - Type-safe development
- MongoDB - NoSQL database
- Mongoose - ODM for MongoDB
Authentication & Security
- JWT - JSON Web Tokens
- Bcrypt - Password hashing
- CORS - Cross-origin resource sharing
- Helmet - Security headers
Validation & Error Handling
- Zod - Schema validation
- Custom error middleware - Centralized error handling
- HTTP status codes - Proper status responses
Advanced Features
- Route Optimization Algorithms - Nearest Neighbor, Genetic Algorithms
- Distance Calculation - Haversine formula
- Real-time Tracking - Live location updates
- Analytics Dashboard - Comprehensive reporting
- Performance Metrics - Delivery efficiency tracking
π Advanced Features
πΊοΈ Route Optimization
- Multi-vehicle routing
- Time window constraints
- Capacity optimization
- Priority-based routing
- Real-time rerouting
- Cost minimization
π Analytics & Reporting
- Delivery efficiency metrics
- Fleet utilization statistics
- Driver performance tracking
- Revenue analytics
- Route optimization reports
- Real-time dashboard
π Fleet Management
- Vehicle registration
- Driver assignment
- Location tracking
- Capacity management
- Maintenance scheduling
- Fuel consumption tracking
π¦ Parcel Management
- Automated tracking numbers
- Status workflow management
- Delivery time estimation
- Special handling instructions
- Insurance and value tracking
- Customer notifications
π§ Development Scripts
# Development
npm run dev # Start development server with hot reload
npm run build # Build TypeScript to JavaScript
npm start # Start production server
npm run lint # Run ESLint
npm run test # Run tests
# Database
npm run db:seed # Seed database with sample data
npm run db:reset # Reset databaseπ Module Structure
Each module follows the MVC pattern with:
module/
βββ module.controller.ts # HTTP request handlers
βββ module.service.ts # Business logic
βββ module.model.ts # Database schema
βββ module.interface.ts # TypeScript interfaces
βββ module.validation.ts # Input validation
βββ routes.ts # Route definitions
π Key Features
- β Modular Architecture - Feature-based organization
- β Type Safety - Full TypeScript implementation
- β Role-based Access Control - Secure API endpoints
- β Advanced Route Optimization - Industry-grade algorithms
- β Real-time Tracking - Live delivery monitoring
- β Analytics Dashboard - Comprehensive reporting
- β Fleet Management - Complete vehicle management
- β Performance Metrics - Delivery efficiency tracking
- β Scalable Design - Enterprise-ready architecture
- β Comprehensive Validation - Input sanitization
- β Error Handling - Centralized error management
- β Security - JWT authentication & authorization
π Performance & Scalability
- Database Indexing - Optimized queries
- Connection Pooling - Efficient database connections
- Caching Strategy - Redis integration ready
- Load Balancing - Horizontal scaling support
- API Rate Limiting - Request throttling
- Monitoring - Performance metrics
π Security Features
- JWT Authentication - Secure token-based auth
- Password Hashing - Bcrypt encryption
- Input Validation - Zod schema validation
- SQL Injection Prevention - Mongoose ODM
- CORS Configuration - Cross-origin security
- Environment Variables - Secure configuration
π API Response Format
{
"success": true,
"message": "Operation completed successfully",
"data": {
// Response data
}
}π¨ Error Response Format
{
"success": false,
"message": "Error description",
"errors": [
{
"field": "fieldName",
"message": "Error message",
"code": "error_code"
}
]
}π Support
For support and questions:
- Documentation: Check API endpoints above
- Issues: Create GitHub issue
- Email: [Your Email]
π License
This project is licensed under the MIT License.
π Ready for Production Deployment!
This is a complete, enterprise-grade parcel delivery system with all modern features and best practices implemented.