A fully functional E-Commerce REST API built with Spring Boot, featuring JWT authentication, role-based access control, and PostgreSQL database.
| 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 |
- ✅ 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
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
| 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 |
| 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 |
| 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 |
| 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 |
| 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) |
- Java 17+
- Maven 3.x
- PostgreSQL 14+
- Clone the repository
git clone https://github.com/arunkp7/ecommerce-backend.git
cd ecommerce-backend- Create PostgreSQL database
CREATE DATABASE ecommerce_db;- Configure application properties
cp src/main/resources/application.properties.example src/main/resources/application.propertiesEdit application.properties with your database credentials and JWT secret.
- Run the application
mvn spring-boot:runThe API will start at http://localhost:8080
This API uses JWT Bearer Token authentication.
- Register or Login to get a token
- Include the token in request headers:
users ──────────────── orders ──────── order_items │ │ └──── carts ────── cart_items └──── products ──── categories
Arun Kumar Pal