Skip to content

akashpatelknit/springboot-ecommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ E-Commerce REST API

A comprehensive, production-ready RESTful E-Commerce API built with Spring Boot, featuring JWT authentication, shopping cart, order management, payment processing, and review system.

Spring Boot Java PostgreSQL License


πŸ“‹ Table of Contents


✨ Features

Core Features

  • πŸ” User Authentication & Authorization - JWT-based secure authentication with role-based access control
  • πŸ‘€ User Management - Registration, profile management, address management
  • πŸ“¦ Product Management - Complete CRUD operations with image upload support
  • 🏷️ Category Management - Organize products into categories
  • πŸ›’ Shopping Cart - Add, update, remove items with real-time price calculation
  • πŸ“ Order Management - Place orders, track status, view history, cancel orders
  • πŸ’³ Payment Processing - Mock payment gateway integration
  • ⭐ Review & Rating System - Users can review and rate products
  • πŸ“§ Email Notifications - Automated emails for registration, orders, and status updates
  • πŸ” Advanced Search & Filtering - Search products by name, filter by price, category, rating
  • πŸ“Š Admin Dashboard - Analytics, user management, order management
  • πŸ“„ Pagination & Sorting - Efficient data retrieval for large datasets

Additional Features

  • βœ… Input validation on all endpoints
  • βœ… Global exception handling
  • βœ… File upload for product images
  • βœ… Stock management with automatic updates
  • βœ… Order status workflow (Pending β†’ Confirmed β†’ Shipped β†’ Delivered)
  • βœ… Low stock alerts for admins
  • βœ… Comprehensive API documentation with Swagger
  • βœ… Request/Response logging
  • βœ… Security headers and CORS configuration

πŸ› οΈ Tech Stack

Technology Purpose Version
Java Programming Language 17+
Spring Boot Backend Framework 3.2.x
Spring Security Authentication & Authorization 6.2.x
Spring Data JPA Database ORM 3.2.x
JWT Token-based Authentication 0.11.5
PostgreSQL Primary Database 15+
Hibernate ORM Implementation 6.4.x
Maven Dependency Management 3.9.x
Lombok Reduce Boilerplate Code 1.18.x
SpringDoc OpenAPI API Documentation 2.3.x
Spring Mail Email Service 3.2.x
JUnit 5 Unit Testing 5.10.x
Mockito Mocking Framework 5.8.x

πŸ—οΈ Architecture

Project Structure

src/main/java/com/ecommerce/
β”‚
β”œβ”€β”€ config/
β”‚   β”œβ”€β”€ SecurityConfig.java          # Spring Security configuration
β”‚   β”œβ”€β”€ JwtAuthenticationFilter.java # JWT filter for requests
β”‚   β”œβ”€β”€ OpenAPIConfig.java           # Swagger configuration
β”‚   └── EmailConfig.java             # Email configuration
β”‚
β”œβ”€β”€ controller/
β”‚   β”œβ”€β”€ AuthController.java          # Authentication endpoints
β”‚   β”œβ”€β”€ UserController.java          # User management endpoints
β”‚   β”œβ”€β”€ ProductController.java       # Product CRUD endpoints
β”‚   β”œβ”€β”€ CategoryController.java      # Category management
β”‚   β”œβ”€β”€ CartController.java          # Shopping cart operations
β”‚   β”œβ”€β”€ OrderController.java         # Order management
β”‚   β”œβ”€β”€ ReviewController.java        # Product reviews
β”‚   β”œβ”€β”€ PaymentController.java       # Payment processing
β”‚   └── AdminController.java         # Admin dashboard
β”‚
β”œβ”€β”€ service/
β”‚   β”œβ”€β”€ AuthService.java             # Authentication logic
β”‚   β”œβ”€β”€ UserService.java             # User business logic
β”‚   β”œβ”€β”€ ProductService.java          # Product operations
β”‚   β”œβ”€β”€ CategoryService.java         # Category operations
β”‚   β”œβ”€β”€ CartService.java             # Cart management
β”‚   β”œβ”€β”€ OrderService.java            # Order processing
β”‚   β”œβ”€β”€ ReviewService.java           # Review management
β”‚   β”œβ”€β”€ PaymentService.java          # Payment handling
β”‚   β”œβ”€β”€ EmailService.java            # Email notifications
β”‚   └── FileStorageService.java      # File upload/download
β”‚
β”œβ”€β”€ repository/
β”‚   β”œβ”€β”€ UserRepository.java
β”‚   β”œβ”€β”€ RoleRepository.java
β”‚   β”œβ”€β”€ ProductRepository.java
β”‚   β”œβ”€β”€ CategoryRepository.java
β”‚   β”œβ”€β”€ CartRepository.java
β”‚   β”œβ”€β”€ CartItemRepository.java
β”‚   β”œβ”€β”€ OrderRepository.java
β”‚   β”œβ”€β”€ OrderItemRepository.java
β”‚   β”œβ”€β”€ ReviewRepository.java
β”‚   β”œβ”€β”€ PaymentRepository.java
β”‚   └── AddressRepository.java
β”‚
β”œβ”€β”€ entity/
β”‚   β”œβ”€β”€ User.java                    # User entity
β”‚   β”œβ”€β”€ Role.java                    # Role entity (USER, ADMIN)
β”‚   β”œβ”€β”€ Address.java                 # User address entity
β”‚   β”œβ”€β”€ Product.java                 # Product entity
β”‚   β”œβ”€β”€ Category.java                # Category entity
β”‚   β”œβ”€β”€ ProductImage.java            # Product images entity
β”‚   β”œβ”€β”€ Cart.java                    # Shopping cart entity
β”‚   β”œβ”€β”€ CartItem.java                # Cart items entity
β”‚   β”œβ”€β”€ Order.java                   # Order entity
β”‚   β”œβ”€β”€ OrderItem.java               # Order items entity
β”‚   β”œβ”€β”€ Payment.java                 # Payment entity
β”‚   └── Review.java                  # Product review entity
β”‚
β”œβ”€β”€ dto/
β”‚   β”œβ”€β”€ request/                     # Request DTOs
β”‚   β”‚   β”œβ”€β”€ RegisterRequestDTO.java
β”‚   β”‚   β”œβ”€β”€ LoginRequestDTO.java
β”‚   β”‚   β”œβ”€β”€ ProductRequestDTO.java
β”‚   β”‚   β”œβ”€β”€ AddToCartDTO.java
β”‚   β”‚   β”œβ”€β”€ CreateOrderDTO.java
β”‚   β”‚   └── ReviewRequestDTO.java
β”‚   β”‚
β”‚   └── response/                    # Response DTOs
β”‚       β”œβ”€β”€ AuthResponseDTO.java
β”‚       β”œβ”€β”€ UserResponseDTO.java
β”‚       β”œβ”€β”€ ProductResponseDTO.java
β”‚       β”œβ”€β”€ CartResponseDTO.java
β”‚       β”œβ”€β”€ OrderResponseDTO.java
β”‚       └── ReviewResponseDTO.java
β”‚
β”œβ”€β”€ exception/
β”‚   β”œβ”€β”€ ResourceNotFoundException.java
β”‚   β”œβ”€β”€ DuplicateResourceException.java
β”‚   β”œβ”€β”€ UnauthorizedException.java
β”‚   β”œβ”€β”€ InsufficientStockException.java
β”‚   β”œβ”€β”€ InvalidOperationException.java
β”‚   β”œβ”€β”€ GlobalExceptionHandler.java  # @ControllerAdvice
β”‚   └── ErrorResponse.java           # Error response structure
β”‚
β”œβ”€β”€ security/
β”‚   β”œβ”€β”€ JwtUtils.java                # JWT token generation/validation
β”‚   β”œβ”€β”€ CustomUserDetails.java       # UserDetails implementation
β”‚   └── CustomUserDetailsService.java # Load user for authentication
β”‚
└── ECommerceApplication.java        # Main application class

πŸ’Ύ Database Schema

Entity Relationship Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User     │────────▢│   Address    β”‚
β”‚             β”‚ 1     * β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
       β”‚
       β”‚ *
       β”‚
       β–Ό *
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    Role     β”‚
β”‚ (USER/ADMIN)β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Category   │────────▢│   Product    β”‚
β”‚              β”‚ 1     * β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                β”‚
                                β”‚ 1
                                β”‚
                                β–Ό *
                         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                         β”‚ProductImage  β”‚
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User     │────────▢│     Cart     │────────▢│  CartItem    β”‚
β”‚             β”‚ 1     1 β”‚              β”‚ 1     * β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                                                         β”‚
                                                         β”‚ *
                                                         β–Ό 1
                                                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                                  β”‚   Product    β”‚
                                                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User     │────────▢│    Order     │────────▢│  OrderItem   β”‚
β”‚             β”‚ 1     * β”‚              β”‚ 1     * β”‚              β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                               β”‚                         β”‚
                               β”‚ 1                       β”‚ *
                               β–Ό 1                       β–Ό 1
                        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                        β”‚   Payment    β”‚         β”‚   Product    β”‚
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚    User     │────────▢│    Review    β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚             β”‚ 1     * β”‚              β”‚ *     1 β”‚   Product    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Key Tables

Users

id (PK), first_name, last_name, email (unique), password, 
phone_number, is_active, created_at, updated_at

Products

id (PK), name, description, price, discount_price, 
stock_quantity, sku, category_id (FK), image_url, 
average_rating, review_count, is_active, created_at, updated_at

Orders

id (PK), order_number (unique), user_id (FK), total_amount, 
status (PENDING/CONFIRMED/SHIPPED/DELIVERED/CANCELLED),
payment_status (PENDING/COMPLETED/FAILED), 
shipping_address_id (FK), created_at, updated_at

Reviews

id (PK), user_id (FK), product_id (FK), rating (1-5), 
comment, created_at, updated_at

πŸ“‘ API Endpoints

Authentication Endpoints

Method Endpoint Description Access
POST /api/auth/register Register new user Public
POST /api/auth/login Login user Public
POST /api/auth/refresh-token Refresh JWT token Public

User Endpoints

Method Endpoint Description Access
GET /api/users/profile Get user profile User
PUT /api/users/profile Update user profile User
POST /api/users/change-password Change password User
GET /api/users/addresses Get user addresses User
POST /api/users/addresses Add new address User
PUT /api/users/addresses/{id} Update address User
DELETE /api/users/addresses/{id} Delete address User

Category Endpoints

Method Endpoint Description Access
GET /api/categories Get all categories Public
GET /api/categories/{id} Get category by ID Public
POST /api/categories Create category Admin
PUT /api/categories/{id} Update category Admin
DELETE /api/categories/{id} Delete category Admin

Product Endpoints

Method Endpoint Description Access
GET /api/products Get all products (paginated) Public
GET /api/products/{id} Get product by ID Public
GET /api/products/search?keyword= Search products Public
GET /api/products/filter Filter products by price, category, rating Public
GET /api/products/category/{categoryId} Get products by category Public
POST /api/products Create product Admin
PUT /api/products/{id} Update product Admin
DELETE /api/products/{id} Delete product Admin
POST /api/products/{id}/images Upload product images Admin

Cart Endpoints

Method Endpoint Description Access
GET /api/cart Get user's cart User
POST /api/cart/items Add item to cart User
PUT /api/cart/items/{itemId} Update cart item quantity User
DELETE /api/cart/items/{itemId} Remove item from cart User
DELETE /api/cart/clear Clear entire cart User

Order Endpoints

Method Endpoint Description Access
POST /api/orders Create new order User
GET /api/orders Get user's orders User
GET /api/orders/{id} Get order by ID User
PUT /api/orders/{id}/cancel Cancel order User
GET /api/admin/orders Get all orders (paginated) Admin
PUT /api/admin/orders/{id}/status Update order status Admin

Review Endpoints

Method Endpoint Description Access
POST /api/products/{productId}/reviews Add review User
GET /api/products/{productId}/reviews Get product reviews Public
GET /api/reviews/my-reviews Get user's reviews User
PUT /api/reviews/{id} Update review User
DELETE /api/reviews/{id} Delete review User

Payment Endpoints

Method Endpoint Description Access
POST /api/payments/process Process payment User
GET /api/payments/order/{orderId} Get payment details User

Admin Endpoints

Method Endpoint Description Access
GET /api/admin/dashboard/stats Get dashboard statistics Admin
GET /api/admin/orders/recent Get recent orders Admin
GET /api/admin/products/low-stock Get low stock products Admin
GET /api/admin/users Get all users Admin
PUT /api/admin/users/{id}/activate Activate user Admin
PUT /api/admin/users/{id}/deactivate Deactivate user Admin

πŸš€ Getting Started

Prerequisites

  • Java 17 or higher
  • Maven 3.9+
  • PostgreSQL 15+
  • IDE (IntelliJ IDEA, Eclipse, VS Code)
  • Postman (for API testing)
  • Git

Installation

1. Clone the Repository

git clone https://github.com/yourusername/ecommerce-api.git
cd ecommerce-api

2. Create Database

-- Login to PostgreSQL
psql -U postgres

-- Create database
CREATE DATABASE ecommerce_db;

-- Create user (optional)
CREATE USER ecommerce_user WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE ecommerce_db TO ecommerce_user;

3. Configure Application Properties

Create/Update src/main/resources/application.properties:

# Application
spring.application.name=E-Commerce API
server.port=8080

# Database Configuration
spring.datasource.url=jdbc:postgresql://localhost:5432/ecommerce_db
spring.datasource.username=postgres
spring.datasource.password=your_password
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect

# JWT Configuration
jwt.secret=your-256-bit-secret-key-change-this-in-production
jwt.expiration=86400000

# File Upload Configuration
spring.servlet.multipart.enabled=true
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=10MB
file.upload-dir=./uploads

# Email Configuration (Gmail SMTP)
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username[email protected]
spring.mail.password=your-app-password
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true

# Logging
logging.level.root=INFO
logging.level.com.ecommerce=DEBUG
logging.file.name=logs/ecommerce.log

# Swagger/OpenAPI
springdoc.api-docs.path=/api-docs
springdoc.swagger-ui.path=/swagger-ui.html

4. Build the Project

mvn clean install

5. Run the Application

mvn spring-boot:run

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

6. Access API Documentation

Open browser and navigate to:


βš™οΈ Configuration

Email Configuration (Gmail)

  1. Enable 2-Factor Authentication in your Gmail account
  2. Generate an App Password:
    • Go to Google Account β†’ Security β†’ 2-Step Verification β†’ App Passwords
    • Select "Mail" and "Other (Custom name)"
    • Copy the generated password
  3. Use this password in application.properties

JWT Secret Key

Generate a secure secret key (256-bit):

# Using OpenSSL
openssl rand -base64 32

Replace jwt.secret in application.properties

File Upload Directory

Create uploads directory:

mkdir uploads

Or configure different path in application.properties:

file.upload-dir=/path/to/your/uploads

πŸ“– Usage Examples

1. Register a New User

Request:

POST /api/auth/register
Content-Type: application/json

{
  "firstName": "John",
  "lastName": "Doe",
  "email": "[email protected]",
  "password": "SecurePass123!",
  "phoneNumber": "+1234567890"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "type": "Bearer",
  "user": {
    "id": 1,
    "firstName": "John",
    "lastName": "Doe",
    "email": "[email protected]",
    "role": "USER"
  }
}

2. Login

Request:

POST /api/auth/login
Content-Type: application/json

{
  "email": "[email protected]",
  "password": "SecurePass123!"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "type": "Bearer",
  "user": {
    "id": 1,
    "firstName": "John",
    "lastName": "Doe",
    "email": "[email protected]",
    "role": "USER"
  }
}

3. Get All Products (with Pagination)

Request:

GET /api/products?page=0&size=10&sort=price,asc

Response:

{
  "content": [
    {
      "id": 1,
      "name": "Laptop",
      "description": "High performance laptop",
      "price": 999.99,
      "discountPrice": 899.99,
      "stockQuantity": 50,
      "category": "Electronics",
      "imageUrl": "/uploads/laptop.jpg",
      "averageRating": 4.5,
      "reviewCount": 120
    }
  ],
  "page": 0,
  "size": 10,
  "totalElements": 100,
  "totalPages": 10
}

4. Add Item to Cart

Request:

POST /api/cart/items
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

{
  "productId": 1,
  "quantity": 2
}

Response:

{
  "id": 1,
  "items": [
    {
      "id": 1,
      "product": {
        "id": 1,
        "name": "Laptop",
        "price": 999.99
      },
      "quantity": 2,
      "subtotal": 1999.98
    }
  ],
  "totalAmount": 1999.98
}

5. Place an Order

Request:

POST /api/orders
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

{
  "shippingAddressId": 1,
  "paymentMethod": "CREDIT_CARD"
}

Response:

{
  "id": 1,
  "orderNumber": "ORD-2024-001",
  "status": "PENDING",
  "paymentStatus": "PENDING",
  "totalAmount": 1999.98,
  "items": [
    {
      "productName": "Laptop",
      "quantity": 2,
      "price": 999.99,
      "subtotal": 1999.98
    }
  ],
  "shippingAddress": {
    "street": "123 Main St",
    "city": "New York",
    "state": "NY",
    "zipCode": "10001"
  },
  "createdAt": "2024-01-15T10:30:00"
}

6. Add Product Review

Request:

POST /api/products/1/reviews
Authorization: Bearer <your_jwt_token>
Content-Type: application/json

{
  "rating": 5,
  "comment": "Excellent product! Highly recommended."
}

Response:

{
  "id": 1,
  "user": {
    "firstName": "John",
    "lastName": "Doe"
  },
  "rating": 5,
  "comment": "Excellent product! Highly recommended.",
  "createdAt": "2024-01-15T11:00:00"
}

πŸ§ͺ Testing

Run All Tests

mvn test

Run Specific Test Class

mvn test -Dtest=ProductServiceTest

Run with Coverage

mvn clean test jacoco:report

View coverage report at: target/site/jacoco/index.html

Test Categories

  • Unit Tests: Test individual components (services, utilities)
  • Integration Tests: Test complete request-response flow
  • Security Tests: Test authentication and authorization

Postman Collection

Import the Postman collection from postman/E-Commerce-API.postman_collection.json

Contains:

  • All API endpoints with examples
  • Environment variables for tokens
  • Pre-request scripts for authentication
  • Test scripts for validation

🐳 Deployment

Docker Deployment

1. Create Dockerfile

FROM openjdk:17-jdk-slim
WORKDIR /app
COPY target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

2. Create docker-compose.yml

version: '3.8'

services:
  postgres:
    image: postgres:15-alpine
    environment:
      POSTGRES_DB: ecommerce_db
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: password
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

  app:
    build: .
    ports:
      - "8080:8080"
    environment:
      SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/ecommerce_db
      SPRING_DATASOURCE_USERNAME: postgres
      SPRING_DATASOURCE_PASSWORD: password
    depends_on:
      - postgres

volumes:
  postgres_data:

3. Build and Run

# Build the application
mvn clean package -DskipTests

# Build and start containers
docker-compose up --build

# Stop containers
docker-compose down

Deploy to Cloud

Heroku Deployment

# Login to Heroku
heroku login

# Create app
heroku create your-ecommerce-api

# Add PostgreSQL
heroku addons:create heroku-postgresql:hobby-dev

# Deploy
git push heroku main

# Open app
heroku open

Railway Deployment

  1. Go to Railway.app
  2. Click "New Project" β†’ "Deploy from GitHub"
  3. Select your repository
  4. Add PostgreSQL database from "New" β†’ "Database"
  5. Configure environment variables
  6. Deploy automatically

🀝 Contributing

Contributions are welcome! Please follow these steps:

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

Code Style Guidelines

  • Follow Java naming conventions
  • Use meaningful variable and method names
  • Add comments for complex logic
  • Write unit tests for new features
  • Update documentation for API changes

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘₯ Authors


πŸ™ Acknowledgments

  • Spring Boot Documentation
  • Baeldung Tutorials
  • Stack Overflow Community
  • PostgreSQL Documentation

πŸ“ž Support

For support, email [email protected] or create an issue in the repository.


πŸ—ΊοΈ Roadmap

Version 1.0 (Current)

  • βœ… Basic CRUD operations
  • βœ… JWT Authentication
  • βœ… Shopping Cart
  • βœ… Order Management
  • βœ… Payment Processing (Mock)
  • βœ… Review System

Version 2.0 (Planned)

  • Real payment gateway integration (Stripe/Razorpay)
  • Wishlist functionality
  • Product recommendations
  • Real-time order tracking
  • WebSocket notifications
  • Advanced analytics dashboard
  • Multi-currency support
  • Inventory management system

Version 3.0 (Future)

  • Microservices architecture
  • Redis caching
  • Elasticsearch for advanced search
  • Mobile app integration
  • Social media authentication
  • Multi-vendor support
  • Subscription management

πŸ“Š API Statistics

  • Total Endpoints: 40+
  • Authentication: JWT-based
  • Database Tables: 11
  • Roles: 2 (USER, ADMIN)
  • Average Response Time: < 200ms
  • Test Coverage: 75%+

πŸ”’ Security Features

  • βœ… Password encryption with BCrypt
  • βœ… JWT token-based authentication
  • βœ… Role-based authorization
  • βœ… CORS configuration
  • βœ… Input validation and sanitization
  • βœ… SQL injection prevention
  • βœ… XSS protection
  • βœ… Rate limiting (optional)
  • βœ… Secure file upload

πŸ“ˆ Performance

  • Efficient database queries with JPA
  • Pagination for large datasets
  • Lazy loading for related entities
  • Connection pooling with HikariCP
  • Query optimization with indexes
  • Caching support (optional)

Built with ❀️ using Spring Boot

⭐ If you found this project helpful, please give it a star!

About

Scalable E-Commerce REST API built with Spring Boot featuring JWT authentication, product catalog, cart, orders, payments, reviews, and advanced filtering.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors