Skip to content

iRahmanG/Ecommerce-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 

Repository files navigation

Ecommerce Backend

A Production-Ready Spring Boot E-Commerce REST API

Ecommerce Backend is a secure, scalable RESTful backend system built using Spring Boot, implementing authentication, cart management, order processing, optimistic locking, and role-based access control—designed using clean architecture principles.

Focused on real-world backend practices such as JWT authentication, transactional consistency, DTO mapping, and layered architecture, this project demonstrates enterprise-grade backend development using Java and Spring.

FeaturesArchitectureTech StackGetting Started


Project Overview

Many beginner backend projects only implement basic CRUD operations without handling real-world concerns like authentication, transactional integrity, or concurrency control.

Ecommerce Backend was built to demonstrate:

  • Secure JWT-based authentication
  • Role-based authorization (ADMIN / USER)
  • Cart-to-order transactional workflow
  • Optimistic locking for inventory protection
  • DTO-based API design (no entity exposure)
  • Clean layered architecture

This project focuses on correct domain modeling, consistency, and production-level backend structure.


Architecture & Flow

graph TD
    A[Client / Frontend] --> B[Controller Layer]
    B --> C[Service Layer]
    C --> D[Repository Layer]
    D --> E[(Database)]
    C --> F[Security Layer - JWT]
    F --> B
Loading

Architectural Highlights

  • Layered Architecture (Controller → Service → Repository)
  • DTO Pattern for request/response separation
  • JWT Authentication & Role-Based Authorization
  • Transactional Order Processing
  • Optimistic Locking for Inventory Safety
  • Global Exception Handling

Key Features

Authentication & Authorization

  • JWT-based authentication
  • Role-based access control (ADMIN / USER)
  • Secure password hashing
  • Protected endpoints using Spring Security

Product Management

  • Create products (Admin only)
  • Delete products (Admin only)
  • Fetch product list
  • Inventory tracking with stock management

Cart Management

  • Add product to cart
  • Remove product from cart
  • View cart items
  • Quantity validation
  • Price captured at time of adding (priceAtAdd logic)

Order Processing

  • Convert cart into order
  • Transaction-safe order placement
  • Stock validation before order confirmation
  • Order entity linked with user

Inventory Safety

  • Optimistic locking using @Version
  • Prevents overselling during concurrent orders
  • Automatic rollback on failure

Clean API Design

  • DTO-based input/output
  • Validation annotations
  • Meaningful HTTP status codes
  • Centralized exception handling

Tech Stack & Architecture

Core Technologies

  • Language: Java
  • Framework: Spring Boot
  • Build Tool: Maven
  • Database: MySQL / H2 (configurable)
  • ORM: Spring Data JPA (Hibernate)

Spring Modules Used

  • Spring Web – REST API development
  • Spring Data JPA – Database abstraction
  • Spring Security – Authentication & Authorization
  • Validation API – Request validation
  • JWT – Stateless authentication

Database Design

Core Entities:

  • User
  • Product
  • Cart
  • CartItem
  • Order
  • OrderItem

Key Relationships:

  • User → OneToMany Orders
  • User → OneToOne Cart
  • Cart → OneToMany CartItems
  • Order → OneToMany OrderItems
  • Product → Optimistic Locking via @Version

Getting Started

Clone the Repository

git clone https://github.com/iRahmanG/Ecommerce-Backend.git

Configure Database

Update application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update

Or use H2 for quick testing.


Run the Application

mvn spring-boot:run

Application will start at:

http://localhost:8080

Example API Flow

  1. Register User
  2. Login → Receive JWT
  3. Create Product (Admin only)
  4. Add Product to Cart
  5. Place Order
  6. Inventory updated safely via optimistic locking

Learning Outcomes

This project demonstrates:

  • Secure JWT-based authentication
  • Role-based authorization in Spring Security
  • Clean layered architecture design
  • Transaction management using @Transactional
  • Optimistic locking for concurrency handling
  • DTO-based REST API design
  • Proper entity relationships in JPA
  • Business logic validation inside service layer

Future Enhancements (Planned)

  • Refresh Token support
  • Product search & filtering with pagination
  • Payment gateway integration (Stripe / Razorpay)
  • Wishlist functionality
  • Product reviews & ratings
  • Redis caching for performance
  • Swagger / OpenAPI documentation
  • Unit & Integration testing

(Planned for next development phase)


Author

Maksud Rahman Backend Developer | Java & Spring Boot

GitHub: https://github.com/iRahmanG


⭐ If this project helped you understand backend architecture, consider starring the repository!


About

Production-ready Spring Boot e-commerce backend implementing JWT authentication, role-based access control, cart management, order processing, and optimistic locking with clean layered architecture.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages