A powerful, secure, and feature-rich Spring Boot-based e-commerce backend, built with modular architecture, role-based authentication, and complete RESTful APIs for managing products, carts, orders, payments, wishlist, users, and more.
- ๐ Features
- ๐ ๏ธ Tech Stack
- ๐ Authentication & Roles
- ๐งฉ Project Structure
- ๐ API Overview
- ๐ Getting Started
- ๐ฌ Sample Credentials
- ๐ฎ Postman Collection
- ๐ฉโ๐ป Author
- โ User Registration & Login with JWT Authentication
- ๐ฅ Role-Based Access for
USERandADMIN - ๐ฆ Product Management (CRUD + filtering, sorting, pagination)
- ๐ Shopping Cart (Add, update, remove, clear cart items)
- โค๏ธ Wishlist (Add/remove favorite products)
- ๐ณ Payment Simulation (Fake payment with order creation)
- ๐ฆ Order Placement & History
- ๐ Order Status Update by Admin (PROCESSING, SHIPPED, DELIVERED)
- ๐ง Global Exception Handling
- Spring Boot (REST APIs)
- Spring Security (JWT Auth)
- Spring Data JPA (Hibernate ORM)
- MySQL (Database)
- Lombok (Boilerplate reduction)
- Postman (API testing)
- Maven (Build tool)
- JWT-based stateless authentication
- Secure endpoints using Spring Security filters
@PreAuthorizefor method-level security- Roles:
USER: Can manage cart, wishlist, ordersADMIN: Can manage products and update order status
src โโโ main โ โโโ java โ โ โโโ org.ecommerce โ โ โโโ config # JWT & Security config โ โ โโโ controller # All REST controllers โ โ โโโ entity # JPA Entities (User, Product, CartItem, etc.) โ โ โโโ enums # Enum for OrderStatus โ โ โโโ exception # GlobalExceptionHandler โ โ โโโ repository # JPA Repositories โ โ โโโ service # Business logic โ โ โโโ util # JWT utilities โ โโโ resources โ โโโ application.properties โ โโโ data.sql
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register |
Register new user |
| POST | /api/auth/login |
Login & receive JWT token |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/products |
List products with filters/sorting |
| GET | /api/products/{id} |
Get product by ID |
| POST | /api/products |
Create product (Admin) |
| PUT | /api/products/{id} |
Update product (Admin) |
| DELETE | /api/products/{id} |
Delete product (Admin) |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/cart |
View cart items |
| POST | /api/cart |
Add item to cart |
| PUT | /api/cart/{itemId} |
Update item quantity |
| DELETE | /api/cart/{itemId} |
Remove item from cart |
| DELETE | /api/cart/clear |
Clear all cart items |
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/wishlist |
Get wishlist items |
| POST | /api/wishlist/{productId} |
Add product to wishlist |
| DELETE | /api/wishlist/{productId} |
Remove product from wishlist |
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/orders |
Place order (with fake payment) |
| GET | /api/orders |
View userโs order history |
| PUT | /api/orders/{id} |
Update status (Admin) |
- Java 17+
- MySQL
- Maven
- Clone the repo bash git clone https://github.com/your-username/ecommerce-backend.git cd ecommerce-backend
Configure DB in application.properties properties
spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_db spring.datasource.username=root spring.datasource.password=yourpassword
Build and Run bash mvn clean install mvn spring-boot:run
๐ฌ Sample Credentials Role Email Password User user@example.com user123 Admin admin@example.com admin123
๐ฉโ๐ป Author Built by Farheen