Skip to content

SOURABHs23/ECommerce

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

52 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›’ ShopHub β€” E-Commerce Application

A full-stack E-Commerce application built with Angular 18 and Spring Boot 3.


πŸš€ Features

Storefront

  • Product Browsing β€” Filterable product listing with search, category filtering, and price range
  • Product Detail β€” Rich product view with multiple images and add-to-cart
  • Shopping Cart β€” Add, update quantity, remove items, and real-time cart totals
  • Checkout β€” Select a shipping address from your address book and place orders
  • Order History β€” Track past orders and their statuses

User Account

  • JWT Authentication β€” Secure signup, sign-in, and protected routes
  • OTP Verification β€” Phone number verification via Twilio SMS
  • Address Book β€” Manage multiple shipping addresses (CRUD)

Admin Panel

  • Dashboard β€” Overview of the store
  • Product Management β€” Create, edit, and delete products with image uploads
  • Category Management β€” Full CRUD for product categories
  • Order Management β€” View all orders and update order statuses

Other

  • Email Notifications β€” Order confirmation emails via Gmail SMTP
  • SMS Notifications β€” OTP delivery via Twilio
  • Global Exception Handling β€” Consistent API error responses
  • Input Validation β€” Request DTO validation with Bean Validation
  • CORS β€” Pre-configured for Angular dev server on localhost:4200
  • Responsive UI β€” Modern interface with CSS Grid/Flexbox

πŸ› οΈ Technology Stack

Backend

Component Technology
Framework Spring Boot 3.2.1
Language Java 21
Database PostgreSQL
Security Spring Security + JWT (jjwt 0.12)
Validation Spring Boot Starter Validation
Email Spring Boot Starter Mail
SMS Twilio SDK 9.14
Boilerplate Lombok 1.18
Build Tool Maven

Frontend

Component Technology
Framework Angular 18
Language TypeScript 5.5
UI Library Angular Material 18 + Angular CDK
Styling Vanilla CSS (Grid / Flexbox)
JWT Handling jwt-decode
Build Tool Angular CLI

πŸ“‚ Project Structure

ECommerce/
β”œβ”€β”€ backend/                              # Spring Boot Application
β”‚   β”œβ”€β”€ src/main/java/com/ecommerce/
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ common/                       # ── Shared Infrastructure ──
β”‚   β”‚   β”‚   β”œβ”€β”€ config/                   #   SecurityConfig
β”‚   β”‚   β”‚   β”œβ”€β”€ security/                 #   JWT filter, token provider, CookieService
β”‚   β”‚   β”‚   β”œβ”€β”€ exception/                #   BadRequestException, ResourceNotFoundException
β”‚   β”‚   β”‚   β”œβ”€β”€ handler/                  #   GlobalExceptionHandler
β”‚   β”‚   β”‚   └── dto/                      #   ApiResponse
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ auth/                         # ── πŸ” Auth Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthController            #   /api/auth
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthService (interface)   #   Signup, Signin
β”‚   β”‚   β”‚   β”œβ”€β”€ AuthServiceImpl           #   Implementation
β”‚   β”‚   β”‚   β”œβ”€β”€ SignInRequest, SignUpRequest, AuthResponse
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ user/                         # ── πŸ‘€ User Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ User (entity)             #   JPA entity
β”‚   β”‚   β”‚   β”œβ”€β”€ UserRepository            #   Data access
β”‚   β”‚   β”‚   β”œβ”€β”€ UserService (interface)   #   Centralized user access
β”‚   β”‚   β”‚   β”œβ”€β”€ UserServiceImpl           #   Implementation
β”‚   β”‚   β”‚   └── HomeController            #   /
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ product/                      # ── πŸ“¦ Product Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ ProductController         #   /api/products
β”‚   β”‚   β”‚   β”œβ”€β”€ ProductService + Impl     #   CRUD, search, filter
β”‚   β”‚   β”‚   β”œβ”€β”€ ImageService + Impl       #   Product image fetching
β”‚   β”‚   β”‚   β”œβ”€β”€ Product, ProductImage     #   JPA entities
β”‚   β”‚   β”‚   β”œβ”€β”€ ProductRepository         #   Data access
β”‚   β”‚   β”‚   └── ProductRequest, ProductResponse
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ category/                     # ── πŸ“‚ Category Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ CategoryController        #   /api/categories
β”‚   β”‚   β”‚   β”œβ”€β”€ CategoryService + Impl    #   CRUD
β”‚   β”‚   β”‚   β”œβ”€β”€ Category                  #   JPA entity
β”‚   β”‚   β”‚   β”œβ”€β”€ CategoryRepository        #   Data access
β”‚   β”‚   β”‚   └── CategoryRequest, CategoryResponse
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ cart/                         # ── πŸ›’ Cart Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ CartController            #   /api/cart
β”‚   β”‚   β”‚   β”œβ”€β”€ CartService + Impl        #   Add, update, remove, clear
β”‚   β”‚   β”‚   β”œβ”€β”€ Cart, CartItem            #   JPA entities
β”‚   β”‚   β”‚   β”œβ”€β”€ CartRepository, CartItemRepository
β”‚   β”‚   β”‚   └── CartItemRequest, CartResponse
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ order/                        # ── πŸ“‹ Order Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ OrderController           #   /api/orders
β”‚   β”‚   β”‚   β”œβ”€β”€ OrderService + Impl       #   Create, cancel, track
β”‚   β”‚   β”‚   β”œβ”€β”€ Order, OrderItem, OrderStatus
β”‚   β”‚   β”‚   β”œβ”€β”€ OrderRepository           #   Data access
β”‚   β”‚   β”‚   └── OrderRequest, OrderResponse
β”‚   β”‚   β”‚
β”‚   β”‚   β”œβ”€β”€ address/                      # ── πŸ“ Address Domain ──
β”‚   β”‚   β”‚   β”œβ”€β”€ AddressController         #   /api/addresses
β”‚   β”‚   β”‚   β”œβ”€β”€ AddressService + Impl     #   CRUD + default management
β”‚   β”‚   β”‚   β”œβ”€β”€ Address                   #   JPA entity
β”‚   β”‚   β”‚   β”œβ”€β”€ AddressRepository         #   Data access
β”‚   β”‚   β”‚   └── AddressRequest, AddressResponse
β”‚   β”‚   β”‚
β”‚   β”‚   └── notification/                 # ── πŸ”” Notification Domain ──
β”‚   β”‚       β”œβ”€β”€ OtpController             #   /api/otp
β”‚   β”‚       β”œβ”€β”€ OtpService + Impl         #   OTP generate, send, verify
β”‚   β”‚       β”œβ”€β”€ OtpCleanupScheduler       #   Scheduled expired OTP cleanup
β”‚   β”‚       β”œβ”€β”€ EmailService + Impl       #   Transactional emails
β”‚   β”‚       β”œβ”€β”€ SmsService + Impl         #   Twilio SMS
β”‚   β”‚       β”œβ”€β”€ OrderEmailComposer        #   Order email templates
β”‚   β”‚       β”œβ”€β”€ Otp, OtpRepository        #   JPA entity + data access
β”‚   β”‚       └── SendEmailRequest, SendSmsRequest
β”‚   β”‚
β”‚   β”œβ”€β”€ .env.example                      # Template for environment variables
β”‚   └── pom.xml
β”‚
β”œβ”€β”€ frontend/                             # Angular Application
β”‚   β”œβ”€β”€ src/app/
β”‚   β”‚   β”œβ”€β”€ core/
β”‚   β”‚   β”‚   β”œβ”€β”€ guards/                   # Auth, Admin, HomeRedirect guards
β”‚   β”‚   β”‚   β”œβ”€β”€ interceptors/             # HTTP interceptors (JWT attach)
β”‚   β”‚   β”‚   β”œβ”€β”€ models/                   # TypeScript interfaces / models
β”‚   β”‚   β”‚   └── services/                # API services (auth, product, cart, order, …)
β”‚   β”‚   β”œβ”€β”€ features/
β”‚   β”‚   β”‚   β”œβ”€β”€ admin/                    # Dashboard, ProductForm
β”‚   β”‚   β”‚   β”œβ”€β”€ auth/                     # Login, Register
β”‚   β”‚   β”‚   β”œβ”€β”€ cart/                     # Shopping cart page
β”‚   β”‚   β”‚   β”œβ”€β”€ checkout/                # Checkout flow
β”‚   β”‚   β”‚   β”œβ”€β”€ orders/                  # Order history
β”‚   β”‚   β”‚   └── products/               # Product list, Product detail
β”‚   β”‚   └── shared/
β”‚   β”‚       └── components/              # Header, Footer, ProductCard
β”‚   └── package.json
β”‚
└── ECommerce_API.postman_collection.json # Postman collection for all endpoints

πŸ—οΈ Architecture

Domain-Driven Design (Microservice-Ready)

The backend is organized by business domain (vertical slicing), not by technical layer. Each domain package is self-contained with its own controller, service, entities, DTOs, and repositories β€” making it straightforward to extract into an independent microservice.

Domain Responsibility API Prefix
auth/ User registration & login /api/auth
user/ User entity & centralized access β€”
product/ Product catalog, search, images /api/products
category/ Product categories /api/categories
cart/ Shopping cart management /api/cart
order/ Order creation, tracking, cancellation /api/orders
address/ Shipping address book /api/addresses
notification/ Email, SMS, OTP verification /api/otp

SOLID Principles Applied

Principle Implementation
Single Responsibility OTP cleanup extracted to OtpCleanupScheduler; cookie logic to CookieService; email composition to OrderEmailComposer
Open/Closed All services are interfaces with Impl classes β€” swap implementations without modifying consumers
Liskov Substitution EmailService.sendOrderConfirmation uses OrderResponse (typed) instead of Object
Interface Segregation Email composition separated from email sending; domain-specific concerns stay in their domain
Dependency Inversion Controllers depend on service interfaces; UserService abstracts all user data access across domains

βš™οΈ Setup & Installation

1. Prerequisites

  • Node.js v18+
  • Java JDK 21
  • PostgreSQL (running instance)
  • Maven 3.8+

2. Backend Setup

  1. Navigate to backend/:

    cd backend
  2. Copy the example env file and fill in your values:

    cp .env.example .env
  3. Edit .env with your configuration:

    # Database
    DB_URL=jdbc:postgresql://localhost:5432/ecommerce
    DB_USERNAME=your_db_username
    DB_PASSWORD=your_db_password
    
    # JWT
    JWT_SECRET=YourSuperSecretKeyMustBeAtLeast256BitsLong
    
    # Email (Gmail App Password)
    SPRING_MAIL_USERNAME[email protected]
    SPRING_MAIL_PASSWORD=your_app_password
    
    # Twilio SMS (optional β€” required for OTP)
    TWILIO_ACCOUNT_SID=your_twilio_account_sid
    TWILIO_AUTH_TOKEN=your_twilio_auth_token
    TWILIO_PHONE_NUMBER=+1234567890
  4. Build and run:

    mvn clean install
    mvn spring-boot:run

    The backend will start on http://localhost:8080.

3. Frontend Setup

  1. Navigate to frontend/:

    cd frontend
  2. Install dependencies:

    npm install
  3. Start the dev server:

    npm start
  4. Open your browser at http://localhost:4200.


πŸ” Security & Roles

Role Capabilities
USER Browse products, manage cart, manage addresses, place orders
ADMIN Create/edit/delete products & categories, view & update all orders

Note: To promote a user to admin, manually update the role column to ADMIN in the users table for the desired user.

API Access Rules

Endpoint Access
/api/auth/** Public
GET /api/products/** Public
/api/products/** Admin only (CUD operations)
/api/categories/** Public
/api/cart/** Authenticated users (USER)
/api/orders/** Authenticated users (USER)
/api/addresses/** Authenticated users (USER)

πŸ“ API Documentation

A complete Postman collection is provided at the project root:

ECommerce_API.postman_collection.json

Import this file into Postman to explore and test all endpoints.


πŸ§‘β€πŸ’» Development Notes

  • Domain-Driven Structure β€” Each backend domain is a self-contained module with its own controller, service interface, implementation, entities, repositories, and DTOs. This enables clean microservice extraction when needed.
  • Service Interfaces β€” All business logic is behind interfaces (CartService, OrderService, etc.) with corresponding Impl classes, following OCP and DIP.
  • UserService Abstraction β€” UserRepository is only accessed within the user/ package. All other domains use the UserService interface, reducing coupling.
  • Long userId Pattern β€” Service methods accept Long userId instead of the full User entity. Controllers extract the ID from @AuthenticationPrincipal and pass only the ID downstream.
  • Standalone Components β€” The Angular frontend uses standalone components with lazy-loaded routes (no NgModules).
  • Global Error Handling β€” GlobalExceptionHandler returns structured error responses for ResourceNotFoundException, BadRequestException, and validation errors.
  • Environment Variables β€” Spring Boot loads configuration from backend/.env via spring.config.import. See .env.example for all required keys.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published