The Cart service gives each authenticated user an isolated shopping cart backed by Redis. Every cart operation — reading, adding items, removing items, and clearing — is scoped to the user identified by the JWT submitted in the request. Redis stores each cart as a JSON-serialized array under a key equal to the user’s ID, with a rolling 7-day TTL that resets on every write. Because Redis lives entirely in memory, cart operations are fast and stateless from the perspective of the service itself.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/astrxnomo/shop-microservers/llms.txt
Use this file to discover all available pages before exploring further.
Overview
Runtime
Express on port 3002 inside Docker. Gateway prefix:
/api/cart/.Storage
Redis — cart data stored under key
userId as a JSON array. TTL: 7 days (604800 seconds).Authentication
All endpoints require a valid JWT. The
userId is extracted from the sub claim of the decoded token.Merge Behavior
Adding an item that already exists in the cart increments the quantity rather than creating a duplicate entry.
Authentication
Every request to the Cart service must carry the JWT issued by the Auth service:sub (the user ID), and uses it as the Redis key for all cart operations. Requests without a valid token receive 401 Unauthorized.
Endpoints
| Method | Path | Auth | Description |
|---|---|---|---|
| GET | / | Required | Get current cart with items and total |
| POST | /items | Required | Add or increment an item |
| DELETE | /items/:productId | Required | Remove a specific item from the cart |
| DELETE | / | Required | Clear the entire cart |
Cart Item Shape
When adding an item (POST /items), the request body is validated against the AddItemSchema:
The catalog product ID. Used as the merge key — duplicate entries increment quantity instead of creating a new row.
Display name of the product, stored in the cart for rendering without a catalog lookup.
Unit price. Must be a positive number. Stored in the cart so the total can be computed independently of the catalog.
A valid URL for the product image.
Number of units to add. Must be a positive integer. Defaults to
1 if omitted.Storage and TTL
Cart data is persisted in Redis with the following semantics:- Key: the user’s ID (extracted from JWT
sub) - Value: JSON-serialized
CartItem[] - TTL: reset to 7 days on every
addItemorremoveItemcall - On clear: the Redis key is deleted entirely (
redis.del)
A cart that has not been modified for 7 days will expire automatically. The user’s next visit will begin with an empty cart.
Merge Behavior
If aPOST /items request references a productId that already exists in the cart, the quantities are summed rather than creating a duplicate entry:
Total Calculation
The cart total is computed on read by the service layer, rounded to two decimal places:Response Shapes
GET / — cart with total:
POST /items, DELETE /items/:productId — updated items array:
DELETE / — empty cart confirmation:
Error Cases
| HTTP Status | Condition |
|---|---|
400 | Request body fails Zod validation |
401 | Missing or invalid JWT in the Authorization header |
API Reference
GET /
Retrieve the current user’s cart.
POST /items
Add or increment a cart item.
DELETE /items/:productId
Remove a specific item from the cart.
DELETE /
Clear the entire cart.