Developer Resourcescart
Cart Module Feature List
Digital-only cart features, cache behavior, and integration boundaries.
Cart Module - Feature List
1. Overview
Cart supports both digital and physical products.
- Physical product types:
thangka,singing_bowl,statue,jewellery - Online-only checkout integration
- No delivery fee in cart totals
2. Exposed Routes
| Surface | Route prefix |
|---|---|
| Admin | /api/admin/cart |
| Customer API | /api/cart |
| Mobile-composed customer API | /api/mobile/cart |
3. Core Features
| Feature | Behavior |
|---|---|
| Active cart lifecycle | One active cart per user (active, checkout, completed, abandoned) enforced by DB partial unique index |
| Add/remove items | Snapshot pricing (unitMrp, unitSp) |
| Checkout handoff | Payment initiation for cart and quick purchase is owned by order endpoints (/api/orders/checkout, /api/orders/buy-now) |
| Coupon projection | Uses appliedPromotionId, appliedPromotionCode, appliedDiscount |
| Final payable | totalSp - appliedDiscount |
Cart integrity is DB-hardened:
cart_item.product_idcannot be nullcart.applied_discountcannot be negativecart_item.unit_mrpandcart_item.unit_spcannot be negative
4. State Models
4.1 Cart lifecycle state
4.2 Cart item lifecycle
5. Queue/Worker Features
| Job | Queue | Trigger |
|---|---|---|
cart.clear_after_order_confirmed | QueueName.CART | Order payment success |
cart.expire | QueueName.CART | Cart TTL expiry |
6. Admin Features
| Endpoint | Purpose |
|---|---|
GET /users/:userId | Support/debug active cart view |
7. Customer Features
| Endpoint | Purpose |
|---|---|
GET /cart | Get or lazily create active cart for current user |
POST /cart/items | Add one sellable product to active cart |
DELETE /cart/items/:itemId | Remove one cart item from active cart |
DELETE /cart | Clear all items and reset applied coupon fields |
Notes:
- Customer surface is authenticated (
JwtAuthGuard) and mounted under/api/mobile/cartviaMobileModulecomposition. buyNowbehavior exists inCartCustomerServicefor internal service use; public buy-now API is owned by order endpoints.
8. Cache Features
| Keyspace | Prefix |
|---|---|
| User cart | cart:user: |
- Keys are built with
CacheKeyUtil.build(...) - Values are invalidated by prefix with
invalidatePattern(prefix*) - Redis failures degrade gracefully (warn + DB fallback)
9. Rate Limiting
Redis sliding-window counters:
- customer mutating cart operations
Failures in Redis rate checks are fail-open with warning logs.
10. Integration Boundaries
- Cart writes and reads stay in cart services and schema (
cart,cart_item). - Checkout and buy-now payment initiation are owned by order customer endpoints.
- Async cart clearing after confirmed order is handled through cart queue job
cart.clear_after_order_confirmed.
Related payment docs:
apps/fumadocs/content/docs/developer/payment/cart-checkout-flow.mdx
11. Environment Variables
CART_CUSTOMER_OPERATION_RATE_LIMIT(default60)CART_CUSTOMER_RATE_WINDOW_SECONDS(default60)CART_CUSTOMER_CACHE_TTL_SECONDS(default60)CART_EXPIRE_INTERVAL_MS(default600000)
12. Error UX Mapping
| Scenario | API behavior | Recommended UI |
|---|---|---|
| Add item with invalid productId | 400 CART_PRODUCT_NOT_FOUND | Show "Product not found" toast |
| Add duplicate product | 409 CART_ITEM_DUPLICATE | Show "Already in cart" message, navigate to cart |
| Cart not found | 404 CART_NOT_FOUND | Auto-create new cart on GET, return empty |
| Remove non-owned item | 403 CART_ITEM_ACCESS_DENIED | Show "Cannot remove this item" |
| Rate limit exceeded | 429 RATE_LIMIT_EXCEEDED | Show "Please wait" with backoff |
| Invalid coupon applied | 400 PROMOTION_NOT_APPLICABLE | Show coupon error message, remove from cart |
| Cart expired | 200 with new empty cart | Silent refresh, show "Cart refreshed" |
13. Release/QA Checklist
- Verify cart creates lazily on first GET request for authenticated user
- Verify duplicate product add returns 409 and does not create duplicate item
- Verify coupon application and removal work correctly
- Verify cart invalidation on write operations
- Verify rate limiting returns 429 on threshold breach
- Verify mobile routes
/api/mobile/cart/*work correctly - Verify cart clear after order payment success
- Verify Redis fallback on cache failures
14. Data Flow
15. Integration Flows
15.1 Add to Cart Flow
A customer adds a sellable product to their active cart.
- Customer calls
GET /api/cart(orGET /api/mobile/cart) to get or create their active cart. - Customer calls
POST /api/cart/items(orPOST /api/mobile/cart/items) with{ productId, quantity }. - System validates product is not already in cart (returns 409 if duplicate).
- System inserts
cart_itemwith snapshot pricing (unitMrp,unitSp). - System updates
carttotals: recalculatetotalMrp,totalSp, apply any existingappliedDiscount. - System invalidates Redis cache key
cart:user:{userId}. - Client refetches cart to see updated totals and item.
15.2 Checkout Flow
A customer proceeds from cart to order checkout.
- Customer has items in active cart with valid coupon (if any applied).
- Customer calls
POST /api/orders/checkoutwithidempotency-keyheader. - Order service validates cart exists, is active, has items, and coupon is still valid.
- Order service creates order, snapshots pricing, applies discount, sets status
payment_pending. - Order service enqueues
cart.clear_after_order_confirmedjob to run after payment success. - Payment gateway is invoked, returns
initiationTypewithgatewayPayload. - Customer completes payment via form_post or redirect.
- Payment callback triggers order payment success, which triggers cart clear job.
- CartProcessor clears the user's active cart and sets status to
completed.
Time fields in this module are stored as timezone-aware values and should be handled as ISO-8601 instants by API consumers.
See Also
- API Reference: See Cart - API & Integration Guide Section 7 (Endpoint Reference + Payload Cheatsheet) for complete request/response DTOs.
- Backend Reference: See Cart - Backend Documentation Section 3 (Data Model) for schema details.