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.
- 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.
| 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 |
| 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 |
| 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
}
]
}- Java 17+
- Maven 3.8+
- MySQL 8.0 (optional, H2 works out-of-box)
git clone git clone https://github.com/Sparkydev007/springboot-ecommerce-backend.git
cd ecommerce-backend
mvn spring-boot:runServer runs on http://localhost:8080
- Create database:
ecommerce_db - Update
application.yml:
spring:
datasource:
url: jdbc:mysql://localhost:3306/ecommerce_db
username: root
password: yourpassword
jpa:
hibernate:
ddl-auto: updateUse 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}'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
- Protected endpoints require authentication.
- Add Spring Security JWT dependency for token-based auth.
- Customize
SecurityConfig.javafor your needs.
mvn testSpring Boot Actuator endpoints:
/actuator/health/actuator/info/actuator/metrics
- Fork the project
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Prathmesh Bunde
LinkedIn | Leetcode
⭐ Star this repo if you found it helpful! ⭐
Made with ❤️ using Spring Boot