E-Commerce Lite is a simplified online store backend API built with Spring Boot. It provides core e-commerce functionality including user management, product catalog, and order processing with inventory management.
- User Management: Create and manage customer profiles
- Product Catalog: Full CRUD operations for products with inventory tracking
- Order System: Process orders with automatic stock validation and total calculation
- Inventory Management: Real-time stock updates with business logic enforcement
- RESTful API: Clean JSON API for frontend clients
users (id, email, name, created_date)
products (id, name, description, price, stock_quantity, created_date)
orders (id, user_id, total_amount, status, created_date)
order_items (id, order_id, product_id, quantity, price)- Orders automatically calculate totals based on product prices
- Stock quantities are validated before order processing
- Inventory is updated in real-time upon successful orders
- Orders cannot exceed available stock quantities
src/main/java/com/ecommerce/ecommercelite/
├── config/
│ └── SwaggerConfig.java # API documentation
├── controller/
│ ├── UserController.java # User management endpoints
│ ├── ProductController.java # Product catalog endpoints
│ └── OrderController.java # Order processing endpoints
├── dto/
│ ├── OrderRequest.java # Order creation payload
│ ├── OrderResponse.java # Order response format
│ ├── ProductRequest.java # Product creation/update payload
│ └── UserRequest.java # User creation payload
├── entity/
│ ├── User.java # User entity with orders relationship
│ ├── Product.java # Product entity with inventory
│ ├── Order.java # Order entity with total calculation
│ └── OrderItem.java # Order-item join entity
├── repository/
│ ├── UserRepository.java # User data access
│ ├── ProductRepository.java # Product data access
│ └── OrderRepository.java # Order data access
├── service/
│ ├── UserService.java # User business logic
│ ├── ProductService.java # Product business logic
│ └── OrderService.java # Order processing logic
└── EcommerceLiteApplication.java # Main application class
src/main/resources/
├── application.properties # Database & server configuration
└── data.sql # Optional sample data
src/test/java/com/ecommerce/ecommercelite/
├── service/
│ ├── UserServiceTest.java
│ ├── ProductServiceTest.java
│ └── OrderServiceTest.java
└── controller/
├── UserControllerTest.java
├── ProductControllerTest.java
└── OrderControllerTest.java
- Framework: Spring Boot 3.2.x
- Database: MySQL with Spring Data JPA
- Build Tool: Maven
- Java Version: 17+
- Validation: Bean Validation API
- Documentation: SpringDoc OpenAPI
- Spring Data JPA for database operations
- Spring MVC for REST controllers
- Transaction management for data consistency
- Bean validation for input sanitization
- Repository pattern for data access abstraction
GET /api/users- List all usersGET /api/users/{id}- Get user by IDPOST /api/users- Create new userGET /api/users/{id}/orders- Get user's order history
GET /api/products- List all products (with pagination)GET /api/products/{id}- Get product detailsPOST /api/products- Create new product (admin)PUT /api/products/{id}- Update product (admin)DELETE /api/products/{id}- Delete product (admin)
GET /api/orders- List all ordersGET /api/orders/{id}- Get order detailsPOST /api/orders- Create new orderPUT /api/orders/{id}/cancel- Cancel order
- Request Validation: Validate order items and quantities
- Stock Check: Verify sufficient inventory for all items
- Price Calculation: Calculate order total using current product prices
- Inventory Update: Reduce stock quantities atomically
- Order Creation: Save order with items in single transaction
- Response: Return order confirmation with details
- One-to-Many: User → Orders
- One-to-Many: Order → OrderItems
- Many-to-One: OrderItem → Product
- Bi-directional: Orders can navigate to User and Products
- Service classes encapsulate complex business rules
- Transactional boundaries ensure data consistency
- Custom exceptions for business rule violations
- Automatic total calculations and inventory management
- Java 17+
- MySQL 8.0+
- Maven 3.6+
# Database
spring.datasource.url=jdbc:mysql://localhost:3306/ecommerce_db
spring.datasource.username=username
spring.datasource.password=password
# JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=truemvn spring-boot:run- Unit tests for service layer business logic
- Integration tests for repository layer
- MockMvc tests for controller endpoints
- Test data builders for easy test creation
- Transaction rollback for test isolation
By building this project, you'll master:
- Spring Boot application structure and best practices
- JPA entity relationships and mapping
- REST API design and implementation
- Transaction management and data consistency
- Business logic layer development
- Testing strategies for Spring applications
- Database design for real-world scenarios
Ready to start coding? This structure will give us a professional-grade Spring Boot application that demonstrates real e-commerce functionality while following industry best practices.