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.
- 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
- 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)
src
├── controller
├── service
│ └── impl
├── repository
├── entity
├── dto
├── mapper
├── exception
├── common
├── security
└── config
The API uses JWT-based authentication with Spring Security.
-
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.
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.
git clone https://github.com/zeynep4713/ecommerce-backend.gitCreate 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_passwordmvn spring-boot:runor run the main application class directly from your IDE.
| Method | Endpoint | Description |
|---|---|---|
| POST | /auth/login |
Authenticate user and obtain JWT token |
| 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 |
| 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 |
| 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 |
Examples:
GET /products?page=0&size=5
GET /products?page=0&size=5&sort=price
GET /products?page=0&size=5&sort=price,desc
- Order Management
- Advanced Filtering
- Unit & Integration Tests
- Docker Support
- GitHub Actions CI/CD
This project is intended for educational and portfolio purposes.
Zeynep Nur Yılmaz