cash-register


Project Documentation: Cash Register Application


1. Project Overview

The Cash Register application was developed as part of a technical challenge to create a flexible, user-friendly system for managing a shopping cart. This system handles product additions, calculates the total price, and applies special pricing rules to meet the requirements provided. The main goals of the project included simplicity, maintainability, and scalability while adhering to a test-driven development methodology.

State of the application upon opening!

The core functionality revolves around three special pricing rules:

  1. Buy-One-Get-One-Free: Applies to Green Tea (GR1).
  2. Bulk Discount: Reduces the price of Strawberries (SR1) to €4.50 when purchasing 3 or more.
  3. Conditional Discount: Decreases the price of Coffee (CF1) to two-thirds of its original value when buying 3 or more.

2. Technical Requirements

Backend:

Frontend:

Testing:


3. System Design

Architecture:

Core Features:

Pricing Rules:

Documentation:


4. API Features

Endpoints:

  1. POST /cart/add:
    • Description: Add a product to the cart by providing its code and quantity.
    • Request Body:
      {
        "code": "string",
        "quantity": "integer"
      }
      
    • Response:
      {
        "message": "Product added to cart successfully"
      }
      
  2. GET /cart/list:
    • Description: Retrieve all items in the cart, including quantities, original prices, and any applicable discounts.
    • Response:
      {
        "items": [
          {
            "item": "GR1",
            "quantity": 2,
            "original_price": 6.22,
            "discounted_price": 3.11
          }
        ]
      }
      
  3. POST /cart/clear:
    • Description: Remove all items from the cart.
    • Response:
      {
        "message": "Cart cleared successfully"
      }
      
  4. GET /catalog/list:
    • Description: Retrieve all products in the catalog with their codes, names, and original prices.
    • Response:
      {
        "items": [
          {
            "code": "GR1",
            "name": "Green Tea",
            "price": 3.11
          }
        ]
      }
      

5. Usage Instructions

  1. Installation:
    • Run make install to install all dependencies for both backend and frontend.
  2. Start the Backend:
    • Use make backend to start the FastAPI server.
  3. Start the Frontend:
    • Run make frontend to launch the React application.
  4. Generate TypeScript Types:
    • Use make types to generate TypeScript types from the OpenAPI schema.
  5. Run the Full Application:
    • Use make run to start both the backend and frontend concurrently.
  6. Run Tests:
    • Execute make test to run backend tests.