Skip to content

Repository files navigation

Spring Cart API

A production‑ready RESTful service for managing products, shopping carts and their items, built with Spring Boot 3.4.x.

JavaSpring BootLicense: MIT


Table of Contents

  1. Features

  2. Tech Stack

  3. Getting Started

    1. Prerequisites
    2. Clone & Configure
    3. Run Locally
    4. Run with Docker / Compose
  4. API Reference

  5. Database Migration

  6. Testing

  7. Common Issues & Tips

  8. Contributing

  9. License


Features

  • CRUD operations for products, carts, and cart items.
  • JWT authentication with role‑based authorization (admin / user).
  • Validation using Jakarta Bean Validation.
  • Pagination & filtering query parameters.
  • Rate limiting (10 requests / 10 seconds) on product catalogue.
  • OpenAPI 3 documentation via Swagger UI.
  • Flyway database migrations.
  • MapStruct DTO mapping & Lombok boilerplate reduction.
  • Environment configuration with spring‑dotenv.
  • Ready‑to‑use Dockerfile & example docker‑compose.yml.

Tech Stack

LayerTechnology
LanguageJava 17
FrameworkSpring Boot 3.4.5
Build ToolMaven
DatabaseMySQL 8.x
MigrationsFlyway
AuthSpring Security + JWT (jjwt)
Docsspringdoc‑openapi / Swagger UI
Object MappingMapStruct
BoilerplateLombok

Getting Started

Prerequisites

# Recommended versions
java --version # 17+
mvn -v # Maven 3.9+
mysql --version # 8+

Clone & Configure

git clone https://github.com/DemchaAV/Spring-Cart-API.git
cd Spring-Cart-API
cp .env.example .env # adjust credentials

Environment variables (excerpt)

KeyExamplePurpose
DB_URLjdbc:mysql://localhost:3306/store_apiJDBC connection string
DB_USERNAMErootDB user
DB_PASSWORDsecretDB password
JWT_SECRETchange_meHS256 signing key

Run Locally

mvn spring-boot:run
# Swagger UI → http://localhost:8080/swagger-ui.html

Run with Docker / Compose

Build a standalone image:

docker build -t spring-cart-api .
docker run -p 8080:8080 --env-file .env spring-cart-api

Or spin everything up with Compose:

version: "3.8"services:
api:
build: .ports:
- "8080:8080"env_file: .envdepends_on:
- mysqlmysql:
image: mysql:8environment:
MYSQL_ROOT_PASSWORD: rootMYSQL_DATABASE: store_apivolumes:
- db-data:/var/lib/mysqlvolumes:
db-data:

API Reference

MethodEndpointDescription
GET/api/v1/productsList / filter products
POST/api/v1/products (admin)Create a new product
POST/api/v1/auth/loginObtain JWT access token
POST/api/v1/cartsCreate a cart for current user
POST/api/v1/cart-productsAdd product to cart
DELETE/api/v1/cart-products/{id}Remove item from cart

Full contract is available in the Swagger UI.


Database Migration

Flyway automatically applies migrations found in src/main/resources/db/migration at startup.

To create & apply a new migration manually:

mvn flyway:migrate -Dflyway.locations=filesystem:src/main/resources/db/migration

Testing

mvn test

Common Issues & Tips

Access Denied? – Make sure you send the Authorization: Bearer <token> header.

MySQL connection errors – Check your .env credentials and verify that the database container is healthy.


Contributing

  1. Fork the project and create your feature branch:

    git checkout -b feat/awesome
  2. Commit your changes using conventional commits.

  3. Test: make sure mvn test passes.

  4. Open a PR describing your changes.

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.


License

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


Quick Start (Compose)

docker compose up --build

Enjoy building with Spring Cart API! 🎉

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages