Skip to content

AryaPathrikar/crowdsourced_delivery

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Crowdsourced Delivery System

A full-stack application that allows daily commuters to earn money by delivering packages on their way to their destination. Customers can create delivery requests, and commuters can accept and complete deliveries while earning money.

πŸ—οΈ Tech Stack

  • Backend: Java Spring Boot 3.2.0 (REST API)
  • Frontend: React.js 18.2.0
  • Database: PostgreSQL
  • Authentication: JWT (JSON Web Tokens)
  • Maps: Leaflet + OpenStreetMap

✨ Features

Backend

  • MVC Architecture (Controllers β†’ Services β†’ Repositories)
  • JWT Authentication with Spring Security
  • Role-based Access Control (CUSTOMER, COMMUTER, ADMIN)
  • Design Patterns: Strategy, Template Method, Observer, Factory
  • Dynamic Pricing: Base price + per-km + surge pricing based on demand
  • Event-driven notifications
  • Global exception handling
  • Input validation

Frontend

  • User authentication (Login/Register)
  • Customer dashboard (create deliveries, view maps, price breakdown)
  • Commuter dashboard (accept deliveries, update status)
  • Real-time notifications (pop-ups + sidebar)
  • Interactive maps with route visualization
  • Distance and ETA calculations

πŸ“‹ Prerequisites

  • Java 17+
  • Maven 3.6+
  • Node.js 14+
  • PostgreSQL 12+ (or Docker)

πŸš€ Quick Start

1. Database Setup

# Create database
psql -U <your_username> postgres
CREATE DATABASE crowd_delivery_db;
CREATE USER crowd_user WITH PASSWORD 'password';
GRANT ALL PRIVILEGES ON DATABASE crowd_delivery_db TO crowd_user;
\q

Or use Docker:

docker run --name postgres-crowd-delivery \
  -e POSTGRES_PASSWORD=password \
  -e POSTGRES_USER=crowd_user \
  -e POSTGRES_DB=crowd_delivery_db \
  -p 5432:5432 -d postgres:14

2. Backend

cd crowdsourced_delivery

# Update database credentials in src/main/resources/application.yml if needed

# Run application
mvn clean install
mvn spring-boot:run

Backend runs on http://localhost:8080

3. Frontend

cd frontend
npm install
npm start

Frontend runs on http://localhost:3000

Note: Tables (users, deliveries, notifications) are created automatically by JPA on first run.

πŸ“ Project Structure

crowdsourced_delivery/
β”œβ”€β”€ src/main/java/com/crowddelivery/
β”‚   β”œβ”€β”€ controller/      # REST Controllers
β”‚   β”œβ”€β”€ service/         # Business Logic (includes design patterns)
β”‚   β”œβ”€β”€ repository/      # JPA Repositories
β”‚   β”œβ”€β”€ entity/          # JPA Entities (User, Delivery, Notification)
β”‚   β”œβ”€β”€ dto/             # Data Transfer Objects
β”‚   β”œβ”€β”€ security/        # JWT & Security
β”‚   β”œβ”€β”€ event/           # Event classes (Observer pattern)
β”‚   β”œβ”€β”€ listener/        # Event listeners
β”‚   └── util/            # Utilities (DistanceCalculator)
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/  # React components (maps, notifications)
β”‚   β”‚   β”œβ”€β”€ pages/       # Page components
β”‚   β”‚   β”œβ”€β”€ services/    # API services
β”‚   β”‚   └── hooks/       # Custom hooks
└── pom.xml

πŸ—„οΈ Database Schema

3 tables created automatically:

  • users: id, email, password, name, phone, role, created_at
  • deliveries: id, customer_id, commuter_id, pickup/drop locations & coordinates, price, status, timestamps
  • notifications: id, user_id, delivery_id, title, message, type, is_read, created_at

πŸ”Œ API Endpoints

Authentication (Public)

  • POST /api/auth/register - Register user
  • POST /api/auth/login - Login and get JWT token

Customer (CUSTOMER role)

  • POST /api/customer/deliveries - Create delivery (price auto-calculated)
  • GET /api/customer/deliveries - Get my deliveries
  • GET /api/customer/deliveries/calculate-price - Calculate price before creation
  • PUT /api/customer/deliveries/{id}/status?status=CANCELLED - Cancel delivery

Commuter (COMMUTER role)

  • GET /api/commuter/deliveries/open - View open deliveries
  • POST /api/commuter/deliveries/{id}/accept - Accept delivery
  • GET /api/commuter/deliveries - Get my deliveries
  • PUT /api/commuter/deliveries/{id}/status?status=PICKED_UP - Update status
  • PUT /api/commuter/deliveries/{id}/status?status=DELIVERED - Mark delivered

Notifications (Authenticated)

  • GET /api/notifications - Get all notifications
  • GET /api/notifications/unread - Get unread notifications
  • GET /api/notifications/count - Get unread count
  • PUT /api/notifications/{id}/read - Mark as read

πŸ’° Pricing System

Base Pricing:

  • Base Price: $5.00
  • Price per km: $2.50/km
  • Formula: Price = Base + (Distance Γ— $2.50)

Surge Pricing (based on open deliveries):

  • 0-9 deliveries: No surge (1.0x)
  • 10-19 deliveries: Low surge (1.2x = +20%)
  • 20-29 deliveries: Medium surge (1.5x = +50%)
  • 30+ deliveries: High surge (2.0x = +100%)

Final Price: (Base + Distance Price) Γ— Surge Multiplier

Prices are automatically calculated when coordinates are provided.

🎨 Design Patterns

  • Strategy Pattern: MatchingStrategy interface with implementations
  • Template Method Pattern: DeliveryService.updateDeliveryStatus() workflow
  • Observer Pattern: Event-driven notifications (DeliveryCreatedEvent, DeliveryStatusChangedEvent)
  • Factory Pattern: JWT token generation in JwtTokenProvider

🎯 User Flow

Customer:

  1. Register/Login β†’ Create delivery β†’ System calculates price β†’ View deliveries β†’ Receive notifications

Commuter:

  1. Register/Login β†’ View open deliveries β†’ Accept delivery β†’ Update status (PICKED_UP β†’ DELIVERED) β†’ Receive notifications

πŸ” Authentication

  • JWT tokens required for all endpoints except /api/auth/**
  • Tokens expire after 24 hours
  • Include in header: Authorization: Bearer <token>
  • Passwords hashed with BCrypt

πŸ“ Configuration

Backend (src/main/resources/application.yml):

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/crowd_delivery_db
    username: crowd_user
    password: password
  jpa:
    hibernate:
      ddl-auto: update

server:
  port: 8080

jwt:
  secret: yourSecretKeyShouldBeAtLeast256BitsLongForHS512AlgorithmMakeItLongerForProduction
  expiration: 86400000  # 24 hours

Frontend (frontend/src/services/api.js):

  • API base URL: http://localhost:8080/api

πŸ§ͺ Testing

# Register
curl -X POST http://localhost:8080/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"name":"John","email":"john@test.com","password":"pass123","role":"CUSTOMER"}'

# Login
curl -X POST http://localhost:8080/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"john@test.com","password":"pass123"}'

🚧 Future Enhancements

  • Email notifications
  • Real-time location tracking
  • Rating system
  • Payment integration
  • Admin dashboard
  • Mobile app

πŸ“„ License

Open source for educational purposes.


Built with ❀️ using Spring Boot and React

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors