A secure, modular, and role-based backend API for a parcel delivery system (inspired by Pathao Courier or Sundarban) built with Express.js, TypeScript, and Mongoose. This system allows users to register as senders or receivers and perform parcel delivery operations such as create parcel, track status, and cancel or receive parcels.
Live Demo: Parcel Delivery Management System.
Postman Collection: Parcel Delivery Management System Postman Collection.
- π Authentication: Email/password-based login using JWT.
- π Role-based access (
SENDER,RECEIVER,ADMIN,SUPER_ADMIN,DELIVERY_PERSONNEL) - π¦ Parcel lifecycle: Request, approve, picked, dispatch, deliver, block, cancel, flagged
- π Status Tracking: Track status changes for each parcel.
- π² OTP-based registration verification support
- π§± Scalable Modular Architecture
- ποΈ Coupon support (only admin/super admin can create)
β οΈ Global error and validation handling- π§ Email notifications for OTP and password reset
- Node.js + Express β Backend framework
- MongoDB + Mongoose β NoSQL Database with ODM
- Zod β Schema validation
- TypeScript β Optional typing (if enabled)
- JWT β Authentication
- SSL_Commerz β For Future Payment System
- dotenv β Config management
- Redis β Caching and session management
- Redis β Caching and session management
- EJS β Email templating
- Postman β API testing and documentation
- ESLint β Code quality and linting
- Prettier β Code formatting
- Nodemailer β Email sending
- Vercel β Deployment platform
// ADMIN
email: "bedonad434@ekuali.com",
password: "12345@Mn"
// SENDER
email: "vilicab354@poesd.com",
password: "12345@Mn"
// RECEIVER
email: "ciweto1555@ekuali.com",
password: "12345@Mn",
//Delivery Personnel ID
68ca9515cd3fcd1818b93892
- JWT-based authentication system
- Secure password hashing with bcrypt
- Role-based access control (admin, sender, receiver, super_admin)
- Google OAuth integration with Passport.js
- OTP verification system
- Refresh token mechanism
- User registration and login
- Profile management
- User blocking/unblocking (Admin)
- Email verification system
-
Sender Features:
- Create parcel delivery requests
- Cancel parcels (if not dispatched)
- View all their parcels with status logs
- Delete parcels (with restrictions)
-
Receiver Features:
- View incoming parcels
- Confirm parcel delivery
- View delivery history
-
Admin Features:
- View and manage all users and parcels
- Block or unblock users/parcels
- Update delivery statuses
- Assign delivery personnel
- Create parcels on behalf of users
- Unique tracking ID generation (Format:
TRK-YYYYMMDD-XXXXXX) - Public parcel tracking by tracking ID
- Embedded status logs within parcel documents
- Complete status transition validation
- Dynamic fee calculation based on weight, type, and shipping method
- Coupon system for discounts
- Statistics and analytics
- Advanced search and filtering
- Pagination support
βββ .git/ π« (auto-hidden)
βββ dist/ π« (auto-hidden)
βββ node_modules/ π« (auto-hidden)
βββ src/
β βββ app/
β β βββ config/
β β β βββ cloudinary.config.ts
β β β βββ env.ts
β β β βββ multer.config.ts
β β β βββ passport.ts
β β β βββ redis.config.ts
β β βββ errorHelpers/
β β β βββ AppError.ts
β β β βββ handleCastError.ts
β β β βββ handleDuplicate.ts
β β β βββ handleDuplicateError.ts
β β β βββ handleValidationError.ts
β β β βββ handleZodError.ts
β β β βββ handlerValidationError.ts
β β β βββ handlerZodError.ts
β β βββ interfaces/
β β β βββ error.types.ts
β β β βββ index.d.ts
β β βββ middlewares/
β β β βββ checkAuth.ts
β β β βββ globalErrorHandler.ts
β β β βββ notFound.ts
β β β βββ validateRequest.ts
β β βββ modules/
β β β βββ auth/
β β β β βββ auth.controller.ts
β β β β βββ auth.route.ts
β β β β βββ auth.service.ts
β β β βββ coupon/
β β β β βββ coupon.controller.ts
β β β β βββ coupon.interface.ts
β β β β βββ coupon.model.ts
β β β β βββ coupon.route.ts
β β β β βββ coupon.service.ts
β β β β βββ coupon.utils.ts
β β β β βββ coupon.validation.ts
β β β βββ otp/
β β β β βββ otp.controller.ts
β β β β βββ otp.route.ts
β β β β βββ otp.service.ts
β β β β βββ otp.validation.ts
β β β βββ parcel/
β β β β βββ parcel.controller.ts
β β β β βββ parcel.interface.ts
β β β β βββ parcel.model.ts
β β β β βββ parcel.route.ts
β β β β βββ parcel.service.ts
β β β β βββ parcel.utils.ts
β β β β βββ parcel.validation.ts
β β β βββ stats/
β β β β βββ stats.controller.ts
β β β β βββ stats.route.ts
β β β β βββ stats.service.ts
β β β βββ user/
β β β βββ user.constant.ts
β β β βββ user.controller.ts
β β β βββ user.interface.ts
β β β βββ user.model.ts
β β β βββ user.route.ts
β β β βββ user.service.ts
β β β βββ user.validation.ts
β β βββ routes/
β β β βββ index.ts
β β βββ utils/
β β β βββ templates/
β β β β βββ forgetPassword.ejs
β β β β βββ invoice.ejs
β β β β βββ otp.ejs
β β β βββ QueryBuilder.ts
β β β βββ catchAsync.ts
β β β βββ generateTrackingId.ts
β β β βββ getTransactionId.ts
β β β βββ invoice.ts
β β β βββ jwt.ts
β β β βββ seedSuperAdmin.ts
β β β βββ sendEmail.ts
β β β βββ sendResponse.ts
β β β βββ setCookie.ts
β β β βββ userTokens.ts
β β βββ constants.ts
β βββ app.ts
β βββ server.ts
βββ .env π« (auto-hidden)
βββ .gitignore
βββ README.md
βββ eslint.config.mjs
βββ package-lock.json
βββ package.json
βββ tsconfig.json
- Node.js (v16 or higher)
- MongoDB
- Redis (for session management)
- npm or yarn
- Clone the repository:
git clone https://github.com/md-nasim-mondal/parcel-dms-server
cd parcel-dms-server- Install dependencies:
npm install- Environment Setup:
Create a
.envfile in the root directory:
NODE_ENV=development
PORT=5000
DB_URL=mongodb://localhost:27017
NODE_ENV=development
#JWT
JWT_ACCESS_SECRET=your_jwt_access_secret
JWT_REFRESH_SECRET=your_jwt_refresh_secret
JWT_ACCESS_EXPIRES=1d
JWT_REFRESH_EXPIRES=30d
# BCRYPT
BCRYPT_SALT_ROUNDS=your_bcrypt_salt_round
#For Seed SUPER ADMIN
SUPER_ADMIN_EMAIL=your_super_admin_email
SUPER_ADMIN_PASSWORD=your_super_admin_password
# Google
GOOGLE_CLIENT_ID=your_google_Oauth_client_id
GOOGLE_CLIENT_SECRET=your_google_Oauth_client_secret
GOOGLE_CALLBACK_URL=http://localhost:5000/api/v1/auth/google/callback
# Express Session
EXPRESS_SESSION_SECRET=express-session
# Frontend URL
FRONTEND_URL=http://localhost:5173
#sslCommerz
SSL_STORE_ID=your_ssl_store_id
SSL_STORE_PASS=your_ssl_store_pass
SSL_PAYMENT_API=ssl_payment_api
SSL_VALIDATION_API=ssl_payment_validation_api
SSL_IPN_URL=your_ipn_url
# SSL Commerz BACKEND URLs
SSL_SUCCESS_BACKEND_URL="http://localhost:5000/api/v1/payment/success"
SSL_FAIL_BACKEND_URL="http://localhost:5000/api/v1/payment/fail"
SSL_CANCEL_BACKEND_URL="http://localhost:5000/api/v1/payment/cancel"
# SSL Commerz FRONTEND URLs
SSL_SUCCESS_FRONTEND_URL="http://localhost:5173/payment/success"
SSL_FAIL_FRONTEND_URL="http://localhost:5173/payment/fail"
SSL_CANCEL_FRONTEND_URL="http://localhost:5173/payment/cancel"
# CLOUDINARY Setup
CLOUDINARY_CLOUD_NAME=your_cloudinary_cloud_name
CLOUDINARY_API_KEY=your_cloudinary_api_key
CLOUDINARY_API_SECRET=your_cloudinary_api_secret
# SMTP GMAIL Setup With Nodemailer
SMTP_HOST=smtp.gmail.com
SMTP_PORT=465
SMTP_USER=your_smtp_user_email_address
SMTP_PASS=your_smtp_user_email_app_pass
SMTP_FORM=your_smtp_user_email_address
# Redis Setup
REDIS_HOST=your_redis_host_url or redis://localhost:6379
REDIS_PORT=13474
REDIS_USERNAME=your_redis_username
REDIS_PASSWORD=your_redis_password
- Start the development server:
npm run dev- Build for production:
npm run build
npm startPOST /register- User registrationPOST /login- User loginPOST /refresh-token- Get new access tokenPOST /change-password- Change passwordPOST /forgot-password- Forgot passwordPOST /reset-password- Reset passwordGET /google- Google OAuth login
GET /- Get all users (Admin only)GET /me- Get current user profileGET /:id- Get single user (Admin only)PUT /:id- Update user profile
POST /- Create parcel (Sender only)POST /cancel/:id- Cancel parcel (Sender only)DELETE /delete/:id- Delete parcel (Sender only)GET /me- Get sender's parcels (Sender only)GET /status-log/:id- Get parcel with history (Sender only)
GET /me/incoming- Get incoming parcels (Receiver only)PATCH /confirm/:id- Confirm delivery (Receiver only)GET /me/history- Get delivery history (Receiver only)
GET /- Get all parcels (Admin only)POST /create-parcel- Create parcel by admin (Admin only)PATCH /delivery-status/:id- Update parcel status (Admin only)PATCH /block-status/:id- Block/unblock parcel (Admin only)GET /details/:id- Get parcel details (Admin only)
GET /tracking/:trackingId- Track parcel by tracking ID
POST /send- Send OTPPOST /verify- Verify OTP
POST /- Create coupon (Admin only)GET /- Get all coupons
For applying coupons code you need to sendCoupon code as couponCode in parcel create time
GET /user- Get system user statistics (Admin only)GET /parcel- Get system parcel statistics (Admin only)
- SENDER: Can create, cancel, and view their parcels
- RECEIVER: Can view incoming parcels and confirm deliveries
- ADMIN: Can manage users and parcels
- SUPER_ADMIN: Full Admin system access and super admin can demoted a admin
{
"userId": "user_id",
"email": "user@example.com",
"role": "SENDER",
"iat": 1234567890,
"exp": 1234567890
}The parcel lifecycle goes through multiple stages. At each stage, certain exceptions such as Cancel, Return, Reschedule, Flag, On Hold, or Blocked may occur.
REQUESTED β APPROVED β PICKED β DISPATCHED β IN_TRANSIT β DELIVERED
REQUESTED β CANCELLED APPROVED β CANCELLED PICKED β RETURNED DISPATCHED β RETURNED IN_TRANSIT β RESCHEDULED
CANCELLED β FLAGGED β BLOCKED RETURNED β FLAGGED β BLOCKED RESCHEDULED β ON_HOLD β BLOCKED
- REQUESTED β When the customer places an order.
- APPROVED β When the order is verified and approved by the seller/admin.
- PICKED β When the courier picks up the parcel.
- DISPATCHED β When the parcel is dispatched toward its destination.
- IN_TRANSIT β While the parcel is on the way.
- DELIVERED β When the parcel is successfully delivered to the customer.
- CANCELLED / RETURNED / RESCHEDULED β Possible exception states depending on customer or delivery issues.
- FLAGGED / ON_HOLD / BLOCKED β Security or policy-related statuses for further investigation.
β This flow clearly illustrates how a parcel progresses step by step and what exceptional cases may occur during the delivery process.
- Format:
TRK-YYYYMMDD-XXXXXX - Example:
TRK-20241201-A1B2C3
- Base fee: ΰ§³50
- Weight-based pricing:
- Up to 500g: +ΰ§³50
- 500g-1kg: +ΰ§³100
- 1kg-2kg: +ΰ§³150
- 2kg-5kg: +ΰ§³250
- 5kg-10kg: +ΰ§³400
DOCUMENT: No surchargePACKAGE: +ΰ§³10FRAGILE: +ΰ§³25ELECTRONICS: +ΰ§³40
STANDARD: No surcharge (5 days)EXPRESS: +ΰ§³50 (2 days)OVERNIGHT: +ΰ§³75 (1 day)SAME_DAY: +ΰ§³100 (6 hours)
- Backend: Node.js, Express.js, TypeScript
- Database: MongoDB with Mongoose ODM
- Authentication: JWT, bcrypt, Passport.js
- Session Store: Redis
- Validation: Zod
- Development: ts-node-dev, ESLint, Prettier
Use the provided Postman collection to test all endpoints. Import the collection and set up the environment variables:
baseURL:http://localhost:5000/api/v1accessToken: JWT token from login response
POST /api/v1/auth/register
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"role": "SENDER",
"phone": "+8801234567890",
"defaultAddress": "123 Main St, Dhaka"
}POST /api/v1/parcels
{
"receiverName": "Jane Smith",
"receiverPhone": "+8801987654321",
"receiverEmail": "jane@example.com",
"pickupAddress": "123 Sender St, Dhaka",
"deliveryAddress": "456 Receiver Ave, Chittagong",
"weight": 2.5,
"type": "PACKAGE",
"shippingType": "EXPRESS",
"description": "Important documents"
}GET /api/v1/parcel/tracking/TRK-20241201-A1B2C3npm run dev- Start development servernpm run build- Build for productionnpm start- Start production servernpm run lint- Run ESLintnpm run lint:fix- Fix ESLint issuesnpm run prettier- Format code with Prettier
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is licensed under the MIT License.
Developed with β€οΈ for the parcel delivery system.
Note: This API is fully functional and includes all the requirements specified in the project brief. All endpoints are protected with proper authentication and authorization, and the system supports complete parcel lifecycle management with embedded status tracking. Additionally, the system includes coupon management features, allowing for the creation, application, and management of discount codes for parcel deliveries.