Real‑time inventory tracking and sales console built with Spring Boot 3.5, JPA (PostgreSQL), WebSocket/STOMP, and Redis caching. A simple static UI (HTML/CSS/JS) consumes REST APIs and live stock updates.
- Backend: Spring Boot 3, REST, JPA, WebSocket (STOMP), Validation, Actuator, Redis
- Frontend: Static assets with SockJS + STOMP for live updates
- Live updates: Clients subscribe to
/topic/inventory-updatesand receive updates after each sale
src/main/java/com/inventoryapp/inventory_system/InventorySystemApplication.java— Spring Boot entry pointcontroller/InventoryController.java— REST API endpointsservice/InventoryService.java,service/InventoryServiceImpl.java— business logicconfig/WebSocketConfig.java— STOMP WebSocket endpoint/ws-inventory, topic/topicconfig/RedisConfig.java— Redis cache manager and JSON serializationmodel/Product.java,model/SaleTransaction.java— domain entitiesrepository/ProductRepository.java,repository/SaleTransactionRepository.java— data accessdto/ProductRequest.java,dto/SaleRequest.java— request DTOsexception/GlobalExceptionHandler.java— API error responsesresources/static/— UI (index.html,js/app.js,css/styles.css)resources/application.properties— port, DB, and actuator settingsresources/data.sql— optional seed data
- Add/list products via REST
- Process sales with validation and transaction logging
- Redis‑backed cache for product list (
@Cacheable("products")) - Real‑time stock updates broadcast to all connected clients
- Health/metrics via Spring Boot Actuator
- JDK 21
- PostgreSQL (configured at
localhost:5435) with userpostgresand passwordmysecretpassword - Redis (default
localhost:6379)
src/main/resources/application.properties (defaults):
- Server:
server.port=8080 - Postgres:
spring.datasource.url=jdbc:postgresql://localhost:5435/postgres - JPA:
spring.jpa.hibernate.ddl-auto=update,spring.jpa.show-sql=true - Actuator:
management.endpoints.web.exposure.include=health,metrics,info
Optional H2 profile snippets are present but commented out.
Using the Maven Wrapper:
# from the repo root (Windows PowerShell)
./mvnw.cmd spring-boot:runOpen the UI:
# PostgreSQL 16
docker run -d --name pg -e POSTGRES_PASSWORD=mysecretpassword -p 5435:5432 postgres:16
# Redis 7
docker run -d --name redis -p 6379:6379 redis:7Base URL: http://localhost:8080
-
GET
/api/inventory— list all products -
POST
/api/inventory— create a product- Body example:
{ "name": "Wireless Mouse", "sku": "WM123", "stockQuantity": 150, "price": 25.99 } -
POST
/api/inventory/sale— record a sale, returns updated product or 400/404 on errors- Body example:
{ "sku": "WM123", "quantitySold": 2 }
- STOMP endpoint:
/ws-inventory - Topic:
/topic/inventory-updates - See
resources/static/js/app.jsfor the SockJS/STOMP client usage.
./mvnw.cmd test- Cache serialization uses a configured
ObjectMapperto include type info for safe JSON deserialization in Redis (RedisConfig). - Business and validation errors are centralized in
GlobalExceptionHandler. - If you prefer in‑memory DB for quick demos, uncomment H2 settings in
application.propertiesand comment out Postgres.