Skip to content

Feature Built: Authentication, Cart, Product Catalog, Coupons and Sponsored Ads#11

Open
prabhu30 wants to merge 3 commits into
opensource-for-valkey:mainfrom
prabhu30:valkey-talkies
Open

Feature Built: Authentication, Cart, Product Catalog, Coupons and Sponsored Ads#11
prabhu30 wants to merge 3 commits into
opensource-for-valkey:mainfrom
prabhu30:valkey-talkies

Conversation

@prabhu30

@prabhu30 prabhu30 commented May 24, 2026

Copy link
Copy Markdown

Implements five Valkey-powered backend subsystems with matching frontend integration for the Build Beyond Limits hackathon.

Challenge 1: User Authentication

  • Session tokens stored in Valkey (SET session:{token} {userId} EX 86400)
  • Passwords hashed with bcrypt (cost 12); user docs via JSON.SET
  • Rate limiting on failed logins (INCR login_attempts:{email})
  • Concurrent session tracking with SADD; POST /api/auth/refresh extends TTL
  • Frontend: AuthContext, login/register/profile UI in Account.jsx, headers show logged-in user

Challenge 2: Product Catalog

  • Products, categories, vendors stored as JSON docs (JSON.SET product:{id})
  • Sorted sets for price index and category membership; sets for brand/vendor indexes
  • 12 products × 4 root categories (17 total with 2-level nesting) seeded via POST /api/seed
  • Filtering by category, price range, brand; cursor-based pagination
  • Frontend: all product listing components fetch live catalog data

Challenge 3: Shopping Cart with Coupons

  • Cart as Valkey Hash (HSET cart:{userId} {productId} {qty}) with 7-day TTL
  • Guest carts via X-Guest-Id header; merge on login (POST /api/cart/merge)
  • 4 coupons seeded with full validation: expiry, min order, per-user usage (SISMEMBER coupon_used:{code}),
    category restrictions
  • Global usage count via JSON.NUMINCRBY
  • Frontend: CartContext with auto-merge on login; live cart badge in both headers

Challenge 4: Trending Products

  • Weighted event scoring: view=1, add-to-cart=3, purchase=5
  • Three sliding windows (1h/6h/24h) via ZINCRBY trending:global:{window} + EXPIRE
  • Category-level trending in parallel (trending:category:{id}:{window})
  • Frontend: TrendingOne rewritten — live data, time-window tabs, category tabs, scores shown on cards

Challenge 5: Ads

  • Ad creatives stored via JSON.SET ad:{uuidv7}
  • Bid-ranked indexes: ZADD ads:global {bid} {adId} + ZADD ads:category:{catId} {bid} {adId}
  • Daily budget enforcement via INCRBY ad_spend:{adId}:{date} (stops serving when exhausted)
  • Impression/click tracking per ad per day (INCR, EXPIRE 86400)
  • Frequency capping: server-side per-user/day (INCR ad_freq:{userId}:{adId}:{date}), client-side per-session
    (sessionStorage, cap=3)
  • 5 sample ads seeded (POST /api/seed/ads)
  • Frontend: AdBanner component — fires impression on mount, click on interaction, "Sponsored" label; placed
    on home page (global) and shop page (category-targeted)

Challenge 6: Full-Text Search

Implemented product search with full-text capabilities using the Valkey Search module, supporting autocomplete, typo tolerance, and faceted filtering.

  • Index Creation — Search index built on product JSON documents covering name, description, brand, tags, category, and price fields
  • Query Support — Full-text queries with stemming, prefix matching, and fuzzy matching for typo tolerance
  • Faceted Search — Aggregated counts returned by category, brand, and price range alongside search results
  • Autocomplete — Prefix-based search suggestions as the user types
  • Sorting — Results sortable by relevance, price (asc/desc), rating, and newest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant