Skip to content

Latest commit

 

History

21 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Electronics Shop API

Java CI

Java Spring Boot Spring Security MySQL MapStruct Swagger License: MIT

A REST API backend for an online electronics components shop, built with Spring Boot.

About The Project

A Spring Boot REST API for an electronics e-commerce platform featuring JWT authentication, product catalog management, order processing, and role-based authorization. Built as a portfolio project focused on clean architecture and backend best practices.

Features

  • Authentication & Authorization — JWT authentication with role-based authorization
  • Product Catalog — CRUD for products and categories with filtering and pagination
  • Order Management — stock validation, price snapshotting, and controlled status transitions
  • Ownership-based Access Control — customers can access only their own orders, while admins have full access
  • Centralized Exception Handling — consistent JSON error responses
  • Bean Validation — request validation
  • API Documentation — interactive Swagger UI with built-in JWT bearer token support
  • Unit Tests — Mockito-based unit test coverage for core service logic (orders, auth, products, categories, JWT)

Tech Stack

  • Language: Java 21
  • Framework: Spring Boot 4
  • Security: Spring Security, JWT (jjwt)
  • Persistence: Spring Data JPA, MySQL
  • Mapping: MapStruct
  • Documentation: springdoc-openapi (Swagger UI)
  • Testing: JUnit 5, Mockito, AssertJ
  • Build Tool: Maven

Getting Started

Prerequisites

  • Java 21 or higher
  • Maven
  • MySQL Server

Installation

  1. Clone the repository:
git clone https://github.com/TheNa3ik/electronics-shop-api.git
cd electronics-shop-api
  1. Rename application.properties.example to application.properties and configure your database credentials and JWT secret.
spring.application.name=electronics-shop-api

# Database Connection
spring.datasource.url=jdbc:mysql://localhost:3306/YOUR_DB_NAME
spring.datasource.username=YOUR_DB_USER
spring.datasource.password=YOUR_DB_PASSWORD

# JWT Configuration — use a random string at least 256 bits (32+ characters) long
jwt.secret=YOUR_JWT_SECRET
jwt.expiration-ms=86400000

spring.jpa.hibernate.ddl-auto=update
  1. Build and run the application:
./mvnw clean install
./mvnw spring-boot:run

The API will be available at http://localhost:8080.

API Documentation

Swagger UI is available at:

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

Authenticate via /api/v1/auth/login or /api/v1/auth/register, copy the JWT, and authorize in Swagger UI.

Key Endpoints

Method Endpoint Description Access
POST /api/v1/auth/register Register a new user Public
POST /api/v1/auth/login Log in and receive a JWT Public
GET /api/v1/products List products (paginated, filterable) Public
POST /api/v1/products Create a product Admin
GET /api/v1/categories List categories (paginated) Public
POST /api/v1/categories Create a category Admin
POST /api/v1/orders Place an order Authenticated
GET /api/v1/orders/my View your own orders Authenticated
GET /api/v1/orders/{orderId} View a specific order Owner or Admin
GET /api/v1/orders List all orders (filterable) Admin
PATCH /api/v1/orders/{orderId}/status Update order status Admin

Full request/response schemas and all remaining endpoints are available in Swagger UI.

Running Tests

./mvnw test

What I Learned

This project was built as a hands-on way to learn backend fundamentals beyond basic CRUD:

  • Designing a layered Spring Boot architecture
  • Implementing JWT authentication and role-based authorization
  • Handling business logic that spans multiple entities (stock decrement, price snapshotting, ownership checks)
  • Writing centralized exception handling for consistent API error responses
  • Unit testing service logic with Mockito, including mocking Spring Security context

License

Distributed under the MIT License. See LICENSE for more information.

About

Spring Boot e-commerce REST API featuring JWT authentication, role-based authorization, product management, and order processing

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Contributors

Languages