Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

🛒 E-Commerce Backend API

A fully functional E-Commerce REST API built with Spring Boot, featuring JWT authentication, role-based access control, and PostgreSQL database.

🚀 Tech Stack

Technology Purpose
Java 17 Programming Language
Spring Boot 3.x Backend Framework
Spring Security Authentication & Authorization
JWT (JSON Web Token) Stateless Authentication
Spring Data JPA Database ORM
PostgreSQL Relational Database
Lombok Boilerplate Reduction
Maven Build Tool

✨ Features

  • ✅ User Registration & Login with JWT Authentication
  • ✅ BCrypt Password Hashing
  • ✅ Role-based Access Control (CUSTOMER / ADMIN)
  • ✅ Product Management with Categories
  • ✅ Product Search & Filter by Category
  • ✅ Shopping Cart (Add, Remove, Clear)
  • ✅ Order Management (Place, View, Cancel)
  • ✅ Order Status Tracking (PENDING → CONFIRMED → SHIPPED → DELIVERED)
  • ✅ Global Exception Handling with clean JSON error responses

📁 Project Structure

src/main/java/com/ecommerce/ ├── controller/ # REST API Controllers │ ├── AuthController │ ├── CategoryController │ ├── ProductController │ ├── CartController │ ├── OrderController │ └── UserController ├── service/ # Business Logic ├── repository/ # Spring Data JPA Repositories ├── entity/ # JPA Entities ├── dto/ # Data Transfer Objects ├── security/ # JWT Filter & Utility └── exception/ # Global Exception Handler

🔌 API Endpoints

Auth

Method Endpoint Description Auth Required
POST /api/auth/register Register new user No
POST /api/auth/login Login & get JWT token No
GET /api/users/me Get logged-in user profile Yes

Categories

Method Endpoint Description Auth Required
POST /api/categories Create category No
GET /api/categories Get all categories No
GET /api/categories/{id} Get category by ID No
PUT /api/categories/{id} Update category No
DELETE /api/categories/{id} Delete category No

Products

Method Endpoint Description Auth Required
POST /api/products?categoryId={id} Create product No
GET /api/products Get all products No
GET /api/products/{id} Get product by ID No
GET /api/products/category/{id} Get by category No
GET /api/products/search?name={name} Search products No
PUT /api/products/{id} Update product No
DELETE /api/products/{id} Delete product No

Cart (🔒 Requires JWT)

Method Endpoint Description
GET /api/cart View cart
POST /api/cart/add?productId={id}&quantity={n} Add to cart
DELETE /api/cart/remove?productId={id} Remove from cart
DELETE /api/cart/clear Clear cart

Orders (🔒 Requires JWT)

Method Endpoint Description
POST /api/orders?shippingAddress={address} Place order
GET /api/orders Get my orders
GET /api/orders/{id} Get order by ID
PUT /api/orders/{id}/cancel Cancel order
PUT /api/orders/{id}/status?status={status} Update status (Admin)

⚙️ Setup & Installation

Prerequisites

  • Java 17+
  • Maven 3.x
  • PostgreSQL 14+

Steps

  1. Clone the repository
git clone https://github.com/arunkp7/ecommerce-backend.git
cd ecommerce-backend
  1. Create PostgreSQL database
CREATE DATABASE ecommerce_db;
  1. Configure application properties
cp src/main/resources/application.properties.example src/main/resources/application.properties

Edit application.properties with your database credentials and JWT secret.

  1. Run the application
mvn spring-boot:run

The API will start at http://localhost:8080

🔐 Authentication

This API uses JWT Bearer Token authentication.

  1. Register or Login to get a token
  2. Include the token in request headers:

📊 Database Schema

users ──────────────── orders ──────── order_items │ │ └──── carts ────── cart_items └──── products ──── categories

🛠️ Built By

Arun Kumar Pal

GitHub

About

E-Commerce REST API built with Spring Boot, JWT Auth, PostgreSQL

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages