Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

e-commerceSpring Backend

A Spring Boot and MongoDB backend that models a small e-commerce workflow across products, carts, orders, and payments. It was created as coursework while learning Java backend development and is presented as a supporting learning project rather than a production-ready system.

Domain features

  • Create and list products
  • Add products to a user's cart, view the cart, and clear it
  • Convert cart items into an order and calculate the total from current product prices
  • Reduce product stock during order creation
  • Create a pending payment and process a simulated payment webhook
  • Update an order to PAID or FAILED from the webhook result
  • Validate cart, order, payment, and webhook request DTOs

Technology stack

  • Java 17
  • Spring Boot 3.5
  • Spring Web and Bean Validation
  • Spring Data MongoDB
  • Maven Wrapper
  • JUnit 5, Mockito, AssertJ, and MockMvc

Architecture and project structure

ecommerce/src/
├── main/java/com/example/ecommerce/
│   ├── config/       # Shared Spring beans
│   ├── controller/   # REST endpoints
│   ├── dto/          # Validated request payloads
│   ├── model/        # MongoDB domain documents
│   ├── repository/   # Spring Data repositories
│   └── service/      # Cart, order, payment, and product behaviour
├── main/resources/   # Environment-based application configuration
└── test/             # Configuration, validation, service, and controller tests

Controllers accept HTTP requests, services coordinate domain behaviour, and Spring Data repositories persist documents in MongoDB.

Prerequisites and configuration

  • Java 17
  • A MongoDB database you manage separately

Set MONGODB_URI in your shell before starting the application. PORT is optional and defaults to 8080.

export MONGODB_URI='your MongoDB connection value'
export PORT=8080

Spring Boot does not automatically load JavaScript-style .env files. Use shell environment variables or configure the same variables in your IDE run configuration. Do not commit local connection values or local override property files.

Build and run locally

From the repository root:

cd ecommerce
./mvnw clean package
./mvnw spring-boot:run

Startup fails clearly if MONGODB_URI is missing.

API endpoint summary

Method Endpoint Behaviour
POST /api/products Create a product
GET /api/products List all products
POST /api/cart/add Add an item to a cart
GET /api/cart/{userId} List a user's cart items
DELETE /api/cart/{userId}/clear Clear a user's cart
POST /api/orders Create an order from a user's cart
GET /api/orders/{id} Retrieve an order by ID
POST /api/payments/create Create a simulated pending payment
POST /api/webhooks/payment Apply a SUCCESS or FAILED payment result

Create a harmless sample product:

curl -X POST http://localhost:8080/api/products \
  -H 'Content-Type: application/json' \
  -d '{"name":"Notebook","description":"Sample stationery item","price":5.50,"stock":20}'

Add it to a sample cart after replacing the product ID:

curl -X POST http://localhost:8080/api/cart/add \
  -H 'Content-Type: application/json' \
  -d '{"userId":"sample-user","productId":"PRODUCT_ID","quantity":2}'

Testing

Tests use mocked repositories and services; they do not require a live MongoDB cluster. The context test uses a local-only test setting and does not perform database operations.

cd ecommerce
./mvnw test
./mvnw -DskipTests package

Security considerations

  • Supply MongoDB configuration through MONGODB_URI; no database URL is logged by application code.
  • Keep credentials out of Git and rotate any value that was previously committed.
  • Historical credentials should be treated as invalidated. Cleaning the current branch does not erase older Git commits.
  • This coursework project does not implement authentication, authorization, webhook signatures, or production payment processing.

Current limitations

  • No authentication or user accounts
  • Product payloads have no dedicated validated DTO
  • Stock updates are not transactionally coordinated with order creation
  • The payment flow is a local simulation that schedules a callback to localhost:8080
  • No pagination, idempotency controls, or centralized API error model
  • No integration test suite against MongoDB

There is no maintained public deployment of this coursework project.

About

Spring Boot and MongoDB e-commerce backend covering products, carts, orders, payments, DTO validation, and REST configuration.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages