Skip to content

omix2003/CentralizedDeliveryNetwork

Repository files navigation

🚚 Centralized Delivery Network

A comprehensive delivery management platform connecting partners, agents, and administrators

Next.js Express TypeScript PostgreSQL Prisma

Features β€’ Installation β€’ Documentation β€’ API Reference β€’ Deployment


πŸ“‹ Table of Contents

🎯 Overview

Centralized Delivery Network is a full-stack delivery management platform that enables seamless coordination between delivery partners, agents, and administrators. The platform provides real-time tracking, order management, analytics, and comprehensive administrative tools.

Key Capabilities

  • πŸ”„ Real-time Order Management - Live order tracking and status updates
  • πŸ“ Location Tracking - Real-time agent location monitoring
  • πŸ”Œ REST API Integration - Partner API for seamless integrations
  • πŸ“Š Analytics Dashboard - Comprehensive metrics and insights
  • πŸ” Multi-role Authentication - Secure role-based access control
  • πŸ“± Mobile-Optimized - Responsive design for all devices

✨ Features

πŸ‘₯ For Partners

  • βœ… REST API for order creation and management
  • βœ… Webhook support for real-time order updates
  • βœ… Comprehensive dashboard with analytics
  • βœ… API key management and rotation
  • βœ… Order tracking and status monitoring
  • βœ… Performance metrics and reporting

🚴 For Agents

  • βœ… Real-time order notifications
  • βœ… Accept/reject order offers
  • βœ… Live location tracking
  • βœ… Order status updates (Pickup, Delivery, etc.)
  • βœ… Profile and document management
  • βœ… KYC verification system
  • βœ… Earnings and performance tracking
  • βœ… Mobile-optimized interface with collapsible sidebar

πŸ‘¨β€πŸ’Ό For Administrators

  • βœ… Live map view of all agents and orders
  • βœ… Agent approval and management
  • βœ… Partner account management
  • βœ… Order oversight and reassignment
  • βœ… KYC document verification
  • βœ… System-wide analytics dashboard
  • βœ… Support ticket management
  • βœ… Real-time system monitoring

πŸ› οΈ Tech Stack

Backend

Technology Purpose
Node.js 18+ Runtime environment
Express.js Web framework
TypeScript Type-safe development
PostgreSQL Primary database
Prisma ORM and database toolkit
Redis Caching and real-time data
Socket.io WebSocket for real-time updates
JWT Authentication
Multer File upload handling
Firebase Admin Push notifications

Frontend

Technology Purpose
Next.js 16 React framework with App Router
TypeScript Type-safe development
Tailwind CSS 4 Utility-first CSS framework
Axios HTTP client
Socket.io Client WebSocket client
Mapbox GL Interactive maps
Recharts Data visualization
NextAuth.js Authentication
Zod Schema validation

πŸ“ Project Structure

NextJS/
β”œβ”€β”€ backend/                    # Express.js API Server
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ controllers/        # Request handlers
β”‚   β”‚   β”œβ”€β”€ routes/            # API route definitions
β”‚   β”‚   β”œβ”€β”€ services/          # Business logic layer
β”‚   β”‚   β”œβ”€β”€ middleware/        # Auth, validation, error handling
β”‚   β”‚   β”œβ”€β”€ lib/               # External library configs
β”‚   β”‚   β”‚   β”œβ”€β”€ prisma.ts      # Prisma client
β”‚   β”‚   β”‚   β”œβ”€β”€ redis.ts       # Redis client
β”‚   β”‚   β”‚   β”œβ”€β”€ websocket.ts   # Socket.io server
β”‚   β”‚   β”‚   └── webhook.ts     # Webhook utilities
β”‚   β”‚   └── utils/             # Utility functions
β”‚   β”œβ”€β”€ prisma/
β”‚   β”‚   β”œβ”€β”€ schema.prisma      # Database schema
β”‚   β”‚   └── migrations/        # Database migrations
β”‚   └── uploads/               # File uploads directory
β”‚
β”œβ”€β”€ next-app/                  # Next.js Frontend Application
β”‚   β”œβ”€β”€ app/                   # Next.js App Router
β”‚   β”‚   β”œβ”€β”€ (admin)/          # Admin route group
β”‚   β”‚   β”œβ”€β”€ (agent)/          # Agent route group
β”‚   β”‚   β”œβ”€β”€ (partner)/        # Partner route group
β”‚   β”‚   └── (auth)/           # Authentication routes
β”‚   β”œβ”€β”€ components/            # React components
β”‚   β”‚   β”œβ”€β”€ layout/           # Layout components
β”‚   β”‚   β”œβ”€β”€ maps/             # Map components
β”‚   β”‚   β”œβ”€β”€ orders/           # Order components
β”‚   β”‚   └── ui/               # Reusable UI components
β”‚   β”œβ”€β”€ lib/                   # Utilities and helpers
β”‚   β”‚   β”œβ”€β”€ api/              # API client functions
β”‚   β”‚   └── utils/            # Helper functions
β”‚   └── public/                # Static assets
β”‚
└── docs/                      # Project documentation
    β”œβ”€β”€ API_DOCUMENTATION.md
    β”œβ”€β”€ DEPLOYMENT.md
    β”œβ”€β”€ PARTNER_INTEGRATION_GUIDE.md
    └── ...

πŸ“¦ Prerequisites

Before you begin, ensure you have the following installed:

  • Node.js 18+ (Download)
  • npm or yarn package manager
  • PostgreSQL 12+ (Download)
  • Redis (Optional, for caching and real-time features)
  • Git (Download)

Additional Services

  • Mapbox Account - For map features (Sign up)
  • Firebase Project - For push notifications (Optional)

πŸš€ Quick Start

# Clone the repository
git clone <repository-url>
cd NextJS

# Backend setup
cd backend
npm install
cp .env.example .env
# Edit .env with your configuration
npm run prisma:generate
npm run prisma:migrate
npm run dev

# Frontend setup (in a new terminal)
cd ../next-app
npm install
cp .env.local.example .env.local
# Edit .env.local with your configuration
npm run dev

Visit http://localhost:3000 to see the application.

πŸ“₯ Installation

Step 1: Clone Repository

git clone <repository-url>
cd NextJS

Step 2: Backend Setup

cd backend

# Install dependencies
npm install

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Set up database
npm run prisma:generate
npm run prisma:migrate

# (Optional) Seed database
npm run prisma:seed

Step 3: Frontend Setup

cd ../next-app

# Install dependencies
npm install

# Set up environment variables
cp .env.local.example .env.local
# Edit .env.local with your configuration

βš™οΈ Configuration

Backend Environment Variables

Create backend/.env:

# Server Configuration
NODE_ENV=development
PORT=5000

# Database
DATABASE_URL="postgresql://user:password@localhost:5432/delivery_network"

# Authentication
JWT_SECRET="your-super-secret-jwt-key-minimum-32-characters-long"

# CORS
CORS_ORIGIN="http://localhost:3000"

# Redis (Optional)
REDIS_ENABLED=true
REDIS_URL="redis://localhost:6379"

# Firebase (Optional)
FIREBASE_PROJECT_ID="your-project-id"
FIREBASE_PRIVATE_KEY="your-private-key"
FIREBASE_CLIENT_EMAIL="your-client-email"

Frontend Environment Variables

Create next-app/.env.local:

# API Configuration
NEXT_PUBLIC_API_URL="http://localhost:5000/api"

# Authentication
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="your-nextauth-secret-minimum-32-characters"

# Maps
NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN="pk.your-mapbox-token"

Generate Secure Secrets

# Generate JWT_SECRET
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

# Generate NEXTAUTH_SECRET
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"

πŸƒ Running the Application

Development Mode

Terminal 1 - Start Backend:

cd backend
npm run dev

Backend runs on http://localhost:5000

Terminal 2 - Start Frontend:

cd next-app
npm run dev

Frontend runs on http://localhost:3000

Production Mode

Build and Start Backend:

cd backend
npm run build
npm start

Build and Start Frontend:

cd next-app
npm run build
npm start

πŸ“š API Documentation

Base URLs

  • Development: http://localhost:5000/api
  • Production: https://your-backend-url.onrender.com/api

Authentication Methods

JWT Authentication (Web App)

Authorization: Bearer <jwt_token>

API Key Authentication (Partner API)

X-API-Key: pk_<your_api_key>

Quick API Examples

Register User:

curl -X POST http://localhost:5000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "john@example.com",
    "password": "securePassword123",
    "role": "AGENT"
  }'

Create Order (Partner API):

curl -X POST http://localhost:5000/api/partner-api/orders \
  -H "X-API-Key: pk_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "pickupLat": 28.7041,
    "pickupLng": 77.1025,
    "dropLat": 28.6139,
    "dropLng": 77.2090,
    "payoutAmount": 150.00,
    "priority": "HIGH"
  }'

Complete API Reference

πŸ“– See docs/API_DOCUMENTATION.md for complete API documentation.

🚒 Deployment

Quick Deployment Guide

See docs/QUICK_DEPLOY.md for fast-track deployment.

Detailed Deployment

See docs/DEPLOYMENT.md for comprehensive deployment instructions.

Deployment Platforms

  • Backend: Render.com (recommended)
  • Frontend: Netlify (recommended)
  • Database: Render PostgreSQL or external PostgreSQL
  • Redis: Render Redis or external Redis

Deployment Checklists

πŸ’» Development

Available Scripts

Backend Scripts

npm run dev              # Start development server with hot reload
npm run build            # Build for production
npm start                # Start production server
npm run prisma:generate  # Generate Prisma Client
npm run prisma:migrate   # Run database migrations
npm run prisma:studio    # Open Prisma Studio (database GUI)
npm run prisma:seed      # Seed database with sample data

Frontend Scripts

npm run dev              # Start development server
npm run build            # Build for production
npm start                # Start production server
npm run lint             # Run ESLint

Code Structure

  • Backend: MVC pattern with controllers, services, and routes
  • Frontend: Component-based architecture with Next.js App Router
  • Database: Prisma ORM with migrations
  • Real-time: Socket.io for WebSocket connections

Environment Setup

  1. Copy .env.example to .env in backend
  2. Copy .env.local.example to .env.local in next-app
  3. Fill in all required environment variables
  4. Run database migrations
  5. Start development servers

πŸ”’ Security

  • βœ… JWT Authentication - Secure token-based authentication
  • βœ… API Key Authentication - For partner integrations
  • βœ… Password Hashing - bcryptjs with salt rounds
  • βœ… CORS Protection - Configurable allowed origins
  • βœ… Input Validation - Zod and Express Validator
  • βœ… File Upload Validation - Type and size restrictions
  • βœ… Environment Variables - Sensitive data in .env files
  • βœ… SQL Injection Protection - Prisma ORM parameterized queries
  • βœ… XSS Protection - React's built-in XSS protection

πŸ—„οΈ Database

The application uses PostgreSQL with Prisma ORM.

Key Models

  • User - Authentication and user profiles
  • Agent - Delivery agent profiles and status
  • Partner - Partner accounts and API keys
  • Order - Delivery orders and tracking
  • Document - Agent KYC documents
  • SupportTicket - Support ticket management

Database Schema

See backend/prisma/schema.prisma for the complete schema definition.

Migrations

# Create a new migration
npm run prisma:migrate

# Apply migrations in production
npm run prisma:migrate:deploy

🌐 Real-time Features

  • WebSocket Support - Real-time order updates via Socket.io
  • Location Tracking - Real-time agent location updates
  • Order Notifications - Push notifications for order status changes
  • Live Map - Real-time map updates for admin dashboard

πŸ“± Mobile Support

The frontend is fully responsive with:

  • βœ… Collapsible Sidebar - Mobile-optimized navigation
  • βœ… Touch-Friendly UI - Optimized for mobile interactions
  • βœ… Responsive Design - Works seamlessly on all screen sizes
  • βœ… Progressive Web App - Can be installed on mobile devices

πŸ“– Documentation

All documentation is available in the docs/ directory:

Document Description
API_DOCUMENTATION.md Complete API reference
DEPLOYMENT.md Deployment guide
QUICK_DEPLOY.md Quick deployment reference
PARTNER_INTEGRATION_GUIDE.md Partner API integration
backend-deployment-checklist.md Backend deployment checklist
frontend-deployment-checklist.md Frontend deployment checklist

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Commit your changes (git commit -m 'Add some amazing feature')
  5. Push to the branch (git push origin feature/amazing-feature)
  6. Open a Pull Request

Development Guidelines

  • Follow TypeScript best practices
  • Write meaningful commit messages
  • Add tests for new features
  • Update documentation as needed
  • Follow the existing code style

πŸ“ License

This project is licensed under the ISC License.

πŸ†˜ Support

Need help? Check out:

🎯 Roadmap

  • Enhanced analytics and reporting
  • Mobile app (React Native)
  • Advanced route optimization
  • Multi-language support
  • Payment integration
  • SMS notifications
  • Advanced admin features
  • Automated testing suite
  • CI/CD pipeline

πŸ™ Acknowledgments


Built with ❀️ using Next.js, Express.js, and TypeScript

⬆ Back to Top

About

A Real-time centralized full stack application for delivery management.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages