A modern, scalable backend API for a parcel delivery management system. Built with TypeScript, Express.js, and Prisma ORM, NexDrop provides a comprehensive solution for managing parcels, riders, payments, and user authentication.
- Production URL: https://nexdrop.up.railway.app/
- GitHub Repository: https://github.com/mdmhrz/nexdrop-backend
- User Management: Customer, Admin, and Rider account management with role-based access control
- Authentication & Authorization: Secure authentication using better-auth with session-based and token-based auth
- Parcel Management: Create, track, and manage parcels with real-time status updates
- Rider Operations: Rider application, approval, assignment, and delivery management
- Payment Integration: Multiple payment gateway support (Stripe, SSLCommerz)
- Rating System: Customer ratings for riders with average rating calculations
- Address Management: Multiple address management for customers
- Analytics Dashboard: Revenue analytics, parcel statistics, and performance metrics
- Cashout System: Rider earnings management and cashout request processing
- Customer: Create parcels, track deliveries, manage addresses, rate riders
- Rider: Apply for rider account, accept deliveries, manage earnings, request cashouts
- Admin: Manage users, approve riders, view analytics, manage system operations
- Super Admin: Full system control and configuration
- Node.js - JavaScript runtime
- Express.js - Web application framework
- TypeScript - Type-safe JavaScript
- PostgreSQL - Relational database
- Prisma ORM - Database toolkit and ORM
- Prisma Adapter (pg) - PostgreSQL adapter for Prisma
- better-auth - Modern authentication library
- JWT - Token-based authentication
- Cookie Parser - Cookie management
- Stripe - Payment processing
- SSLCommerz - Alternative payment gateway
- Zod - Schema validation
- http-status - HTTP status codes
- dotenv - Environment variable management
- ESLint - Code linting
- tsx - TypeScript execution
- tsup - TypeScript bundler
- Prisma Studio - Database GUI
Before you begin, ensure you have the following installed:
- Node.js (v18 or higher)
- pnpm (v10 or higher) - Package manager
- PostgreSQL (v14 or higher) - Database
- Git - Version control
git clone https://github.com/mdmhrz/nexdrop-backend.git
cd nexdrop-backendpnpm installCopy the .env.example file to .env and configure your environment variables:
cp .env.example .envEdit the .env file with your configuration:
NODE_ENV=development
PORT=5000
DATABASE_URL=postgresql://user:password@localhost:5432/nexdrop
BETTER_AUTH_SECRET=your_better_auth_secret_here
BETTER_AUTH_URL=http://localhost:5000
# JWT Configuration
ACCESS_TOKEN_SECRET=your_access_token_secret_here
REFRESH_TOKEN_SECRET=your_refresh_token_secret_here
ACCESS_TOKEN_EXPIRES_IN=1d
REFRESH_TOKEN_EXPIRES_IN=7d
# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
FRONTEND_URL=http://localhost:3000
BACKEND_URL=http://localhost:5000
# SSL Commerz Configuration
SSLCOMMERZ_STORE_ID=your_store_id
SSLCOMMERZ_STORE_PASSWORD=your_store_password
SSLCOMMERZ_IS_SANDBOX=truepnpm migrateThis will create the database and apply all migrations.
pnpm pushThis will push the schema directly to the database without creating migration files.
pnpm generateRun the project in development mode with hot reload:
pnpm devThe server will start at http://localhost:5000
Build the project and run in production mode:
pnpm build
pnpm startOpen Prisma Studio to manage your database visually:
pnpm studioComprehensive API documentation is available in the /docs directory:
- Auth Module API - Authentication and user management endpoints
- User Module API - User management and profile endpoints
- Address Module API - Address management endpoints
- Rider Module API - Rider application and management endpoints
- Parcel Module API - Parcel management endpoints
- Payment Module API - Payment processing endpoints
- Rating Module API - Rating and review endpoints
- Analytics Module API - Analytics and statistics endpoints
A Bruno API collection is available at public/NexDrop_API-documentation.html for testing API endpoints.
All API endpoints are prefixed with /api/v1
Example: http://localhost:5000/api/v1/auth/register
Most endpoints require authentication using either:
- Session Token: Cookie
better-auth.session_token - Access Token: Authorization header
Bearer <token>
Success Response:
{
"success": true,
"message": "Success message",
"data": { ... }
}Error Response:
{
"success": false,
"message": "Error message",
"errorSources": [
{
"path": "field_name",
"message": "Validation error message"
}
]
}The project uses Prisma ORM with PostgreSQL. Key models include:
- User: Customer, admin, and rider accounts
- Rider: Rider profiles and account status
- Parcel: Delivery parcels with tracking
- Payment: Payment transactions
- Earning: Rider earnings from deliveries
- Cashout: Rider cashout requests
- Address: User addresses
- RiderRating: Customer ratings for riders
To view the full schema, check the prisma/schema directory.
pnpm dev # Run in development mode with hot reload
pnpm build # Build the project for production
pnpm start # Run the production build
pnpm lint # Run ESLint
pnpm migrate # Run Prisma migrations
pnpm generate # Generate Prisma client
pnpm studio # Open Prisma Studio
pnpm push # Push schema to database (no migration)
pnpm pull # Pull schema from databaseThe project is currently deployed on Railway. To deploy your own instance:
- Push your code to GitHub
- Connect your GitHub repository to Railway
- Configure environment variables in Railway dashboard
- Railway will automatically build and deploy
Ensure these environment variables are set in your production environment:
- NODE_ENV=production
- DATABASE_URL - Production PostgreSQL connection string
- BETTER_AUTH_SECRET - Strong random secret for auth
- BETTER_AUTH_URL - Production backend URL
- ACCESS_TOKEN_SECRET - Secret for access token generation
- REFRESH_TOKEN_SECRET - Secret for refresh token generation
- STRIPE_SECRET_KEY - Production Stripe secret key
- STRIPE_WEBHOOK_SECRET - Production webhook secret
- FRONTEND_URL - Production frontend URL
- BACKEND_URL - Production backend URL
- SSLCOMMERZ_STORE_ID - SSLCommerz store ID
- SSLCOMMERZ_STORE_PASSWORD - SSLCommerz store password
- SSLCOMMERZ_IS_SANDBOX=false - Set to false for production
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes following the project conventions
- Run linting (
pnpm lint) - Test your changes thoroughly
- Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Use TypeScript for all new code
- Follow the existing code structure and naming conventions
- Add type annotations for all functions and variables
- Use Zod for request validation
- Add API documentation for new endpoints in
/docs - Write clear, descriptive commit messages
nexdrop-backend/
├── prisma/
│ └── schema/ # Database schema files
├── src/
│ ├── app/
│ │ ├── config/ # Configuration files
│ │ ├── errorHelper/ # Error handling utilities
│ │ ├── lib/ # Library files (prisma, etc.)
│ │ ├── module/ # Feature modules
│ │ │ ├── address/
│ │ │ ├── analytics/
│ │ │ ├── auth/
│ │ │ ├── parcel/
│ │ │ ├── payment/
│ │ │ ├── rating/
│ │ │ ├── rider/
│ │ │ └── user/
│ │ ├── middleware/ # Express middleware
│ │ ├── routes/ # Route definitions
│ │ └── shared/ # Shared utilities
│ └── server.ts # Server entry point
├── docs/ # API documentation
├── public/ # Public files
├── .env.example # Environment variables template
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # This file
Issue: Prisma client not found
pnpm generateIssue: Database connection failed
- Check your
DATABASE_URLin.env - Ensure PostgreSQL is running
- Verify database credentials
Issue: Migration conflicts
pnpm pull
pnpm pushIssue: Build fails
pnpm install
pnpm generate
pnpm buildThis project is licensed under the ISC License.
- MD MHRZ - GitHub
- Built with modern web technologies
- Inspired by delivery management systems
- Uses open-source libraries and frameworks
For support, please open an issue on GitHub or contact the author.
Note: This project is under active development. Features and APIs may change as the project evolves.