SmartCart Ecommerce is a Spring Boot backend for core e-commerce workflows: authentication, category and product management, image upload, and shopping cart operations.
- JWT-based authentication with cookie session handling
- Role model with seeded
ROLE_USER,ROLE_SELLER, andROLE_ADMIN - Category CRUD APIs with pagination and sorting
- Product CRUD APIs with category filtering and keyword search
- Product image upload and static image hosting under
/images/** - User cart management (add, update quantity, remove, view cart)
- Global exception handling with consistent API error responses
- Java 21
- Spring Boot 4.0.2
- Spring Web MVC
- Spring Security + JWT (
jjwt) - Spring Data JPA
- PostgreSQL
- Maven Wrapper (
mvnw,mvnw.cmd)
src/main/java/com/psd/smartcart_ecommerce
|- config
|- controllers
|- exceptions
|- models
|- payload
|- repositories
|- security
|- services
|- util
src/main/resources
|- application.properties
- JDK 21
- PostgreSQL running locally
- Git + terminal (PowerShell, CMD, or bash)
Default config is in src/main/resources/application.properties.
Important properties:
spring.datasource.urlspring.datasource.usernamespring.datasource.passwordspring.app.jwtSecretspring.app.jwtExpirationMsspring.ecom.app.jwtCookieNamefrontend.urlproject.imageimage.base.url
For local development, make sure PostgreSQL credentials and DB URL match your environment.
.\mvnw.cmd spring-boot:run./mvnw spring-boot:runThe API starts at:
http://localhost:8080
| Username | Password | Roles |
|---|---|---|
user1 |
password1 |
ROLE_USER |
seller1 |
password2 |
ROLE_SELLER |
admin |
adminPass |
ROLE_USER, ROLE_SELLER, ROLE_ADMIN |
- Call
POST /api/auth/signinwith username/password. - Backend returns a JWT and sets cookie
springBootEcom(path/api). - Send this cookie in subsequent protected requests.
- Call
POST /api/auth/signoutto clear auth cookie.
Example login:
curl -i -c cookies.txt -X POST http://localhost:8080/api/auth/signin \
-H "Content-Type: application/json" \
-d '{"username":"user1","password":"password1"}'Example protected cart call:
curl -b cookies.txt http://localhost:8080/api/carts/users/cartPOST /api/auth/signupPOST /api/auth/signinPOST /api/auth/signoutGET /api/auth/usernameGET /api/auth/user
Signup body example:
{
"username": "newuser",
"email": "newuser@example.com",
"password": "strongpass123",
"role": ["user"]
}Supported role strings: admin, seller, user.
GET /api/public/categoriesPOST /api/public/categoriesPUT /api/public/categories/{categoryId}DELETE /api/admin/categories/{categoryId}
Category body example:
{
"categoryName": "Electronics"
}Pagination/sort query params (where supported):
pageNumber(default0)pageSize(default50)sortBy(default category:categoryId, product:productId)sortOrder(ascordesc, defaultasc)
POST /api/admin/categories/{categoryId}/productsGET /api/public/productsGET /api/public/categories/{categoryId}/productsGET /api/public/products/keyword/{keyword}PUT /api/admin/products/{productId}DELETE /api/admin/products/{productId}PUT /api/products/{productId}/image(multipart form-data)
Product body example:
{
"productName": "Wireless Mouse",
"description": "Ergonomic mouse with 2.4GHz receiver",
"quantity": 20,
"price": 25.0,
"discount": 10.0
}Image upload example:
curl -X PUT -b cookies.txt \
-F "image=@/path/to/product.jpg" \
http://localhost:8080/api/products/1/imagePOST /api/carts/products/{productId}/quantity/{quantity}GET /api/cartsGET /api/carts/users/cartPUT /api/cart/products/{productId}/quantity/{operation}DELETE /api/carts/{cartId}/product/{productId}
operation in cart update supports values like delete (decrement) or any other value (increment).
Validation errors:
{
"fieldName": "validation message"
}Business/resource errors:
{
"message": "Readable error message",
"status": false
}WebSecurityConfigcurrently permits"/api/admin/**"in the filter chain.- JWT cookie is currently created with
httpOnly(false).
These settings are suitable for development/testing but should be tightened before production deployment.
CORS allows:
http://localhost:3000frontend.urlfrom properties (defaulthttp://localhost:5173/)
Run tests:
./mvnw testCurrent automated test coverage is minimal (contextLoads).