ShopStream Hackathon Β· Reactive Commerce Advisor Built with Spring Boot 3.x, React 18, and Vite
ShopStream's StockPulse replaces slow spreadsheets and reactive email debates with an autonomous, agentic commercial advisor. When inventory drops below safety thresholds or social velocity surges, StockPulse detects it in real time, formulates context-aware pricing and replenishment recommendations via LLM reasoning (or deterministic rule baselines), and places both proposals before merchandisers for one-click approval.
(\text{Observe (Signal)} \longrightarrow \text{Reason (AI Advisor)} \longrightarrow \text{Act (Queue Proposal)} \longrightarrow \text{Checkpoint (Human Approval)})
- Java 21+ (
java -version) - Node.js 18+ & npm (
node -v,npm -v) - Docker & Docker Compose (optional, for containerized deployment)
Before running the application, configure your environment variables.
- Copy the template file:
cp .env.template .env- Edit
.envand update it with your actual credentials.
Note: Never commit the
.envfile containing real credentials to version control.
# Build and start all services
docker-compose up --build
# Or run in detached mode
docker-compose up --build -dConfigure environment variables securely and start the backend.
PowerShell (Windows):
.\setup-env.ps1
cd Backend
.\mvnw.cmd spring-boot:runBash / macOS / Linux:
source ./setup-env.sh
cd Backend
./mvnw spring-boot:runBackend services:
- Backend API:
http://localhost:8080 - H2 Console:
http://localhost:8080/h2-console - JDBC URL:
jdbc:h2:mem:stockpulse - Username:
sa - Password: (empty)
- Preloaded with 8 Addendum A catalogue products and initial demo suggestions.
- AI Gateway: Reads
LLM_API_KEYdynamically from the environment without committing credentials.
Open a second terminal:
cd Frontend
npm install
npm run devOpen the frontend at:
http://localhost:5173
-
On the console, locate PRD-003 (
Organic Cotton T-Shirt). -
Initial seed state:
- Stock =
8 units - Reorder Threshold =
15 units - Status =
PRICE_REVIEW_PENDING
- Stock =
-
The Merchandising Decision Desk displays an initial pending proposal with the
INVENTORY_LOWbadge. -
Review the AI reasoning and confidence score.
-
Click
Publish Price:- Price updates atomically from $24.99 to $27.49.
- Product lifecycle status transitions back to
ACTIVE.
-
Click
Authorize Reorder:- Inbound shipment is simulated.
- Stock increases from 8 to 45 units.
- An audit trail snapshot is recorded in
inventory_snapshots.
-
In the Catalog Board, locate PRD-008 (
Hoodie β Heather Grey). -
Initial state:
- Stock =
11 units - Velocity =
15 orders/24h
- Stock =
-
Click the
π₯ +5 Viralbutton or send:
POST http://localhost:8080/products/PRD-008/orders
Content-Type: application/json
{
"quantity": 5
}- The order endpoint returns immediately (
<15ms). - In the background, the agentic event listener detects that velocity surged to 20 orders/24h, surpassing the category peer benchmark.
- Within approximately 3 seconds, a new proposal card appears on the Decision Desk with the
DEMAND_SPIKEbadge. - Click
Publish Priceto apply the recommendation.
- On any SKU row, such as PRD-001 (
Wireless Earbuds Pro), clickβ‘ Stream AI. - The console connects to:
POST /products/PRD-001/suggest-pricing/stream
- AI reasoning tokens are streamed live in real time.
- The finalized recommendation is automatically persisted and becomes available for approval.
- In the header bar, open the Engine dropdown.
- Switch between:
-
Rule-Based Engine (Deterministic)
- Strict deterministic formula.
+10%on low stock.+5%on a 2x velocity spike.
-
AI Commerce Advisor (LLM Flash)
- LLM-based contextual reasoning.
- Bounds sanity checking.
-
Competitor-Aware Engine
- Pluggable market strategy.
- Respects wholesale margin floors.
- Strategy changes require no code changes and no server restart.
- Click the
βΉοΈbutton next to any product's price. - The modal displays:
- Wholesale Cost (
costPrice) - Competitor Price Benchmark (
competitorPrice) - Supplier Catalog ID (
supplierId) - Calculated Gross Margin %
StockPulse uses environment variables loaded from a .env file to protect sensitive credentials.
- Copy the template:
cp .env.template .env- Edit the
.envfile:
LLM_API_KEY=your_actual_api_key_here
LLM_PROVIDER=litellm
LLM_MODEL=qwen-cursor
LLM_BASE_URL=https://your-llm-provider-endpoint
LLM_HEADER_PRODUCT=PC1
LLM_HEADER_COOKIE=your_actual_cookie_value_here- Load environment variables:
Windows (PowerShell):
.\setup-env.ps1Linux/macOS:
source ./setup-env.sh- π Never commit the
.envfile to version control. - π Store credentials securely using your organization's secrets management system.
- π Rotate API keys regularly.
- π₯ Limit access to environment configuration files.
The .env file is included in .gitignore to prevent accidental commits.
org.zycus
βββ agentic
β βββ event
β β βββ StockDepletedEvent
β β βββ DemandSpikeEvent
β βββ listener
β βββ AgenticRecommendationListener
β βββ Async processing + idempotency guard
β
βββ commerce
β βββ advisor
β β βββ CommerceAdvisorService
β βββ ai
β β βββ LLMGateway
β β βββ PromptBuilder
β β βββ BoundsValidator
β β βββ AIAdvisorOrchestrator
β βββ context
β β βββ CommerceContext
β βββ strategy
β βββ PricingStrategy
β βββ ReorderStrategy
β βββ RuleBased
β βββ AI
β βββ CompetitorAware
β βββ StrategyRegistry
β
βββ domain
β βββ model
β β βββ Product
β β βββ PricingSuggestion
β β βββ ReorderSuggestion
β β βββ InventorySnapshot
β β βββ Enums
β βββ repository
β βββ ProductRepository
β βββ PricingSuggestionRepository
β βββ ReorderSuggestionRepository
β βββ InventorySnapshotRepository
β
βββ service
β βββ ProductService
β βββ PricingSuggestionService
β βββ ReorderSuggestionService
β
βββ web
βββ controller
β βββ ProductController
β βββ PricingSuggestionController
β βββ ReorderSuggestionController
β βββ StrategyConfigController
β βββ SSEStreamController
βββ dto
βββ CreateProductRequest
βββ UpdateStockRequest
βββ SimulateOrderRequest
βββ UpdateSuggestionStatusRequest
βββ StrategyConfigDto
The StockPulse persistence layer is centered around the PRODUCTS entity. Pricing recommendations, reorder recommendations, and inventory history are associated with individual products.
erDiagram
PRODUCTS {
string id PK
string sku UK
string name
string category
decimal current_price
int stock_level
int reorder_threshold
int demand_velocity
string status
decimal cost_price
string supplier_id
decimal competitor_price
datetime created_at
datetime updated_at
}
PRICING_SUGGESTIONS {
long id PK
string product_id FK
decimal current_price
decimal recommended_price
string change_direction
double confidence
string reasoning
string status
string trigger_reason
string strategy_used
datetime created_at
datetime updated_at
}
REORDER_SUGGESTIONS {
long id PK
string product_id FK
int current_stock
int recommended_quantity
int suggested_lead_time_days
double confidence
string reasoning
string status
string trigger_reason
string strategy_used
datetime created_at
datetime updated_at
}
INVENTORY_SNAPSHOTS {
long id PK
string product_id FK
int stock_level
int demand_velocity
string event_type
string notes
datetime timestamp
}
PRODUCTS ||--o{ PRICING_SUGGESTIONS : "has"
PRODUCTS ||--o{ REORDER_SUGGESTIONS : "has"
PRODUCTS ||--o{ INVENTORY_SNAPSHOTS : "has"
| Relationship | Cardinality | Description |
|---|---|---|
PRODUCTS β PRICING_SUGGESTIONS |
1 : N |
A product can have multiple pricing recommendations. |
PRODUCTS β REORDER_SUGGESTIONS |
1 : N |
A product can have multiple reorder recommendations. |
PRODUCTS β INVENTORY_SNAPSHOTS |
1 : N |
A product can have multiple historical inventory snapshots. |
Note:
category,status, andtrigger_reasonare represented as application-level enums rather than separate database tables.
graph TD
A[Frontend - React/Vite] --> B[Backend API - Spring Boot]
B --> C[(H2 Database)]
subgraph Backend_Layers
B --> D[Controllers]
D --> E[Services]
E --> F[Repositories]
F --> C
E --> G[Commerce Engine]
G --> H[AI Advisor]
G --> I[Rule Engine]
E --> J[Agentic Loop]
J --> K[Event Listeners]
end
subgraph External_Services
H --> L[LLM Providers]
end
subgraph Events
E -->|StockDepletedEvent| K
E -->|DemandSpikeEvent| K
K -->|Async Processing| G
end
- Complete JPA domain model for products, pricing suggestions, reorder suggestions, and inventory snapshots.
- Product lifecycle states including
ACTIVE,PRICE_REVIEW_PENDING, andOUT_OF_STOCK. - Product SKU uniqueness validation.
- Inventory tracking with stock level, reorder threshold, and demand velocity.
- Sprint 2 product extensions for wholesale cost, supplier catalog ID, and competitor pricing.
- H2 database persistence for local development and demonstration.
- Preloaded catalogue products and initial recommendation data.
- Pluggable
PricingStrategyinterface for pricing recommendation generation. - Deterministic rule-based pricing strategy.
- AI-powered contextual pricing recommendations.
- Competitor-aware pricing strategy.
- Runtime strategy switching without application restart.
- Price bounds validation and sanity checking.
- Pricing recommendations include confidence, reasoning, trigger reason, and strategy metadata.
- Dedicated
ReorderStrategyabstraction. - Rule-based inventory replenishment recommendations.
- AI-assisted reorder recommendations.
- Recommended quantity and lead-time calculation.
- Reorder suggestions connected directly to product inventory state.
- Centralized
LLMGatewayabstraction for LLM providers. - Support for Gemini, Groq, and Ollama providers.
- Offline/rule-based fallback when an external LLM is unavailable.
- Separate prompts for low-stock and demand-spike scenarios.
- Context-aware reasoning using commerce data and category averages.
BoundsValidatorto prevent unsafe or unrealistic AI-generated recommendations.
- Spring application events for inventory and demand signals.
StockDepletedEventfor low inventory conditions.DemandSpikeEventfor abnormal demand velocity.- Asynchronous recommendation processing using
@Async. - Idempotency guard to prevent duplicate recommendation processing.
- Rule-based fallback for resilient recommendation generation.
- Human approval checkpoint before recommendations are applied.
- React 18 + Vite merchandising interface.
- Executive-style dark UI.
- Interactive Catalog Board.
- Merchandising Decision Desk.
- Trigger badges for
INVENTORY_LOWandDEMAND_SPIKE. - AI reasoning and confidence visibility.
- One-click price publishing.
- One-click reorder authorization.
- Interactive demo triggers for testing inventory and demand scenarios.
- Gross margin visibility.
- Server-Sent Events implementation for AI recommendation streaming.
- Live AI reasoning token display.
- Streaming endpoint:
POST /products/{id}/suggest-pricing/stream
- Final recommendation automatically persisted after streaming completes.
- Strategy Pattern for pricing and reorder engines.
- Runtime
StrategyRegistryfor selecting active strategies. - Separation of controller, service, domain, repository, commerce, and agentic layers.
- DTO-based API boundary.
- Dedicated repository layer using Spring Data JPA.
- Event-driven separation between business operations and recommendation processing.
- Architecture documented through
ADR.md.
- Environment-based configuration for LLM credentials.
.envexcluded through.gitignore.- Credentials are not hardcoded into the application.
- Runtime loading of LLM configuration.
- Dedicated environment setup scripts for Windows and Unix-based systems.
- Backend unit and integration test suite.
- Maven-based test execution.
- Verification of core business and API functionality.
- Test suite reports 0 failures and 0 errors.
Run the backend test suite:
cd Backend
./mvnw.cmd testThe project test suite completes with 0 failures and 0 errors.