Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

E-Commerce Backend API

Java Spring Boot MySQL Maven

A RESTful e-commerce backend application built with Spring Boot. The project demonstrates modern backend development practices including layered architecture, DTO-based request and response handling, validation, exception handling, authentication, role-based authorization, searching, filtering, pagination, sorting, and API documentation with Swagger.

Features

  • User registration and management
  • JWT-based authentication
  • Role-based authorization with USER and ADMIN roles
  • Secure password hashing with BCrypt
  • Category CRUD operations
  • Product CRUD operations
  • Product search by keyword (name and description)
  • Filter products by category
  • Pagination
  • Sorting
  • Request validation
  • Global exception handling
  • Custom exception classes
  • Category–Product relationship (Many-to-One)
  • DTO-based request and response handling
  • MapStruct for Entity-DTO mapping
  • Swagger / OpenAPI documentation

Technologies

  • Java 21 (LTS)
  • Spring Boot 4.0.7
  • Spring Web MVC
  • Spring Data JPA
  • Spring Security
  • JWT
  • MySQL
  • Maven
  • Lombok
  • MapStruct
  • Jakarta Validation
  • SpringDoc OpenAPI (Swagger)

Project Structure

src
├── controller
├── service
│   └── impl
├── repository
├── entity
├── dto
├── mapper
├── exception
├── common
├── security
└── config

Authentication & Authorization

The API uses JWT-based authentication with Spring Security.

Roles

  • USER

    • View products
    • View categories
  • ADMIN

    • All USER permissions
    • Create, update, and delete products
    • Create, update, and delete categories
    • Manage users

Newly registered users are assigned the USER role by default.

Passwords are securely stored using BCrypt hashing.

API Documentation

After starting the application, the interactive Swagger UI is available at:

http://localhost:8080/swagger-ui/index.html

The Swagger UI can be used to explore and test the API endpoints. Authenticated endpoints require a valid JWT token using the Authorize button.

Running the Project

1. Clone the repository

git clone https://github.com/zeynep4713/ecommerce-backend.git

2. Configure MySQL

Create a MySQL database (e.g. ecommerce) and update the application.yaml file with your own database credentials.

Example:

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/ecommerce
    username: your_username
    password: your_password

3. Run the application

mvn spring-boot:run

or run the main application class directly from your IDE.

Available Endpoints

Authentication

Method Endpoint Description
POST /auth/login Authenticate user and obtain JWT token

Users

Method Endpoint Description
POST /users Register a new user
GET /users Get all users
GET /users/{id} Get user by id
GET /users/username/{username} Get user by username
PUT /users/{id} Update user
DELETE /users/{id} Delete user

Categories

Method Endpoint Description
POST /categories Create category
GET /categories Get all categories
GET /categories/{id} Get category by id
PUT /categories/{id} Update category
DELETE /categories/{id} Delete category

Products

Method Endpoint Description
POST /products Create product
GET /products Get products (supports pagination & sorting)
GET /products/{id} Get product by id
PUT /products/{id} Update product
DELETE /products/{id} Delete product
GET /products/search?keyword=... Search products

Pagination & Sorting

Examples:

GET /products?page=0&size=5
GET /products?page=0&size=5&sort=price
GET /products?page=0&size=5&sort=price,desc

Future Improvements

  • Order Management
  • Advanced Filtering
  • Unit & Integration Tests
  • Docker Support
  • GitHub Actions CI/CD

License

This project is intended for educational and portfolio purposes.

Author

Zeynep Nur Yılmaz

About

RESTful e-commerce backend API built with Spring Boot, Spring Data JPA, Spring Security and JWT, with MySQL, MapStruct and Swagger/OpenAPI.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages