Skip to content

lekhrocks/Ecommerce_BE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Ecommerce Backend Service

A comprehensive RESTful API backend service for an ecommerce platform built with Spring Boot, featuring user authentication, product management, shopping cart functionality, order processing with Stripe integration, and wishlist management.

πŸš€ Features

Core Functionality

  • User Management: Registration, authentication, and profile management
  • Product Management: CRUD operations for products with category support
  • Category Management: Product categorization and organization
  • Shopping Cart: Add, remove, and manage cart items
  • Order Processing: Complete order lifecycle with Stripe payment integration
  • Wishlist: Save and manage favorite products
  • Authentication: Token-based authentication system

Technical Features

  • RESTful API: Well-structured REST endpoints
  • Database Integration: MySQL database with JPA/Hibernate
  • API Documentation: Swagger/OpenAPI documentation
  • Exception Handling: Comprehensive error handling and validation
  • Payment Integration: Stripe payment gateway integration
  • CORS Support: Cross-origin resource sharing configuration

πŸ—οΈ System Architecture

High-Level Architecture Diagram

graph TB
    subgraph "Client Applications"
        Web[Web Frontend]
        Mobile[Mobile App]
        Admin[Admin Dashboard]
    end
    
    subgraph "API Gateway"
        API[Spring Boot REST API]
        Swagger[Swagger Documentation]
    end
    
    subgraph "Business Logic Layer"
        Auth[Authentication Service]
        User[User Service]
        Product[Product Service]
        Cart[Cart Service]
        Order[Order Service]
        Wishlist[Wishlist Service]
    end
    
    subgraph "Data Layer"
        JPA[Spring Data JPA]
        MySQL[(MySQL Database)]
    end
    
    subgraph "External Services"
        Stripe[Stripe Payment API]
    end
    
    Web --> API
    Mobile --> API
    Admin --> API
    API --> Swagger
    API --> Auth
    API --> User
    API --> Product
    API --> Cart
    API --> Order
    API --> Wishlist
    Auth --> JPA
    User --> JPA
    Product --> JPA
    Cart --> JPA
    Order --> JPA
    Wishlist --> JPA
    JPA --> MySQL
    Order --> Stripe
Loading

Database Entity Relationship Diagram

erDiagram
    USERS {
        int id PK
        string first_name
        string last_name
        string email UK
        string password
    }
    
    AUTHENTICATION_TOKEN {
        int id PK
        string token UK
        date created_date
        int user_id FK
    }
    
    CATEGORY {
        int id PK
        string category_name UK
        string description
        string image_url
    }
    
    PRODUCT {
        int id PK
        string name
        string image_url
        double price
        string description
        int category_id FK
    }
    
    CART {
        int id PK
        int user_id FK
        int product_id FK
        int quantity
        date created_date
    }
    
    WISHLIST {
        int id PK
        int user_id FK
        int product_id FK
        date created_date
    }
    
    ORDERS {
        int id PK
        date created_date
        double total_price
        string session_id
        int user_id FK
    }
    
    ORDER_ITEM {
        int id PK
        int order_id FK
        int product_id FK
        int quantity
        double price
        date created_date
    }
    
    USERS ||--o{ AUTHENTICATION_TOKEN : "has"
    USERS ||--o{ CART : "has"
    USERS ||--o{ WISHLIST : "has"
    USERS ||--o{ ORDERS : "places"
    CATEGORY ||--o{ PRODUCT : "contains"
    PRODUCT ||--o{ CART : "added_to"
    PRODUCT ||--o{ WISHLIST : "saved_in"
    PRODUCT ||--o{ ORDER_ITEM : "included_in"
    ORDERS ||--o{ ORDER_ITEM : "contains"
Loading

API Flow Diagram

sequenceDiagram
    participant Client
    participant API as Spring Boot API
    participant Auth as Auth Service
    participant Service as Business Service
    participant DB as Database
    participant Stripe as Stripe API
    
    Note over Client, Stripe: User Registration Flow
    Client->>API: POST /user/signup
    API->>Service: UserService.signUp()
    Service->>DB: Save user
    DB-->>Service: User saved
    Service-->>API: SignUpResponse
    API-->>Client: Success response
    
    Note over Client, Stripe: User Authentication Flow
    Client->>API: POST /user/signIn
    API->>Auth: UserService.signIn()
    Auth->>DB: Validate credentials
    DB-->>Auth: User data
    Auth->>DB: Generate token
    Auth-->>API: SignInResponse with token
    API-->>Client: Authentication token
    
    Note over Client, Stripe: Product Management Flow
    Client->>API: POST /product/add
    API->>Service: ProductService.addProduct()
    Service->>DB: Save product
    DB-->>Service: Product saved
    Service-->>API: Success response
    API-->>Client: Product created
    
    Note over Client, Stripe: Shopping Cart Flow
    Client->>API: POST /cart/add?token=xxx
    API->>Auth: Validate token
    Auth-->>API: User data
    API->>Service: CartService.addToCart()
    Service->>DB: Save cart item
    DB-->>Service: Cart item saved
    Service-->>API: Success response
    API-->>Client: Item added to cart
    
    Note over Client, Stripe: Order Processing Flow
    Client->>API: POST /order/create-checkout-session
    API->>Service: OrderService.createSession()
    Service->>Stripe: Create checkout session
    Stripe-->>Service: Session ID
    Service-->>API: StripeResponse
    API-->>Client: Checkout session
    
    Client->>API: POST /order/add?token=xxx&sessionId=xxx
    API->>Auth: Validate token
    Auth-->>API: User data
    API->>Service: OrderService.placeOrder()
    Service->>DB: Save order and items
    Service->>DB: Clear cart
    DB-->>Service: Order saved
    Service-->>API: Success response
    API-->>Client: Order placed
Loading

Component Architecture

graph LR
    subgraph "Presentation Layer"
        Controllers[Controllers]
        DTOs[DTOs]
        Exceptions[Exception Handler]
    end
    
    subgraph "Business Logic Layer"
        Services[Services]
        Validation[Validation]
    end
    
    subgraph "Data Access Layer"
        Repositories[Repositories]
        Entities[Entities]
    end
    
    subgraph "Infrastructure"
        Database[(MySQL)]
        Stripe[Stripe API]
        Config[Configuration]
    end
    
    Controllers --> DTOs
    Controllers --> Services
    Controllers --> Exceptions
    Services --> Repositories
    Services --> Validation
    Services --> Stripe
    Repositories --> Entities
    Entities --> Database
    Config --> Database
    Config --> Stripe
Loading

πŸ› οΈ Technology Stack

  • Framework: Spring Boot 2.7.0
  • Language: Java 11
  • Database: MySQL 8.0
  • ORM: Spring Data JPA with Hibernate
  • API Documentation: Swagger 2 (SpringFox 3.0.0)
  • Payment Gateway: Stripe API
  • Build Tool: Maven
  • Validation: Bean Validation API

πŸ“‹ Prerequisites

Before running this application, ensure you have the following installed:

  • Java 11 or higher
  • Maven 3.6 or higher
  • MySQL 8.0 or higher
  • Stripe Account (for payment processing)

πŸš€ Quick Start

1. Database Setup

Create a MySQL database named ecommerce:

CREATE DATABASE ecommerce;

2. Configuration

Update the database configuration in src/main/resources/application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce
spring.datasource.username=your_username
spring.datasource.password=your_password

3. Stripe Configuration

Add your Stripe secret key to application.properties:

STRIPE_SECRET_KEY=your_stripe_secret_key

4. Build and Run

# Clone the repository
git clone <repository-url>
cd Ecommerce_BE

# Build the project
./mvnw clean install

# Run the application
./mvnw spring-boot:run

The application will start on http://localhost:8081

5. API Documentation

Access the Swagger UI documentation at:

http://localhost:8081/swagger-ui/

πŸ“š API Endpoints

Authentication (/user)

  • POST /user/signup - User registration
  • POST /user/signIn - User login

Categories (/category)

  • GET /category/ - Get all categories
  • POST /category/create - Create new category
  • POST /category/update/{categoryID} - Update category

Products (/product)

  • GET /product/ - Get all products
  • POST /product/add - Add new product
  • POST /product/update/{productID} - Update product

Shopping Cart (/cart)

  • GET /cart/ - Get user's cart items
  • POST /cart/add - Add item to cart
  • DELETE /cart/delete/{cartItemId} - Remove item from cart

Orders (/order)

  • GET /order/ - Get user's orders
  • GET /order/{id} - Get specific order details
  • POST /order/create-checkout-session - Create Stripe checkout session
  • POST /order/add - Place order after payment

Wishlist (/wishlist)

  • GET /wishlist/{token} - Get user's wishlist
  • POST /wishlist/add - Add product to wishlist

πŸ—οΈ Project Structure

src/main/java/com/demo/ecommerce/
β”œβ”€β”€ common/
β”‚   └── ApiResponse.java          # Standard API response wrapper
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ SwaggerConfig.java        # Swagger API documentation config
β”‚   β”œβ”€β”€ WebConfig.java           # Web configuration (CORS, etc.)
β”‚   └── MessageStrings.java      # Application message constants
β”œβ”€β”€ controllers/                  # REST API controllers
β”‚   β”œβ”€β”€ UserController.java      # User authentication endpoints
β”‚   β”œβ”€β”€ ProductController.java   # Product management endpoints
β”‚   β”œβ”€β”€ CategoryController.java  # Category management endpoints
β”‚   β”œβ”€β”€ CartController.java      # Shopping cart endpoints
β”‚   β”œβ”€β”€ OrderController.java     # Order management endpoints
β”‚   └── WishListController.java  # Wishlist endpoints
β”œβ”€β”€ dto/                         # Data Transfer Objects
β”‚   β”œβ”€β”€ users/                   # User-related DTOs
β”‚   β”œβ”€β”€ product/                 # Product-related DTOs
β”‚   β”œβ”€β”€ cart/                    # Cart-related DTOs
β”‚   └── checkout/                # Checkout-related DTOs
β”œβ”€β”€ exceptions/                  # Custom exception classes
β”œβ”€β”€ model/                       # JPA entity models
β”‚   β”œβ”€β”€ User.java               # User entity
β”‚   β”œβ”€β”€ Product.java            # Product entity
β”‚   β”œβ”€β”€ Category.java           # Category entity
β”‚   β”œβ”€β”€ Cart.java               # Cart entity
β”‚   β”œβ”€β”€ Order.java              # Order entity
β”‚   β”œβ”€β”€ OrderItem.java          # Order item entity
β”‚   β”œβ”€β”€ WishList.java           # Wishlist entity
β”‚   └── AuthenticationToken.java # Auth token entity
β”œβ”€β”€ repository/                  # JPA repositories
β”œβ”€β”€ service/                     # Business logic services
└── EcommerceApplication.java    # Main application class

πŸ” Authentication

The application uses token-based authentication:

  1. Registration: Users register with email and password
  2. Login: Users sign in and receive an authentication token
  3. Protected Endpoints: Most endpoints require the token as a query parameter

Example usage:

GET /cart/?token=your_auth_token

πŸ’³ Payment Integration

The application integrates with Stripe for payment processing:

  1. Checkout Session: Creates a Stripe checkout session for cart items
  2. Payment Processing: Handles payment through Stripe
  3. Order Placement: Places order after successful payment

πŸ—„οΈ Database Schema

Core Entities

  • Users: User accounts and authentication
  • Categories: Product categories
  • Products: Product information with category relationships
  • Cart: Shopping cart items for users
  • Orders: Order information with payment details
  • OrderItems: Individual items within orders
  • WishList: User's saved products
  • AuthenticationToken: User authentication tokens

πŸ§ͺ Testing

Run the test suite:

./mvnw test

πŸ“ Environment Variables

Variable Description Default
spring.datasource.url Database connection URL jdbc:mysql://localhost:3306/ecommerce
spring.datasource.username Database username root
spring.datasource.password Database password root
STRIPE_SECRET_KEY Stripe secret key Required
BASE_URL Application base URL http://localhost:8081/

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ‘¨β€πŸ’» Author

Lekhraj Kumar

πŸ†˜ Support

For support and questions, please contact:

About

No description or website provided.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors