nhzaci / ShopifyTechnicalChallenge2022

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Shopify Technical Challenge

Heroku Deployment

Objectives and Architecture

  • Overall project architecture utilises a component style architecture, where each individual component consists of three parts:

    1. Controller - Controls routing endpoints and which service paths to route API call to

    2. Model - Consists of all the models required for an individual component

    3. Service - Consists of all the business logic and communication with the database

  • CRUD operations

    • Create inventory items
      • POST to /inventory/ with item in request body to create a new item
      • create function
    • Edit
      • PATCH to /inventory/{itemId} with item in request body to update item
      • edit function
    • Delete
      • DELETE to /inventory/{itemId} with a deleteReason that can be specified in the request body
      • delete function
    • View a list of them
  • Extra feature chosen:

    • When deleting, allow deletion comments and undeletion

Event-driven Architecture of deletion system

  • Each delete is an event inserted into the delete-events collection
    • Deletion occurs by setting a deleted boolean in an Item to true
      • GET /inventory/ endpoint queries the database only for documents with deleted set to false
      • By setting deleted to true, these documents will not be retrieved
    • Documents can be cleaned up on a monthly schedule, i.e. daily cron job to clean up documents which have deleted flag set to true for over a month
  • Undo is simply getting the most recent delete event, deleting the event from the delete-events collection and setting deleted boolean of corresponding item with id specified to be false

Running Locally

  • Setting up locally consists of two steps,
    • A. Setting up Database
    • B. Setting up Express Application

A. Setting up Database

  • Please follow instructions on MongoDB Install to install MongoDB on your local environment, MongoDB is required to run the application

B. Setting up Express application

  1. Install nvm node version manager to install node js and npm, instructions here

  2. Install node v15.11.0 with nvm

nvm install 15.11.0
  1. Use node v15.11.0 in nvm
nvm use 15.11.0
  1. Install yarn globally with npm
sudo npm i -g yarn
  1. Install dependencies with yarn
yarn
  1. Starting dev server
yarn dev
  1. App docs endpoint http://localhost:3000/docs/ for Swagger UI playground and API documentation

Schema

  • Item Schema
interface Item {
  name: String,
  description: String,
  quanity: Number,
  deleted: Boolean // if deleted is true, item will not show up in get all items endpoint
}
  • Delete Event Schema
interface DeleteEvent {
  itemId: String, // _id of Item that has been deleted
  reason: String  // Reason specified for Item deletion
}

About


Languages

Language:TypeScript 100.0%