Skip to content

Ahmad-Zaki05/Order-Processing-System-Project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

110 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Order Processing System - Online Bookstore

Spring Boot Next.js MySQL TypeScript Java Docker

A comprehensive full-stack Online Bookstore Application with role-based access control, shopping cart functionality, PayPal payment integration, inventory management, and advanced sales analytics.

FeaturesTech StackInstallationAPI ReferenceDatabaseScreenshots


📋 Table of Contents


🎯 Overview

The Order Processing System is a modern e-commerce platform designed specifically for online book sales. It provides a seamless shopping experience for customers while offering powerful management tools for administrators.

Key Highlights

  • 🛒 Full E-commerce Flow - Browse, search, cart, and checkout
  • 💳 Dual Payment Options - PayPal integration & Cash on Delivery
  • 📊 Advanced Analytics - Sales reports, top customers, and best-selling books
  • 📦 Inventory Management - Automatic supply order generation when stock runs low
  • 👥 User Management - Role-based access with admin promotion/demotion
  • 🔐 Secure Authentication - JWT-based authentication with protected routes

✨ Features

🛍️ Customer Features

Feature Description
User Registration & Login Secure account creation with email verification and JWT authentication
Browse Books Explore the complete book catalog with detailed information
Advanced Search Search books by ISBN, title, category, author, or publisher
Book Categories Filter by Science, Art, Religion, History, and Geography
Shopping Cart Add, update quantities, and remove items from cart
Dual Checkout Choose between PayPal or Cash on Delivery
Order History View complete purchase history with order details
User Profile Manage personal information, addresses, and phone numbers

🔧 Admin Features

Feature Description
Dashboard Analytics Comprehensive sales overview and statistics
Book Management Add, modify, and update book inventory
Stock Management Update stock levels and set reorder thresholds
Author Management Add and manage book authors
Publisher Management Add and manage book publishers
User Management View all users, promote to admin, or demote to customer
Supply Orders Manage and confirm inventory replenishment orders
Sales Reports Generate reports for sales by date, top customers, and top books

📊 Reports & Analytics

Report Description
Previous Month Sales Total revenue generated in the last month
Sales by Date Revenue breakdown for any specific date
Top 5 Customers Highest spending customers in the last 3 months
Top 10 Books Best-selling books in the last 3 months
Replenishment Count Supply orders generated per book ISBN

🔄 Automated Features

  • Auto Supply Order Generation - When stock drops below threshold, automatically creates supply order
  • Stock Update on Confirmation - Confirming supply order automatically increases book stock
  • Cart Persistence - Shopping cart saved across sessions
  • Role-based Routing - Automatic redirect based on user role after login

🛠 Tech Stack

Frontend

Technology Version Purpose
Next.js 14.2.0 React framework with App Router
React 18.2.0 UI component library
TypeScript 5.x Type-safe JavaScript
Tailwind CSS 4.x Utility-first CSS framework
Redux Toolkit Latest State management
React Hook Form 7.66 Form handling with validation
Zod 4.1 Schema validation
Radix UI Latest Accessible UI primitives
Lucide React Latest Icon library
React Hot Toast Latest Notification system

Backend

Technology Version Purpose
Spring Boot 3.5.4 Java framework
Java 17 Programming language
Spring Data JPA - Database ORM
Spring Security - Authentication & authorization
JWT (jjwt) 0.11.5 Token-based authentication
MySQL Connector 8.0.33 Database driver
PayPal SDK 1.14.0 Payment processing
OpenPDF 1.3.30 PDF generation
Lombok - Boilerplate reduction
Maven 3.9+ Build tool

Database & Infrastructure

Technology Version Purpose
MySQL 8.0 Relational database
Docker Latest Containerization
Docker Compose Latest Multi-container orchestration

🏗 Architecture

┌─────────────────┐     ┌─────────────────┐     ┌─────────────────┐
│                 │     │                 │     │                 │
│    Frontend     │────▶│     Backend     │────▶│    Database     │
│   (Next.js)     │     │  (Spring Boot)  │     │    (MySQL)      │
│   Port: 3000    │     │   Port: 8080    │     │   Port: 3306    │
│                 │     │                 │     │                 │
└─────────────────┘     └─────────────────┘     └─────────────────┘
        │                       │                       │
        │                       │                       │
        ▼                       ▼                       ▼
   ┌─────────┐            ┌─────────┐            ┌─────────┐
   │  Redux  │            │   JWT   │            │ Triggers│
   │  Store  │            │  Auth   │            │ & Views │
   └─────────┘            └─────────┘            └─────────┘

Request Flow

  1. User → Interacts with Next.js Frontend
  2. Frontend → Sends API requests with JWT token to Spring Boot Backend
  3. Backend → Validates JWT, processes request, queries MySQL Database
  4. Database → Returns data, triggers execute for automated actions
  5. Backend → Returns JSON response to Frontend
  6. Frontend → Updates UI and Redux Store

🚀 Installation

Prerequisites

  • Docker & Docker Compose (for database)
  • Node.js 18+ and npm
  • Java 17 (JDK)
  • Maven 3.9+

Quick Start

1. Clone the Repository

git clone https://github.com/yourusername/Order-Processing-System-Project.git
cd Order-Processing-System-Project

2. Start the Database

# Start MySQL container
docker-compose up -d mysql-db

# Wait for database to initialize (check logs)
docker logs -f mysql-db-cont

3. Start the Backend

cd Backend

# Using Maven Wrapper (recommended)
./mvnw spring-boot:run

# Or with installed Maven
mvn spring-boot:run

The backend API will be available at http://localhost:8080

4. Start the Frontend

cd Frontend

# Install dependencies
npm install

# Start development server
npm run dev

The frontend will be available at http://localhost:3000

Docker (Full Stack)

# Build and start all services
docker-compose up -d

# View logs
docker-compose logs -f

⚙️ Configuration

Backend Configuration

Edit Backend/src/main/resources/application.properties:

# Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/bookstore
spring.datasource.username=root
spring.datasource.password=root

# JWT Configuration
jwt.secret=your-secret-key
jwt.expiration=604800000  # 7 days in milliseconds

# PayPal Configuration (Sandbox)
paypal.client.id=your-paypal-client-id
paypal.client.secret=your-paypal-client-secret
paypal.mode=sandbox

Frontend Configuration

Create Frontend/.env.local:

NEXT_PUBLIC_API_URL=http://localhost:8080/api

Database Configuration

The database is automatically initialized with:

  • Schema: Database/init.sql
  • Test Data: Database/test-data.sql

📡 API Reference

Authentication Endpoints

Method Endpoint Auth Description
POST /api/users/register Public Register new user
POST /api/users/login Public Login and get JWT
GET /api/users/me Required Get current user
POST /api/users/edit Required Update user profile
POST /api/users/logout Required Logout user

Book Endpoints

Method Endpoint Auth Description
GET /api/books Required List all books
GET /api/books/{isbn} Required Get book by ISBN
GET /api/books/search Required Search books
POST /api/books/add Admin Add new book
POST /api/books/{isbn}/image Admin Upload book image
POST /api/books/{isbn} Admin Update book details
POST /api/books/{isbn}/stock Admin Update stock level

Author & Publisher Endpoints

Method Endpoint Auth Description
GET /api/books/authors Required List all authors
GET /api/books/publishers Required List all publishers
POST /api/books/authors Admin Add new author
POST /api/books/publishers Admin Add new publisher

Cart & Checkout Endpoints

Method Endpoint Auth Description
GET /api/cart/view Required View cart contents
GET /api/cart/prices Required Get cart pricing
POST /api/cart Required Add item to cart
POST /api/cart/remove Required Remove item from cart
POST /api/cart/update Required Update item quantity
POST /api/cart/checkout Required PayPal checkout
POST /api/cart/checkout/execute Required Execute PayPal payment
POST /api/cart/checkout/cash Required Cash on delivery

Order Endpoints

Method Endpoint Auth Description
GET /api/cart/past-orders Required View order history
GET /api/cart/past-orders/details Required Detailed order history
GET /api/orders Admin List supply orders
POST /api/orders/confirm Admin Confirm supply order

User Management Endpoints

Method Endpoint Auth Description
GET /api/users Admin List all users
POST /api/users/promote Admin Promote user to admin
POST /api/users/demote Admin Demote admin to customer

Report Endpoints

Method Endpoint Auth Description
GET /api/reports/previous-month-sales Admin Last month total sales
GET /api/reports/sales Admin Sales for specific date
GET /api/reports/top-customers Admin Top 5 customers (3 months)
GET /api/reports/top-books Admin Top 10 books (3 months)
GET /api/reports/replenishment-count Admin Supply orders per book

🗄 Database Schema

Entity Relationship Diagram

┌──────────────┐       ┌──────────────┐       ┌──────────────┐
│  publishers  │───────│    books     │───────│   authors    │
│──────────────│  1:N  │──────────────│  N:M  │──────────────│
│ publisher_id │       │ isbn (PK)    │       │ author_id    │
│ name         │       │ title        │       │ name         │
│ address      │       │ category     │       └──────────────┘
└──────────────┘       │ price        │
                       │ stock        │       ┌──────────────┐
                       │ threshold    │       │ books_images │
                       │ restock_amt  │───────│──────────────│
                       └──────────────┘  1:N  │ image_url    │
                              │               └──────────────┘
                              │
                              ▼
┌──────────────┐       ┌──────────────┐       ┌──────────────┐
│    users     │───────│     cart     │───────│  cart_items  │
│──────────────│  1:1  │──────────────│  1:N  │──────────────│
│ user_id (PK) │       │ cart_id      │       │ isbn         │
│ email        │       │ user_id      │       │ quantity     │
│ password     │       │ total_amount │       │ price        │
│ role         │       └──────────────┘       └──────────────┘
│ first_name   │
│ last_name    │       ┌──────────────┐       ┌──────────────┐
└──────────────┘───────│  purchases   │───────│purchase_items│
             1:N       │──────────────│  1:N  │──────────────│
                       │ purchase_id  │       │ isbn         │
                       │ user_id      │       │ quantity     │
                       │ total_amount │       │ price        │
                       │ purchase_date│       └──────────────┘
                       └──────────────┘

┌──────────────┐
│supply_orders │
│──────────────│
│ order_id     │
│ isbn         │
│ quantity     │
│ status       │
│ order_date   │
└──────────────┘

Tables Overview

Table Description
users User accounts with roles (ADMIN/CUSTOMER)
user_phone_numbers Multi-valued phone numbers for users
user_addresses User shipping addresses
publishers Book publisher information
publishers_phone_numbers Publisher contact numbers
publishers_addresses Publisher branch addresses
authors Book author information
books Book catalog with inventory
books_authors Many-to-many book-author relationship
books_images Book cover images
cart User shopping carts
cart_items Items in shopping carts
purchases Completed orders
purchase_items Items in completed orders
supply_orders Inventory replenishment orders

Database Triggers

Trigger Event Action
trg_prevent_negative_stock BEFORE UPDATE on books Prevents stock from going negative
trg_auto_create_supply_order AFTER UPDATE on books Creates supply order when stock < threshold
trg_confirm_supply_order AFTER UPDATE on supply_orders Increases book stock when order confirmed

Constraints

  • Book Categories: Science, Art, Religion, History, Geography
  • User Roles: ADMIN, CUSTOMER
  • Supply Order Status: PENDING, CONFIRMED
  • Stock Level: Cannot be negative
  • Threshold/Restock Amount: Must be greater than 0

👥 User Roles & Permissions

Feature Customer Admin
Browse & Search Books
View Book Details
Shopping Cart
Checkout (PayPal/Cash)
View Order History
Edit Profile
Add New Books
Modify Books
Update Stock
Manage Authors
Manage Publishers
User Management
Promote/Demote Users
View Sales Reports
Manage Supply Orders

📁 Project Structure

Order-Processing-System-Project/
├── 📁 Backend/
│   ├── 📁 src/
│   │   ├── 📁 main/
│   │   │   ├── 📁 java/com/example/
│   │   │   │   ├── 📁 config/         # Security & JWT config
│   │   │   │   ├── 📁 controller/     # REST controllers
│   │   │   │   ├── 📁 dto/            # Data transfer objects
│   │   │   │   ├── 📁 entity/         # JPA entities
│   │   │   │   ├── 📁 repository/     # Data repositories
│   │   │   │   └── 📁 service/        # Business logic
│   │   │   └── 📁 resources/
│   │   │       └── application.properties
│   │   └── 📁 test/                   # Unit tests
│   ├── Dockerfile
│   ├── pom.xml
│   └── mvnw / mvnw.cmd
│
├── 📁 Frontend/
│   ├── 📁 src/
│   │   ├── 📁 app/                    # Next.js App Router
│   │   │   ├── 📁 (auth)/             # Auth pages (login/register)
│   │   │   ├── 📁 (dashboard)/        # Dashboard pages
│   │   │   │   ├── 📁 admin/          # Admin pages
│   │   │   │   └── 📁 customer/       # Customer pages
│   │   │   ├── layout.tsx
│   │   │   └── page.tsx
│   │   ├── 📁 components/             # React components
│   │   │   ├── 📁 admin/              # Admin-specific components
│   │   │   ├── 📁 forms/              # Form components
│   │   │   ├── 📁 layout/             # Layout components
│   │   │   ├── 📁 orders/             # Order components
│   │   │   ├── 📁 products/           # Product components
│   │   │   ├── 📁 reports/            # Report components
│   │   │   ├── 📁 redux/              # Redux store & slices
│   │   │   └── 📁 ui/                 # UI primitives
│   │   ├── 📁 services/               # API services
│   │   ├── 📁 types/                  # TypeScript types
│   │   ├── 📁 interfaces/             # TypeScript interfaces
│   │   ├── 📁 helpers/                # Utility functions
│   │   ├── 📁 lib/                    # Library configurations
│   │   └── middleware.ts              # Auth middleware
│   ├── package.json
│   ├── tsconfig.json
│   └── next.config.js
│
├── 📁 Database/
│   ├── Dockerfile
│   ├── init.sql                       # Schema creation
│   ├── test-data.sql                  # Sample data
│   └── ERD Code.txt                   # ER diagram source
│
├── docker-compose.yaml
└── README.md

🔐 Security Features

  • JWT Authentication - Stateless token-based authentication with 7-day expiration
  • Password Encryption - BCrypt hashing for secure password storage
  • Role-Based Access Control - Method-level security with @PreAuthorize
  • Protected Routes - Middleware-based route protection on frontend
  • CORS Configuration - Configured for cross-origin requests
  • Input Validation - Zod schemas on frontend, Hibernate Validator on backend

💳 Payment Integration

PayPal Integration

The system integrates with PayPal's REST API for secure payment processing:

  1. Create Payment - Initialize payment with cart items
  2. Redirect to PayPal - User approves payment on PayPal
  3. Execute Payment - Complete the transaction
  4. Order Confirmation - Cart converted to purchase record

Cash on Delivery

Alternative payment option for customers who prefer paying upon delivery.


🧪 Testing

Backend Tests

cd Backend
./mvnw test

Frontend Tests

cd Frontend
npm run test

📊 Monitoring & Logs

View Database Logs

docker logs -f mysql-db-cont

View Backend Logs

cd Backend
./mvnw spring-boot:run
# Logs appear in console

View Docker Container Status

docker-compose ps

🤝 Contributing

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

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.


👨‍💻 Authors


🙏 Acknowledgments

  • Spring Boot Documentation
  • Next.js Documentation
  • PayPal Developer Documentation
  • Tailwind CSS Documentation

⭐ Star this repository if you found it helpful!

About

Order Processing System project for the database course

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages