Skip to content

About

Ecommerce springboot backend

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

ecommerce_springboot

​

Introduction

​ ecommerce_springboot is a robust, full-featured e-commerce backend application built with Spring Boot. The project implements the core functionalities required for an online e-commerce platform, including user registration, product management, shopping cart operations, order processing, authentication, and authorization. The application is structured to promote clear separation of concerns and scalability, making it ideal for both learning and production e-commerce systems. ​

Features

​

  • User registration, authentication, and role-based authorization
  • Product catalog management (CRUD operations)
  • Shopping cart with item management
  • Order processing and management
  • RESTful API endpoints for all core operations
  • JWT-based security for API routes
  • Exception handling and standard API responses
  • Integration-ready backend (can be paired with any frontend)
  • Modular codebase with services, controllers, entities, and repositories ​

Usage

​ Follow these steps to get the ecommerce_springboot backend running locally: ​

Prerequisites

​

  • Java 17 or above
  • Maven
  • MySQL or compatible relational database ​

Installation

​

  1. Clone the repository
    git clone https://github.com/khushi-infinity/ecommerce_springboot.git
    cd ecommerce_springboot

​ 2. Configure Database

  • Update your application.properties with your MySQL credentials:
    spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_db
    spring.datasource.username=YOUR_USERNAME
    spring.datasource.password=YOUR_PASSWORD
    

​ 3. Build the project

mvn clean install

​ 4. Run the application

mvn spring-boot:run

The backend will be available at http://localhost:8080. ​

Example API Usage

​ Interact with the provided REST API endpoints using tools like Postman or curl. See the API documentation section below for details on each endpoint. ​

Database Schema

​ The main entities include User, Product, Cart, CartItem, and Order. Relationships are managed with JPA/Hibernate annotations. ​

erDiagram
    USER ||--o{ ORDER : places
    USER ||--o{ CART : owns
    ORDER ||--o{ ORDER_ITEM : contains
    CART ||--o{ CART_ITEM : contains
    PRODUCT ||--o{ ORDER_ITEM : included_in
    PRODUCT ||--o{ CART_ITEM : added_to
Loading

​

API Documentation

​

User Registration

​

Register a New User

​

{
    "title": "Register User",
    "description": "Registers a new user account.",
    "method": "POST",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/auth/register",
    "headers": [
        {
            "key": "Content-Type",
            "value": "application/json",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "json",
    "requestBody": "{\n  \"username\": \"john_doe\",\n  \"email\": \"john@example.com\",\n  \"password\": \"password123\"\n}",
    "responses": {
        "201": {
            "description": "User created successfully",
            "body": "{\n  \"message\": \"User registered successfully.\"\n}"
        },
        "400": {
            "description": "Invalid input or user exists",
            "body": "{\n  \"error\": \"Email already exists.\"\n}"
        }
    }
}

​

Authenticate User

​

Login and Get JWT Token

​

{
    "title": "Login User",
    "description": "Authenticates a user and returns a JWT token.",
    "method": "POST",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/auth/login",
    "headers": [
        {
            "key": "Content-Type",
            "value": "application/json",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "json",
    "requestBody": "{\n  \"email\": \"john@example.com\",\n  \"password\": \"password123\"\n}",
    "responses": {
        "200": {
            "description": "Authenticated successfully",
            "body": "{\n  \"token\": \"<JWT Token>\"\n}"
        },
        "401": {
            "description": "Authentication failed",
            "body": "{\n  \"error\": \"Invalid credentials.\"\n}"
        }
    }
}

​

Product Management

​

Get All Products

​

{
    "title": "List Products",
    "description": "Retrieves a list of all products.",
    "method": "GET",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/products",
    "headers": [
        {
            "key": "Authorization",
            "value": "Bearer <token>",
            "required": false
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "none",
    "requestBody": "",
    "responses": {
        "200": {
            "description": "List of products",
            "body": "[\n  {\n    \"id\": 1,\n    \"name\": \"Laptop\",\n    \"price\": 800.00\n  },\n  {\n    \"id\": 2,\n    \"name\": \"Phone\",\n    \"price\": 400.00\n  }\n]"
        }
    }
}

​

Add a New Product

​

{
    "title": "Add Product",
    "description": "Creates a new product (admin only).",
    "method": "POST",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/products",
    "headers": [
        {
            "key": "Authorization",
            "value": "Bearer <token>",
            "required": true
        },
        {
            "key": "Content-Type",
            "value": "application/json",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "json",
    "requestBody": "{\n  \"name\": \"Tablet\",\n  \"description\": \"Android tablet\",\n  \"price\": 250.00,\n  \"stock\": 20\n}",
    "responses": {
        "201": {
            "description": "Product created",
            "body": "{\n  \"id\": 3,\n  \"name\": \"Tablet\",\n  \"price\": 250.00\n}"
        },
        "403": {
            "description": "Forbidden",
            "body": "{\n  \"error\": \"Only admins can add products.\"\n}"
        }
    }
}

​

Cart Operations

​

Add Item to Cart

​

{
    "title": "Add Cart Item",
    "description": "Adds a product to the user's cart.",
    "method": "POST",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/cart/items",
    "headers": [
        {
            "key": "Authorization",
            "value": "Bearer <token>",
            "required": true
        },
        {
            "key": "Content-Type",
            "value": "application/json",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "json",
    "requestBody": "{\n  \"productId\": 1,\n  \"quantity\": 2\n}",
    "responses": {
        "200": {
            "description": "Item added to cart",
            "body": "{\n  \"cartId\": 5,\n  \"items\": [\n    {\n      \"productId\": 1,\n      \"quantity\": 2\n    }\n  ]\n}"
        }
    }
}

​

Remove Item from Cart

​

{
    "title": "Remove Cart Item",
    "description": "Removes an item from the user's cart.",
    "method": "DELETE",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/cart/items/{itemId}",
    "headers": [
        {
            "key": "Authorization",
            "value": "Bearer <token>",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [
        {
            "key": "itemId",
            "value": "Cart Item ID",
            "required": true
        }
    ],
    "bodyType": "none",
    "requestBody": "",
    "responses": {
        "200": {
            "description": "Item removed",
            "body": "{\n  \"message\": \"Cart item removed successfully.\"\n}"
        }
    }
}

​

Order Processing

​

Place an Order

​

{
    "title": "Place Order",
    "description": "Places an order for the current user's cart.",
    "method": "POST",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/orders",
    "headers": [
        {
            "key": "Authorization",
            "value": "Bearer <token>",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "none",
    "requestBody": "",
    "responses": {
        "201": {
            "description": "Order placed",
            "body": "{\n  \"orderId\": 12,\n  \"status\": \"PLACED\"\n}"
        }
    }
}

​

Get User Orders

​

{
    "title": "List User Orders",
    "description": "Retrieves all orders placed by the current user.",
    "method": "GET",
    "baseUrl": "http://localhost:8080",
    "endpoint": "/api/orders",
    "headers": [
        {
            "key": "Authorization",
            "value": "Bearer <token>",
            "required": true
        }
    ],
    "queryParams": [],
    "pathParams": [],
    "bodyType": "none",
    "requestBody": "",
    "responses": {
        "200": {
            "description": "List of user's orders",
            "body": "[\n  {\n    \"orderId\": 12,\n    \"status\": \"PLACED\"\n  }\n]"
        }
    }
}

​

Contributing

​ We welcome contributions! To contribute to ecommerce_springboot: ​

  • Fork the repository and create a new branch.
  • Make your changes with clear, descriptive commits.
  • Ensure your code follows the project’s structure and conventions.
  • Add or update tests if applicable.
  • Submit a pull request with a clear description of your changes. ​ For major changes, please open an issue first to discuss what you would like to change. ​

​ Thank you for using and contributing to ecommerce_springboot!

About

Ecommerce springboot backend

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages