Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

🚀 E-Commerce Backend API

Java Spring Boot Maven H2 License

A production-ready E-Commerce Backend built with Spring Boot 3.2.0 and Java 17. Features RESTful APIs for managing products and orders, JWT-based security, JPA/Hibernate for persistence, and comprehensive error handling.

✨ Features

  • Product Management: CRUD operations for products (create, read, update, delete).
  • Order Management: Place orders, view order history with items.
  • RESTful APIs: Clean, well-documented endpoints following REST conventions.
  • Spring Security: Secure endpoints with authentication & authorization.
  • Data Persistence: JPA/Hibernate with H2 (dev) & MySQL (prod) support.
  • Input Validation: Bean Validation (JSR-303) for robust request handling.
  • Global Exception Handling: Centralized error responses.
  • Production-Ready: Logging, health checks, actuator endpoints.

🛠 Tech Stack

Category Technologies
Backend Spring Boot 3.2.0, Spring Web, Spring Data JPA, Spring Security, Spring Validation
Database H2 (In-memory), MySQL 8.0
Language Java 17
Build Maven
ORM Hibernate
Validation Bean Validation API

📱 API Endpoints

Products

Method Endpoint Description
GET /api/products Get all products
GET /api/products/{id} Get product by ID
POST /api/products Create new product
PUT /api/products/{id} Update product
DELETE /api/products/{id} Delete product

Orders

Method Endpoint Description
POST /api/orders Place new order
GET /api/orders/{id} Get order by ID
GET /api/orders/user/{userId} Get orders by user

Request Examples:

Create Product:

{
  \"name\": \"iPhone 15\",
  \"description\": \"Latest iPhone model\",
  \"price\": 999.99,
  \"stock\": 50
}

Place Order:

{
  \"userId\": 1,
  \"items\": [
    {
      \"productId\": 1,
      \"quantity\": 2
    }
  ]
}

🚀 Quick Start

Prerequisites

  • Java 17+
  • Maven 3.8+
  • MySQL 8.0 (optional, H2 works out-of-box)

Clone & Run

git clone git clone https://github.com/Sparkydev007/springboot-ecommerce-backend.git
cd ecommerce-backend
mvn spring-boot:run

Server runs on http://localhost:8080

Database Setup (MySQL)

  1. Create database: ecommerce_db
  2. Update application.yml:
spring:
  datasource:
    url: jdbc:mysql://localhost:3306/ecommerce_db
    username: root
    password: yourpassword
  jpa:
    hibernate:
      ddl-auto: update

API Testing

Use Postman, curl, or Swagger (add springdoc-openapi-ui dependency for Swagger UI).

Sample curl:

# Get products
curl -X GET http://localhost:8080/api/products

# Create product
curl -X POST http://localhost:8080/api/products \\
  -H \"Content-Type: application/json\" \\
  -d '{\"name\":\"Laptop\",\"price\":1299.99,\"stock\":10}'

🏗 Project Structure

ecommerce-backend/
├── src/main/java/com/ecommerce/
│   ├── EcommerceApplication.java      # Main Spring Boot app
│   ├── config/                        # Security & config
│   ├── controller/                    # REST controllers
│   ├── dto/                           # Data Transfer Objects
│   ├── entity/                        # JPA entities
│   ├── exception/                     # Global exception handler
│   ├── repository/                    # JPA repositories
│   └── service/                       # Business logic
└── src/main/resources/
    └── application.yml                # App configuration

🔒 Security

  • Protected endpoints require authentication.
  • Add Spring Security JWT dependency for token-based auth.
  • Customize SecurityConfig.java for your needs.

🧪 Testing

mvn test

📈 Performance & Monitoring

Spring Boot Actuator endpoints:

  • /actuator/health
  • /actuator/info
  • /actuator/metrics

🤝 Contributing

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

📄 License

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

👨‍💻 Author

Prathmesh Bunde
LinkedIn | Leetcode


Star this repo if you found it helpful!

Made with ❤️ using Spring Boot

About

Spring Boot backend system implementing secure REST APIs for e-commerce operations including product inventory management, order processing, and role-based authentication with real-world business logic

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages