Skip to content

Repository files navigation

🚀 Checkout System – Microservices Architecture (Spring Boot)

An end-to-end E-Commerce Checkout System built using Spring Boot Microservices, Spring Security + JWT, MongoDB Atlas, and Spring Cloud API Gateway.

This project simulates a real-world checkout workflow with independent microservices for Authentication, Products, Cart, Inventory, Orders, and Gateway routing.

📌 Features Implemented

✔ JWT Authentication (Register + Login + Refresh Token) ✔ Product listing & fetching ✔ Add to Cart / Remove from Cart ✔ Apply Coupons ✔ Checkout → Create Order ✔ Stock Reservation via Inventory Service ✔ Order Status Flow: RESERVED → PAID → SHIPPED → DELIVERED ✔ API Gateway Security + Routing ✔ Full Unit Tests (2+ per functionality)

📁 Microservice Overview Checkout-System/ ├── API-Gateway/ ├── Auth-service/ ├── Cart-Service/ ├── Inventory-Service/ ├── Order-Service/ ├── Product-service/ └── README.md

Each module contains:

Independent Spring Boot Application

application.yaml

Unit Tests

Dedicated business logic

🧰 Tech Stack Category Technology Backend Framework Spring Boot 3.4 API Gateway Spring Cloud Gateway Authentication JWT, Spring Security Database MongoDB Atlas Testing JUnit 5, Mockito, MockMvc Build Tool Maven Architecture Microservices ⚙️ Requirements Before Starting

Make sure you have:

✔ Java 21 or higher ✔ Maven 3.8+ ✔ MongoDB Atlas (or local MongoDB) ✔ IntelliJ IDEA (recommended) ✔ Internet Connection (for dependencies) 🔧 Environment Variables & Config

Each microservice uses its own application.yaml.

MongoDB Config (required for all services) spring: data: mongodb: uri: mongodb+srv://:@cluster.mongodb.net database:

JWT Config (Auth + Gateway + All Services) jwt: secret: "your-secret-key-here" expiryMs: 3600000

Inter-Service URLs

These must be present in:

Cart-Service: PRODUCT_SERVICE: http://localhost:8082 ORDER_SERVICE: http://localhost:8084

Order-Service: PRODUCT_SERVICE: http://localhost:8082 INVENTORY_SERVICE: http://localhost:8085

📦 How to Set Up & Run the Project (Step-by-Step)

You MUST start services in the correct order. Follow these steps exactly for the project to work.

1️⃣ Clone the Repository git clone https://github.com/Shiwans60/checkout-system.git cd checkout-system

2️⃣ Run Each Microservice Individually

Open IntelliJ IDEA → right-click each module → Run.

Or run from terminal:

Start Auth-Service (Port 8081) cd Auth-service mvn spring-boot:run

Use this to register/login and get a JWT.

Start Product-Service (Port 8082) cd Product-service mvn spring-boot:run

Add example products to DB.

Start Inventory-Service (Port 8085) cd Inventory-Service mvn spring-boot:run

Add stock:

POST /api/inventory/add/{productId}/{qty}

Start Order-Service (Port 8084) cd Order-Service mvn spring-boot:run

Handles order creation & workflow.

Start Cart-Service (Port 8083) cd Cart-Service mvn spring-boot:run

Handles cart operations + checkout.

Start API-Gateway (Port 8080) cd API-Gateway mvn spring-boot:run

This becomes the main entry point for all external requests.

🧪 Running Unit Tests Run ALL tests: mvn test

Run tests in a specific microservice: cd Cart-Service mvn test

Expected output:

Tests run: X, Failures: 0, Errors: 0, Skipped: 0

🔄 Functional Flow Explanation 🛒 Add Item to Cart

Cart-Service:

Validates product using Product-Service

Adds item to user's cart

💳 Checkout

Cart-Service:

Builds CreateOrderRequest

Forwards JWT to Order-Service

Order-Service:

Fetches product details

Calls Inventory-Service → reserve stock

Saves order in MongoDB

📦 Order Workflow RESERVED → PAID → SHIPPED → DELIVERED

📘 API Examples 1️⃣ Register User POST /api/auth/register { "name": "John", "email": "john@gmail.com", "password": "pass123" }

2️⃣ Login & Get JWT POST /api/auth/login { "email": "john@gmail.com", "password": "pass123" }

3️⃣ Add Item to Cart POST /api/cart/add Authorization: Bearer { "productId": "p1", "quantity": 2 }

4️⃣ Checkout POST /api/cart/checkout Authorization: Bearer

Response:

{ "orderId": "64e912b...", "message": "Order created successfully" }

🔐 Security Overview

Every service uses JWT authentication.

API Gateway validates the token before routing requests.

Downstream services use RestTemplate and propagate JWT via headers.

⭐ Tech Stack

Spring Boot 3.4

Spring MVC

Spring Data MongoDB

Spring Cloud API Gateway

Spring Security

RestTemplate / HTTP Clients

Authentication & Authorization

JWT (JSON Web Token)

Custom Security Filters

Role-based Access Control

Database & Cloud Integration

MongoDB Atlas Cloud

MongoDB Repositories

Cloud connection using SRV connection strings

Architecture

Microservices Architecture

Service-to-Service Communication

API Gateway Routing & Filtering

Centralized JWT Validation

Testing

JUnit 5

Mockito

MockMvc

Spring Test Context

Build & Deployment

Maven

IntelliJ IDEA

(Optional) Docker support can be added.

🏗 High Level Design (HLD) Key HLD Points

API Gateway is the entry point for all external requests.

All services communicate independently through REST.

JWT is validated at the Gateway before routing.

Inventory Service handles stock checks & reservations.

Order Service handles order creation, payments & state transitions.

Cart Service orchestrates checkout flow.

MongoDB Atlas Cloud stores data for all microservices.

🧩 Low Level Design (LLD)

  1. Authentication Flow (LLD) [User] → POST /auth/login → Auth-Service validates credentials → Generates JWT (userId, roles, expiry) → Returns token to client

[Client] → Sends token in Authorization: Bearer [API Gateway] → Validates token via JwtAuthFilter → Adds userId to request headers → Routes to downstream services

Key LLD Components

JwtAuthenticationFilter (API-Gateway)

JwtUtil for token signing & verification

Spring Security chain to enforce protected endpoints

About

A production-style Spring Boot microservices architecture for an e-commerce checkout flow. Includes JWT authentication, API Gateway, secure inter-service communication, MongoDB Atlas cloud integration, and modular services for Cart, Orders, Products, Inventory, and Auth. Built with real system design principles, scalable structure, and unit tests

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages