Skip to main content

Recommendation Service โ€“ API Reference ๐Ÿค–

This document describes the recommendation APIs exposed by the Recommendation Service in ShopVerse.

The service provides personalized product recommendations based on user interactions, processed asynchronously using Kafka.


๐ŸŒ Base URLโ€‹


/api/recommendations


๐Ÿ” Authentication & Authorizationโ€‹

  • JWT is validated at the API Gateway
  • Gateway injects:
    • X-User-Email
    • X-User-Role
  • Only authenticated users with role CUSTOMER can access recommendations
  • Admin access is not applicable

๐ŸŽฏ Get Recommendations (Customer)โ€‹

Fetch recommended products for the authenticated user.

โžค Endpointโ€‹


GET /api/recommendations

โžค Query Parameters (Optional)โ€‹

ParamDescription
limitNumber of recommendations (default: 10)

โžค Success Response (200 OK)โ€‹

[
{
"productId": "PROD123",
"score": 12.5,
"source": "PERSONAL"
},
{
"productId": "PROD456",
"score": 9.0,
"source": "POPULAR"
}
]

๐Ÿง  Recommendation Logic (High-Level)โ€‹

  • If user interaction data exists โ†’ Personalized recommendations
  • If insufficient data โ†’ Popular products fallback
  • Recommendations are read-only
  • Scores are calculated using weighted interaction events

๐Ÿ”„ Request Flowโ€‹


๐Ÿ“ก Data Sourceโ€‹

Recommendations are generated from Kafka events:

Event TypeSource
VIEW_PRODUCTProduct Service
ADD_TO_CARTOrder Service
ORDER_PLACEDOrder Service

These events are processed asynchronously and stored in MongoDB.


๐Ÿ›ก๏ธ Security Rulesโ€‹

RoleAccess
CUSTOMERFetch own recommendations
ADMINโŒ Not allowed

โš ๏ธ Common Errorsโ€‹

StatusMeaning
401Unauthorized
403Forbidden
500Recommendation generation failure

๐Ÿ“Œ Summaryโ€‹

The Recommendation API provides:

  • Personalized product discovery
  • Event-driven scalability
  • Clean read-only access
  • Secure, customer-only endpoints

It enhances user engagement without affecting core transactions.