Shopping Cart Backend – Spring Boot + Spring Security + JWT
A fully functional and secure shopping cart backend built using Spring Boot, Spring Security, JWT, Spring Data JPA, and MySQL. This backend is capable of managing products, categories, images, and cart operations, along with secure authentication using JWT.
=> Core Functionality
- Full Crud for : Products, Categories and Images
- Relational Mapping using JPA : One-to-Many (Category → Products) , One-to-Many (Product → Images)
- Inventory management
- Search filters by : Category, brand, product name, category + brand, brand + name
=> Security
- User authentication using Spring Security
- JWT access tokens
- Secure API endpoints
=> Other Features
- Helper DTOs for Add/Update operations
- Repository pattern using Spring Data JPA
- Proper Exception Handling (ResourceNotFound, ProductNotFound, etc.)
=> Backend
- Spring Boot 3.x
- Hibernate ORM
- MySQL Database
- JWT Authentication
=> Build Tool : Maven
Prerequisites
- Java 17+
- Maven
- MySQL Server
Steps
-
Clone the repository: git clone https://github.com/dhruvj7/Shopping-app.git
-
Configure your database in application.properties:
- spring.datasource.url=jdbc:mysql://localhost:3306/dreamshopsdb
- spring.datasource.username=root
- spring.datasource.password=yourpassword
- spring.jpa.show-sql=true
- spring.jpa.hibernate.ddl-auto=update
-
Create Database
CREATE DATABASE dreamshopsdb; -
Build and run
mvn spring-boot:run
-
Register User
POST /api/auth/registerSample payload : { "name": "John Doe", "email": "john@example.com", "password": "password123" }
Response: { "id": 1, "email": "john@example.com", "message": "User registered successfully" }
-
Get All Products
GET /api/productsSample response :
[ { "id": 1, "name": "Laptop", "brand": "Dell", "price": 70000 INR, "description": "Handu computer", "categoryId": 3, "images": [] } ]
and many more ....
Dhruv Jain
dhruvjain076@gmail.com