A hands-on e-commerce backend built while learning Spring and Spring Boot from the ground up β every concept learned is immediately implemented here, turning theory into a real, structured, production-style project.
This is a layered, RESTful e-commerce backend built to reinforce core Spring Boot concepts through practical implementation. Instead of isolated tutorials, every feature β exception handling, pagination, DTO mapping, image uploads β is built directly into a working application with a clean package structure and consistent API design.
7 days in, the project already covers full CRUD for Categories and Products, complete with search, filtering, sorting, pagination, and image handling β with Spring Security as the next milestone.
| Layer | Technology |
|---|---|
| Language | Java 25 |
| Framework | Spring Boot 4.1.0 |
| Web | Spring Web MVC |
| Persistence | Spring Data JPA + Hibernate |
| Database | H2 (in-memory, with H2 Console) |
| Object Mapping | ModelMapper 3.2.6 |
| Boilerplate Reduction | Lombok |
| Validation | Spring Boot Starter Validation |
| Testing | Spring Boot Starter Test |
| Build Tool | Maven |
spring-boot-starter-webmvc β’ spring-boot-starter-webmvc-test β’ spring-boot-h2console β’ spring-boot-starter-data-jpa β’ lombok β’ spring-boot-starter-validation β’ modelmapper
The project follows a clean layered architecture, separating concerns across Controller β Service β Repository β Database, with DTOs decoupling the API contract from internal entities.
graph TD
A[Client / Postman / Frontend] -->|HTTP Request| B[Controller Layer]
B --> C[Service Interface]
C --> D[Service Implementation]
D -->|ModelMapper: Entity <-> DTO| E[DTO / Payload Layer]
D --> F[Repository Layer - JPA]
F --> G[(H2 Database)]
D --> H[Exception Handling]
H -->|Custom Exceptions| I[GlobalExceptionHandler]
I -->|API Response| B
B -->|JSON Response| A
style A fill:#1e293b,stroke:#38bdf8,color:#fff
style G fill:#1e293b,stroke:#facc15,color:#fff
style I fill:#1e293b,stroke:#f87171,color:#fff
com.sougata.ecommerce.project
βββ config β AppConfig, AppConstants
βββ controller β CategoryController, ProductController
βββ exceptions β APIException, ResourceNotFoundException, GlobalExceptionHandler
βββ model β Category, Product
βββ payload β DTOs & Response wrappers (APIResponse, CategoryDTO, ProductDTO, etc.)
βββ repositories β CategoryRepository, ProductRepository
βββ service β CategoryService, ProductService, FileService (+ Implementations)
sequenceDiagram
participant Client
participant Controller
participant Service
participant Repository
participant DB as H2 Database
Client->>Controller: GET /public/categories/1/products?pageNumber=0&pageSize=5&sortBy=productId&sortOrder=asc
Controller->>Service: getProductsByCategory(categoryId, pageDetails)
Service->>Repository: findByCategory(category, pageable)
Repository->>DB: SQL Query (LIMIT / OFFSET / ORDER BY)
DB-->>Repository: Result Set
Repository-->>Service: Page<Product>
Service->>Service: Map Entity β DTO (ModelMapper)
Service-->>Controller: ProductResponse (with pagination metadata)
Controller-->>Client: 200 OK + JSON
erDiagram
CATEGORY ||--o{ PRODUCT : contains
CATEGORY {
Long categoryId PK
String categoryName
}
PRODUCT {
Long productId PK
String productName
String image
int quantity
double price
double discount
double specialPrice
Long categoryId FK
}
- β Full CRUD REST APIs for Category and Product
- β
Custom exception handling (
APIException,ResourceNotFoundException,GlobalExceptionHandler) - β
Pagination & Sorting (
pageNumber,pageSize,sortBy,sortOrder) - β Search by keyword, category, and ID
- β DTO-based clean API contracts using ModelMapper
- β
Product image upload & update via
FileService - β
API Versioning (
/api/v1/...) - β Layered OOP-driven design (interfaces + implementations)
- β JPA / Hibernate ORM with H2 in-memory database
- β 40+ structured, incremental GitHub commits
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/public/categories |
Get all categories |
POST |
/api/v1/public/categories |
Create a new category |
PUT |
/api/v1/public/categories/{categoryId} |
Update a category |
DELETE |
/api/v1/admin/categories/{categoryId} |
Delete a category |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/v1/public/products |
Get all products |
GET |
/api/v1/public/categories/{categoryId}/products |
Get products by category |
GET |
/api/v1/public/products/keyword/{keyword} |
Search products by keyword |
POST |
/api/v1/admin/categories/{categoryId}/product |
Add a product to a category |
PUT |
/api/v1/admin/product/{productId} |
Update a product |
PUT |
/api/v1/products/{productId}/image |
Update product image |
DELETE |
/api/v1/admin/products/{productId} |
Delete a product |
?pageNumber=0&pageSize=5&sortBy=productId&sortOrder=asc
Example:
GET /api/v1/public/categories/1/products?pageNumber=0&pageSize=5&sortBy=productId&sortOrder=asc
# Clone the repository
git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>
# Run the application
./mvnw spring-boot:runThe app runs on http://localhost:8080 by default.
H2 Console: http://localhost:8080/h2-console
| Status | Milestone |
|---|---|
| β | Category & Product CRUD APIs |
| β | Exception handling & validation |
| β | Pagination, sorting & search |
| β | Image upload |
| β | API versioning |
| π | Spring Security (Authentication & Authorization) |
| π | JWT-based stateless auth |
| π | Cart & Order management |
| π | Payment integration |
| π | Unit & Integration testing |
| π | Deploying on AWS |
Built as part of a 7-day intensive Spring Boot learning sprint β the goal isn't just to follow tutorials, but to build while learning, turning every new concept (OOP principles, exception design, JPA relationships, DTO patterns) into working, committed code.
This project is for learning purposes and open for feedback, suggestions, and contributions.