Skip to main content

Wishlist Service

Overview

The Wishlist Service provides functionality for users to save and manage products they are interested in. Users can collect products they want to purchase later and receive notifications about price changes or restocking.

ItemValue
LanguagePython 3.11
FrameworkFastAPI
DatabaseDocumentDB (MongoDB compatible)
Namespacemall-services
Port8000
Health CheckGET /health

Architecture

API Endpoints

Wishlist API

MethodPathDescription
GET/api/v1/wishlists/{user_id}Get wishlist
POST/api/v1/wishlists/{user_id}/itemsAdd item
DELETE/api/v1/wishlists/{user_id}/items/{product_id}Remove item

Request/Response Examples

Get Wishlist

Request:

GET /api/v1/wishlists/user_001

Response:

{
"user_id": "user_001",
"items": [
{
"product_id": "prod_001",
"added_at": "2024-01-15T10:00:00Z",
"note": "Want to buy as a birthday gift"
},
{
"product_id": "prod_002",
"added_at": "2024-01-14T15:30:00Z",
"note": null
}
],
"created_at": "2024-01-01T00:00:00Z",
"updated_at": "2024-01-15T10:00:00Z"
}

Add Item

Request:

POST /api/v1/wishlists/user_001/items
Content-Type: application/json

{
"product_id": "prod_003",
"note": "Planning to buy when on sale"
}

Response (201 Created):

{
"product_id": "prod_003",
"added_at": "2024-01-15T11:00:00Z",
"note": "Planning to buy when on sale"
}

Remove Item

Request:

DELETE /api/v1/wishlists/user_001/items/prod_001

Response (204 No Content)

Data Models

Wishlist

class Wishlist(BaseModel):
user_id: str
items: list[WishlistItem] = []
created_at: datetime
updated_at: datetime

WishlistItem

class WishlistItem(BaseModel):
product_id: str
added_at: datetime
note: Optional[str] = None # User note

WishlistItemCreate

class WishlistItemCreate(BaseModel):
product_id: str
note: Optional[str] = None

MongoDB Collection Schema

// wishlists collection
{
"_id": ObjectId("..."),
"user_id": "user_001",
"items": [
{
"product_id": "prod_001",
"added_at": ISODate("2024-01-15T10:00:00Z"),
"note": "Birthday gift"
}
],
"created_at": ISODate("2024-01-01T00:00:00Z"),
"updated_at": ISODate("2024-01-15T10:00:00Z")
}

// Indexes
db.wishlists.createIndex({ "user_id": 1 }, { unique: true })
db.wishlists.createIndex({ "items.product_id": 1 })

Events (Kafka)

Published Topics

TopicEventDescription
wishlists.item-addedItem addedPublished when item is added to wishlist
wishlists.item-removedItem removedPublished when item is removed from wishlist

Event Payload Example

wishlists.item-added:

{
"event_type": "wishlist.item-added",
"user_id": "user_001",
"product_id": "prod_003",
"timestamp": "2024-01-15T11:00:00Z"
}

Event Usage

  • Notification Service: Send notifications for wishlisted product price drops/restocking
  • Recommendation Service: Improve personalized recommendations based on wishlists
  • Analytics Service: Analyze popular wishlisted products

Environment Variables

VariableDescriptionDefault
SERVICE_NAMEService namewishlist
PORTService port8080
AWS_REGIONAWS regionus-east-1
REGION_ROLERegion role (PRIMARY/SECONDARY)PRIMARY
DB_HOSTDatabase hostlocalhost
DB_PORTDatabase port27017
DB_NAMEDatabase namewishlists
DB_USERDatabase usermall
DB_PASSWORDDatabase password-
DOCUMENTDB_HOSTDocumentDB hostlocalhost
DOCUMENTDB_PORTDocumentDB port27017
KAFKA_BROKERSKafka broker addresslocalhost:9092
LOG_LEVELLog levelinfo

Service Dependencies

Services It Depends On

  • DocumentDB: Wishlist data storage
  • Product Catalog: Product existence validation (optional)

Services That Depend On This

  • Notification Service: Wishlist product notifications
  • Recommendation Service: User interest identification
  • Analytics Service: Wishlist trend analysis

Feature Details

Wishlist Limits

  • Maximum 100 products per user
  • No duplicate products allowed
  • Out-of-stock/deleted products retained (for notification purposes)

Notification Integration

Notifications triggered for the following events on wishlisted products:

  • Price drop (10% or more)
  • Restocking
  • Low stock (5 or fewer items)