Cart Module API & Integration Guide
Cart API contracts for hybrid physical + legacy digital support across admin, customer, and mobile composition.
Cart Module - API & Integration Guide
Audience: Mobile/web frontend developers integrating cart Scope: DTOs, error codes, business rules
1. How to Read / Quick Metadata
- Module:
Cart - Auth models:
- Customer/mobile routes:
JwtAuthGuard - Admin routes:
JwtAuthGuard + RoleGuard + @Permissions(...)
- Customer/mobile routes:
- Primary base URLs:
- Customer:
/api/cart - Mobile-composed customer:
/api/mobile/cart - Admin:
/api/admin/cart
- Customer:
- Response envelope: successful endpoints return
ResponseDto<T> - Swagger tags used by controllers:
Cart (Mobile)Cart (Admin)
2. High-Level Overview
Cart API is focused on authenticated cart management for physical products and legacy digital compatibility:
- fetch current cart
- add item
- remove item
- clear cart
Cart eligibility behavior:
- Physical product types:
thangka,singing_bowl,statue,jewellery
Payment initiation endpoints (checkout, buy-now) are owned by order APIs, not cart controller routes.
3. Core Concepts and Terminology
- cart: active per-user basket (
carttable) - cart item: one product line with monetary snapshot (
cart_itemtable) - applied coupon projection:
appliedPromotionId,appliedPromotionCode,appliedDiscount - final payable:
totalSp - (appliedDiscount ?? 0) - cart lifecycle:
active,checkout,completed,abandoned - async cart jobs:
cart.clear_after_order_confirmed,cart.expire
4. Route Summary
4.1 Customer / Mobile
| Method | Path |
|---|---|
GET | /api/cart |
POST | /api/cart/items |
DELETE | /api/cart/items/:itemId |
DELETE | /api/cart |
Mobile-composed equivalents are available under /api/mobile/cart....
4.2 Admin
| Method | Path | Permission |
|---|---|---|
GET | /api/admin/cart/users/:userId | Cart_READ |
Cart GET
| Aspect | Details |
|---|---|
| Endpoint | GET /api/cart or /api/mobile/cart |
| Auth | JwtAuthGuard |
| Request | none |
| Response | ResponseDto<CartDto> with items array |
| Errors | 404 (cart not found - returns new empty) |
Cart Add Item
| Aspect | Details |
|---|---|
| Endpoint | POST /api/cart/items or /api/mobile/cart/items |
| Auth | JwtAuthGuard |
| Request | "" productId: number "" |
| Response | ResponseDto<CartDto> updated |
| Errors | 404 product not found, 409 duplicate |
5. Query Parameters
Cart endpoints do not define list/filter query contracts.
GET /api/cartand mutating cart endpoints do not consume query DTOs.- Admin
GET /api/admin/cart/users/:userIdis path-param only.
6. Response Shape Examples
6.1 Add item request
"
"productId": 101
"6.2 Cart response
"
"id": 1,
"status": "active",
"items": [
"
"id": 10,
"productId": 101,
"productThumbnail": "https://cdn.example.com/thumb.jpg",
"unitMrp": 15000,
"unitSp": 12000,
"discount": 3000
""
],
"totalMrp": 15000,
"totalSp": 12000,
"totalDiscount": 3000,
"appliedCoupon": "
"promotionId": 1,
"code": "SUMMER2024",
"discount": 1000
"",
"finalPayable": 11000
"6.3 Clear cart response
"
"cleared": true
"7. Enums
7.1 cart_status
activecheckoutcompletedabandoned
7.2 Allowed cart product types (service-level)
thangkasinging_bowlstatuejewellery
8. Integration Diagram
9. Caching
Cache keyspaces:
cart:user:
TTL env:
CART_CUSTOMER_CACHE_TTL_SECONDS(default60)
Invalidation triggers:
- add item / remove item / clear cart / coupon updates invalidate
cart:user:userId:<encoded>* - failures in Redis cache operations are logged and request path falls back to DB behavior
10. Error Handling
All cart API errors return the standard error envelope:
"
"statusCode": 404,
"errorCode": "CART_NOT_FOUND",
"message": "Cart not found",
"timestamp": "2026-03-20T10:00:00.000Z",
"path": "/api/cart"
"Representative error map:
| HTTP | errorCode | Message |
|---|---|---|
| 400 | CART_PRODUCT_NOT_ELIGIBLE | This product type cannot be purchased via cart |
| 404 | CART_PRODUCT_NOT_FOUND | Product not found |
| 404 | CART_ITEM_NOT_FOUND | Cart item not found |
| 404 | CART_NOT_FOUND | Cart not found |
| 409 | CART_PRODUCT_ALREADY_IN_CART | Product is already in cart. |
| 429 | RATE_LIMIT_EXCEEDED | Too many requests. Please try again later. |
Time fields in this module are stored as timezone-aware values and should be handled as ISO-8601 instants by API consumers.
11. Endpoint Reference + Payload Cheatsheet
11.1 Payload Cheatsheet Table (Every Endpoint)
| Method | Path | Auth / Permission | Request DTO / Params | Success DTO | Notes |
|---|---|---|---|---|---|
| GET | /api/cart | User JWT | none | CartDto | Returns active cart with items; creates new empty cart if none exists |
| GET | /api/mobile/cart | User JWT | none | CartDto | Mobile-composed equivalent of cart fetch |
| POST | /api/cart/items | User JWT | AddCartItemDto "" productId: number "" | CartDto | Adds product to cart; validates product exists and is sellable |
| POST | /api/mobile/cart/items | User JWT | AddCartItemDto "" productId: number "" | CartDto | Mobile-composed equivalent of add item |
| DELETE | /api/cart/items/:itemId | User JWT | path: itemId (int) | CartDto | Removes specific item from cart; validates item exists and belongs to user |
| DELETE | /api/mobile/cart/items/:itemId | User JWT | path: itemId (int) | CartDto | Mobile-composed equivalent of remove item |
| DELETE | /api/cart | User JWT | none | "" cleared: boolean "" | Clears all items from cart; idempotent operation |
| DELETE | /api/mobile/cart | User JWT | none | "" cleared: boolean "" | Mobile-composed equivalent of clear cart |
| GET | /api/admin/cart/users/:userId | Admin + Cart_READ | path: userId (uuid) | CartDto | Admin views any user's cart; requires valid user ID |
11.1.1 Customer Cart Endpoint Query Variations
| Method | Path | Query Parameters | Notes |
|---|---|---|---|
| GET | /api/cart | (no params) | Default behavior; returns cart with applied coupon if any |
| GET | /api/mobile/cart | (no params) | Mobile equivalent |
11.1.2 Add Item Request Variations
| Method | Path | Request Body | Notes |
|---|---|---|---|
| POST | /api/cart/items | "" "productId": 301 "" | Add thangka to cart |
| POST | /api/cart/items | "" "productId": 302 "" | Add statue to cart |
| POST | /api/mobile/cart/items | "" "productId": 301 "" | Mobile equivalent - add thangka |
11.1.3 Remove Item Request Variations
| Method | Path | Request Body | Notes |
|---|---|---|---|
| DELETE | /api/cart/items/10 | (path only) | Remove item ID 10 |
| DELETE | /api/cart/items/15 | (path only) | Remove item ID 15 |
| DELETE | /api/mobile/cart/items/10 | (path only) | Mobile equivalent |
11.1.4 Cart Response Field Variations
| Field | Value | Notes |
|---|---|---|
| status | active | Cart is active and modifiable |
| status | checkout | Cart is under checkout process |
| status | completed | Cart was converted to order |
| status | abandoned | Cart was abandoned |
| productType | thangka | Physical product |
| productType | statue | Physical product |
| appliedCoupon | "" promotionId: 1, code: "SUMMER2024", discount: 1000 "" | Coupon applied with details |
| appliedCoupon | null | No coupon applied |
11.1.5 Error Response Variations
| HTTP | errorCode | Trigger |
|---|---|---|
| 400 | CART_PRODUCT_NOT_ELIGIBLE | Product type not eligible for cart |
| 404 | CART_PRODUCT_NOT_FOUND | Product ID does not exist |
| 404 | CART_ITEM_NOT_FOUND | Cart item ID does not exist |
| 404 | CART_NOT_FOUND | Cart does not exist |
| 409 | CART_PRODUCT_ALREADY_IN_CART | Product already in user's cart |
| 429 | RATE_LIMIT_EXCEEDED | Too many requests |
11.1.6 Cache Invalidation Variations
| Trigger | Invalidated Key Pattern |
|---|---|
| POST /cart/items | cart:user:userId:* |
| DELETE /cart/items/:itemId | cart:user:userId:* |
| DELETE /cart | cart:user:userId:* |
| POST /promotions/apply (coupon) | cart:user:userId:* |
| POST /promotions/remove | cart:user:userId:* |
11.1.7 Cart Item Fields in Response
| Field | Type | Notes |
|---|---|---|
| id | number | Unique cart item ID |
| productId | number | Referenced product ID |
| productTitle | string | Product title at time of add |
| productSlug | string | Product slug for linking |
| productThumbnail | string | CDN URL for thumbnail |
| unitMrp | number | Original price in paisa |
| unitSp | number | Selling price in paisa |
| discount | number | Discount amount in paisa |
11.1.8 Cart Summary Fields in Response
| Field | Type | Notes |
|---|---|---|
| totalMrp | number | Sum of all MRP in paisa |
| totalSp | number | Sum of all SP in paisa |
| totalDiscount | number | Product-level discount total |
| finalPayable | number | totalSp - appliedDiscount |
| appliedCoupon | object | null | Applied promotion details |
12. Testing Scenarios
12.1 Add Item to Cart
Test Case: Successful add item to empty cart
- Authenticated user with no items in cart
- POST
/api/cart/itemswith"" "productId": 101 "" - Expect
200withResponseDto<CartDto>containing the new item - Verify cart status is
active - Verify item productType, unitMrp, unitSp, discount populated correctly
12.2 Add Duplicate Item
Test Case: Adding already-added product returns conflict
- User has product 101 already in cart
- POST
/api/cart/itemswith"" "productId": 101 "" - Expect
409with errorCodeCART_PRODUCT_ALREADY_IN_CART
12.3 Remove Item from Cart
Test Case: Remove single item from cart
- User has cart with multiple items
- DELETE
/api/cart/items/10(itemId) - Expect
200with updated cart without the removed item - Verify remaining items still have correct pricing
12.4 Clear Entire Cart
Test Case: Clear all items from cart
- User has cart with multiple items
- DELETE
/api/cart - Expect
200with"" "cleared": true "" - Verify subsequent GET
/api/cartreturns empty items array
12.5 Cart with Promo Code
Test Case: Apply valid promo code to cart
- User adds items to cart totaling Rs. 15,000
- Apply promotion via order checkout (promo applied at order, not cart level)
- Verify finalPayable reflects discount
- Verify appliedCoupon populated in cart response
12.6 Admin View User Cart
Test Case: Admin retrieves user cart by userId
- Admin with appropriate permissions
- GET
/api/admin/cart/users/:userId - Expect
200with full cart details including items and pricing
See Also
- Feature Guide: See Cart - Feature List Section 6 (State Models) for cart state diagram.
- Backend Reference: See Cart - Backend Documentation Section 9 for system architecture diagram.