Skip to content

Sathish292004/E-com-Updated-Backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

28 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

βš™οΈ Spring-Ecom β€” E-Com Backend (Updated)

Full-featured REST API backend for the SK Store e-commerce platform, built with Spring Boot. This is the fleshed-out version of the backend β€” JWT + Google OAuth2 auth, an admin panel, and full product/cart/order/review flows are all wired up end-to-end.

πŸ”— Frontend: E-com-new Β· 🌐Live demo

Java Spring Boot PostgreSQL JWT Swagger Docker

πŸ“– Overview

This service is the API layer for the SK Store storefront. Customers can browse products/categories, manage a cart and wishlist, place and track orders, leave reviews, and manage their profile/addresses. Admins get a separate login and dashboard for managing customers, orders, and reviews.

βœ… Status: Actively developed. Core commerce flows (auth, catalog, cart, wishlist, orders, reviews, addresses) are implemented end-to-end; automated test coverage is still minimal.

🧰 Tech Stack

Category Library
β˜• Language Java 21
🌱 Framework Spring Boot 4.1.0
🌐 Web Spring Web MVC (spring-boot-starter-webmvc)
πŸ—„οΈ Persistence Spring Data JPA (+ JPA Specifications for filtering)
🐘 Database PostgreSQL
πŸ” Security Spring Security, BCrypt password hashing
πŸ”‘ Auth JWT (jjwt 0.12.7) + Google OAuth2 login
πŸ“œ API Docs springdoc-openapi / Swagger UI
βœ… Validation Spring Boot Validation
✨ Boilerplate Lombok
πŸ“Š Monitoring Spring Boot Actuator
πŸ”¨ Build Tool Maven (with Maven Wrapper)
🐳 Containerization Docker (multi-stage build)
βš™οΈ CI/CD GitHub Actions β†’ Azure Web App

πŸ“ Project Structure

E-com-Updated-Backend/
β”œβ”€β”€ .github/workflows/         # CI/CD β€” build & deploy to Azure Web App
β”œβ”€β”€ .mvn/wrapper/               # Maven wrapper files
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ main/java/Sathish292004/
β”‚   β”‚   β”œβ”€β”€ config/             # Security, CORS, Swagger, password encoder
β”‚   β”‚   β”œβ”€β”€ controller/         # REST controllers
β”‚   β”‚   β”œβ”€β”€ dto/
β”‚   β”‚   β”‚   β”œβ”€β”€ request/        # Request payloads
β”‚   β”‚   β”‚   └── response/       # Response payloads
β”‚   β”‚   β”œβ”€β”€ exception/          # Custom exceptions + global handler
β”‚   β”‚   β”œβ”€β”€ model/               # JPA entities
β”‚   β”‚   β”œβ”€β”€ repository/         # Spring Data JPA repositories
β”‚   β”‚   β”œβ”€β”€ security/            # JWT filter/service, OAuth2 success handler
β”‚   β”‚   β”œβ”€β”€ service/             # Business logic
β”‚   β”‚   β”œβ”€β”€ specification/      # Dynamic product filtering (JPA Specifications)
β”‚   β”‚   └── SpringEcomApplication.java
β”‚   β”œβ”€β”€ main/resources/
β”‚   β”‚   └── application.properties
β”‚   └── test/java/Sathish292004/
β”œβ”€β”€ Dockerfile                  # Multi-stage build (Maven β†’ JRE 21)
β”œβ”€β”€ mvnw / mvnw.cmd              # Maven wrapper scripts
└── pom.xml

πŸš€ Getting Started

βœ… Prerequisites

  • Java 21 (JDK)
  • PostgreSQL (local instance or remote)
  • A Google OAuth2 Client ID/Secret (see note below)
  • Maven not required β€” the project includes the Maven Wrapper (mvnw)

πŸ” Configuration

This app reads config from environment variables, not hardcoded defaults in application.properties. All five must be set, or Spring Boot will fail to start (the placeholders can't resolve otherwise):

Variable Description
DB_URL JDBC URL, e.g. jdbc:postgresql://localhost:5432/ecom
DB_USERNAME PostgreSQL username
DB_PASSWORD PostgreSQL password
GOOGLE_CLIENT_ID Google OAuth2 client ID
GOOGLE_CLIENT_SECRET Google OAuth2 client secret
export DB_URL=jdbc:postgresql://localhost:5432/ecom
export DB_USERNAME=your_db_username
export DB_PASSWORD=your_db_password
export GOOGLE_CLIENT_ID=your_google_client_id
export GOOGLE_CLIENT_SECRET=your_google_client_secret

Hibernate is set to ddl-auto=update, so tables are created/updated automatically on startup.

▢️ Running Locally

git clone https://github.com/Sathish292004/E-com-Updated-Backend.git
cd E-com-Updated-Backend

# Run with the Maven wrapper
./mvnw spring-boot:run        # macOS/Linux
mvnw.cmd spring-boot:run       # Windows

# Or build a jar and run it
./mvnw clean package -DskipTests
java -jar target/*.jar

The API starts on port 8080 by default.

🐳 Running with Docker

docker build -t ecom-backend .
docker run -p 8080:8080 \
  -e DB_URL=jdbc:postgresql://host.docker.internal:5432/ecom \
  -e DB_USERNAME=your_db_username \
  -e DB_PASSWORD=your_db_password \
  -e GOOGLE_CLIENT_ID=your_google_client_id \
  -e GOOGLE_CLIENT_SECRET=your_google_client_secret \
  ecom-backend

The Dockerfile does a multi-stage build: it compiles with Maven on maven:3.9.8-eclipse-temurin-21, then runs the resulting jar on a lightweight eclipse-temurin:21-jre image.

πŸ“š API Docs

Interactive Swagger UI (with a "bearer token" authorize button for JWTs) is available once the app is running:

http://localhost:8080/swagger-ui.html

Raw OpenAPI spec: GET http://localhost:8080/v3/api-docs

❀️ Health Check

GET http://localhost:8080/actuator/health

πŸ”‘ Authentication & Roles

There are two user types, distinguished by role (CUSTOMER / ADMIN) and enforced with Spring Security:

Flow Endpoint Notes
Customer register POST /api/auth/register Creates a customer, password hashed with BCrypt
Customer login POST /api/auth/login Returns a JWT
Customer Google login GET /oauth2/authorization/google Auto-creates a customer on first login, redirects to the frontend with a JWT
Admin login POST /api/admin/login Returns a JWT with the ADMIN role

Protected endpoints expect:

Authorization: Bearer <token>

πŸ—‚οΈ API Modules

Module Base path Access
Customer auth /api/auth/** Public
Admin auth /api/admin/login Public
Products & categories /api/products/**, /api/product/**, /api/categories, /api/category/** Public browsing/search
Cart, wishlist, addresses, profile /api/customer/** CUSTOMER role
Orders /api/orders/** Authenticated
Reviews /api/products/{id}/reviews, /api/customer/products/{id}/reviews Reading needs auth; posting needs CUSTOMER role
Admin dashboard, customers, orders, reviews /api/admin/** ADMIN role

πŸ—ΊοΈ Roadmap

  • πŸ›’ Product, category, cart, wishlist & order entities
  • πŸ”‘ JWT + Google OAuth2 authentication, role-based access
  • 🧾 Cart, wishlist, and order management endpoints
  • πŸ“š API documentation via Swagger / OpenAPI
  • πŸ§ͺ Real test coverage (currently just a context-load smoke test)
  • πŸ’³ Payment gateway integration
  • πŸ–ΌοΈ Move product images out of the DB into object storage

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

Sathish Kumar B

πŸ”— GitHub: github.com/Sathish292004


⭐ If you found this useful, consider giving the repo a star!

About

πŸ›  Spring Boot REST API for the SK Store e-commerce platform, with JWT + Google OAuth2 auth, PostgreSQL, and Swagger docs.

Topics

Resources

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors