Low Level Design for Amazon Shopping

ยท

11 min read

Requirements

  • User Authentication:

    • Implement a secure user registration system.

    • Develop a user login mechanism with proper authentication.

  • User Profiles:

    • Allow users to create and update their profiles.
  • Product Management:

    • Enable the creation, deletion, and updating of product information.

    • Support product retrieval by ID or category.

    • Implement a search feature to find products based on user queries.

    • Maintain a comprehensive list of all available products.

  • Shopping Cart:

    • Provide users with the ability to create and manage their shopping carts.

    • Allow users to add, update, and remove items from their carts.

  • Order Processing:

    • Develop a system for users to place orders.

    • Enable users to view their order history.

    • Implement order status management, including order confirmation, shipping, delivery, and cancellation.

  • Payment Handling:

    • Create payment links for order transactions.

    • Allow users to update their payment information securely.

  • Product Reviews and Ratings:

    • Implement a feature for users to create product reviews.

    • Enable users to rate products.

    • Display product ratings to users.

  • Order Tracking:

    • Provide users with the ability to view all their orders.

Models Identification

We can see models of the system will include :

  1. Cart

  2. CartItem

  3. Product

  4. User

  5. Address

  6. Reviews

  7. Ratings

  8. Category

  9. Order

  10. Order Item

Service Identification

APIs

Service APIDescription
createUser(userData)Creates a new user with the provided data, including first name, last name, email, password, and role. If a user with the same email already exists, it throws an error.
findUserById(userId)Finds a user by their ID and returns their information. If the user is not found, it throws an error.
getUserByEmail(email)Retrieves a user by their email. If the user is not found, it throws an error.
getUserProfileByToken(token)Retrieves a user's profile using a token, and ensures the user's password is not included in the response. If the user doesn't exist, it throws an error.
getAllUsers()Fetches all users in the system and returns them. If there's an error, it throws an error.
createCart(user)Creates a new cart for a user and returns the created cart.
findUserCart(userId)Finds a user's cart, updates cart details including cart items, and returns the cart.
addCartItem(userId, req)Adds an item to the user's cart based on the provided product information. Returns a confirmation message.
createCartItem(cartItemData)Creates a new cart item with the provided data, including quantity, price, and discounted price, and returns the created cart item.
updateCartItem(userId, cartItemId, cartItemData)Updates an existing cart item with the provided data, such as quantity, price, and discounted price. It ensures that the user can only update their own cart item.
isCartItemExist(cart, product, size, userId)Checks if a cart item already exists in the user's cart based on the provided parameters and returns the cart item if found.
removeCartItem(userId, cartItemId)Removes a cart item from the user's cart. It checks that the user can only remove their own cart item.
findCartItemById(cartItemId)Finds a cart item by its ID and returns its details. If the cart item doesn't exist, it throws a CartItemException.
createProduct(reqData)Creates a new product with the provided data and returns the saved product.
deleteProduct(productId)Deletes a product by its ID. If the product doesn't exist, it throws an error.
updateProduct(productId, reqData)Updates a product's information by its ID and returns the updated product.
findProductById(id)Finds a product by its ID and returns its details. If the product doesn't exist, it throws an error.
getAllProducts(reqQuery)Retrieves a list of products with filtering and pagination options. Returns the product list along with pagination information.
createMultipleProduct(products)Creates multiple products based on the provided data.
createOrder(user, shippAddress)Creates a new order with user and shipping address information, along with order items.
placedOrder(orderId)Updates the order status to "PLACED" and payment status to "COMPLETED" for the given order.
confirmedOrder(orderId)Updates the order status to "CONFIRMED" for the given order.
shipOrder(orderId)Updates the order status to "SHIPPED" for the given order.
deliveredOrder(orderId)Updates the order status to "DELIVERED" for the given order.
cancelledOrder(orderId)Updates the order status to "CANCELLED" for the given order.
findOrderById(orderId)Finds an order by its ID and returns its details.
usersOrderHistory(userId)Retrieves the order history of a user with the "PLACED" status.
getAllOrders()Retrieves all orders with details.
deleteOrder(orderId)Deletes an order by its ID, and if the order doesn't exist, it throws an error.
createPaymentLink(orderId)Creates a payment link for an order, including details such as amount, currency, customer information, and callback URL. Returns the payment link URL and ID.
updatePaymentInformation(reqData)Updates the payment information and order status for a completed payment. Returns a message indicating the order is placed.
createReview(reqData, user)Creates a new review for a product with the provided data, associated with a user and a product.
getAllReview(productId)Retrieves all reviews for a product based on the product's ID. Returns the list of reviews, each associated with a user.
createRating(req, user)Creates a new rating for a product with the provided data, associated with a user and a product.
getProductsRating(productId)Retrieves all ratings for a product based on the product's ID. Returns the list of ratings for the product.

Processing Requests

RequestInputProcessingOutput
User RegistrationUser details (name, email, password)Validate input, create a user, generate a JWT, create a shopping cartSuccessful registration - status 200, JWT, and success message. Errors - status 500 and an error message.
User LoginUser login details (email, password)Validate input, check user existence, verify password, generate a JWTSuccessful login - status 200, JWT, and success message. User not found - status 404 and "User not found" message. Invalid password - status 401 and "Invalid password" message. Errors - status 500 and an error message.
Get User ProfileJWT token in the request headerCheck for JWT, retrieve user profile using the JWTSuccessful profile retrieval - status 200 and user profile data. Token not found - status 404 and "token not found" error message. Errors - status 500 and an error message.
Get All UsersNoneRetrieve all user profiles using the userServiceSuccessful retrieval - status 200 and a list of user profiles. Errors - status 500 and an error message.
Create a ProductProduct data in the request bodyCreate a new product using productService, respond with status 201 and the created product.In case of an error, respond with status 500 and an error message.
Delete a Product by IDProduct ID in the request parametersDelete a product using productService, respond with a success message.In case of an error, respond with status 500 and an error message.
Update a Product by IDProduct ID in the request parameters, product data in the request bodyUpdate a product using productService, respond with the updated product.In case of an error, respond with status 500 and an error message.
Find a Product by IDProduct ID in the request parametersFind a product by ID using productService, respond with the product data.If the product is not found, respond with status 404 and an error message. In case of other errors, respond with status 500 and an error message.
Find Products by CategoryCategory in the request parametersFind products by category using productService, respond with the list of products.In case of an error, respond with status 500 and an error message.
Search Products by QueryQuery in the request parametersSearch products by query using productService, respond with the list of products matching the query.In case of an error, respond with status 500 and an error message.
Get All ProductsQuery parameters for filtering and paginationRetrieve products with filtering and pagination, respond with the list of products.In case of an error, respond with status 500 and an error message.
Create Multiple ProductsMultiple product data in the request bodyCreate multiple products using productService, respond with a success message.In case of an error, respond with status 500 and an error message.
Find User CartUser data from the request (req.user)Find the user's cart using cartService, respond with status 200 and the user's cart data.In case of an error, respond with status 500 and an error message.
Add Item to CartUser data from the request (req.user), item data in the request bodyAdd an item to the user's cart using cartService, respond with status 202 and a success message.In case of an error, respond with status 500 and an error message.
Update Cart ItemUser data from the request (req.user), cart item ID in the request parameters, updated item data in the request bodyUpdate a cart item using cartItemService, respond with status 200 and the updated cart item data.In case of an error, respond with status 500 and an error message.
Remove Cart ItemUser data from the request (req.user), cart item ID in the request parametersRemove a cart item using cartItemService, respond with status 200 and a success message.In case of an error, respond with status 500 and an error message.
Create OrderUser data from the request (req.user), order data in the request bodyCreate an order using orderService, respond with status 201 and the created order.In case of an error, respond with status 500 and an error message.
Find Order by IDUser data from the request (req.user), order ID in the request parametersFind an order by ID using orderService, respond with status 200 and the order data.In case of an error, respond with status 500 and an error message.
Order HistoryUser data from the request (req.user)Retrieve a user's order history using orderService, respond with status 200 and the order history.In case of an error, respond with status 500 and an error message.
Create Payment LinkOrder ID in the request parametersCreate a payment link using paymentService, respond with status 200 and the payment link.In case of an error, respond with status 500 and an error message.
Update Payment InformationQuery parameters with payment informationUpdate payment information using paymentService, respond with status 200 and a success message.In case of an error, respond with status 500 and an error message.
Create ReviewUser data from the request (req.user), review data in the request bodyCreate a review using reviewService, respond with status 201 and the created review.In case of an error, respond with status 500 and an error message.
Get All ReviewsProduct ID in the request parametersRetrieve all reviews for a specific product using reviewService, respond with status 200 and the list of reviews.In case of an error, respond with status 500 and an error message.
Create RatingUser data from the request (req.user), rating data in the request bodyCreate a rating using ratingService, respond with status 202 and the created rating.In case of an error, respond with status 500 and an error message.
Get Products RatingProduct ID in the request parametersRetrieve ratings for a specific product using ratingService, respond with status 200 and the list of ratings.In case of an error, respond with status 500 and an error message.
Get All OrdersNoneRetrieve all orders using orderService, respond with status 202 and the list of orders.In case of an error, respond with status 500 and an error message.
Confirm OrderOrder ID in the request parametersConfirm an order using orderService, respond with status 202 and the confirmed order.In case of an error, respond with status 500 and an error message.
Ship OrderOrder ID in the request parametersShip an order using orderService, respond with status 202 and the shipped order.In case of an error, respond with status 500 and an error message.
Deliver OrderOrder ID in the request parametersMark an order as delivered using orderService, respond with status 202 and the delivered order.In case of an error, respond with status 500 and an error message.
Cancel OrderOrder ID in the request parametersCancel an order using orderService, respond with status 202 and the cancelled order.In case of an error, respond with status 500 and an error message.
Delete OrderOrder ID in the request parametersDelete an order using orderService, respond with status 202 and a success message.In case of an error, respond with status 500 and an error message.
ย