Files
cartchain/README.md
droideparanoico 6d6a14a061 Application revamp
2022-10-08 12:27:21 +02:00

2.8 KiB

CartChain

Proof of concept for an e-commerce API implementing blockchain technology by using a simple private chain (no mining)

How it works?

The aim of this API is to manage a shopping cart of an ecommerce website. So, through it, the client will be able to request and create, update or delete any item in the current cart.

Every action of the API will generate a new Block on the Blockchain in order to create a history and persist the information, so we can retrieve it later, but also keeps a history of which items have the user added to the cart.

Workflow

The workflow of this API is as follows:

  • Create
  1. Create request is received
  2. Check if the id for a Cart is not already used
    1. If it has been used we return error
    2. If it has not been used, we create the cart with the given item and generates a new Block to add to the Blockchain
  3. Add the new Block to the Blockchain with the current information of this Cart
  • Update
  1. Update request is received
  2. Check if the id for a Cart exists
    1. If not exists return error
    2. If exist retrieve it
  3. Update the items in the cart and generate a new Block with the information
  4. Add the new Block to the Blockchain
  • Delete
  1. Delete request is received
  2. Check if the id for a Cart exists
    1. If not exists return error
    2. If exist retrieve it
  3. Remove cart information and create a new Block
  4. Add the new Block to the Blockchain

Technical Considerations

Stack

Architecture

This app is implemented using hexagonal architecture (ports & adapters) and DDD approach.

The architecture helps to have a decoupled code and being easy to modify or extend it. Following diagram hints how this is achieved:

Architecture

More info at Hexagonal Architecture

Getting Started

Within the Makefile you can handle the entire flow to get everything up & running:

  1. Install make on your computer, if you do not already have it.
  2. Start the application: make up
  3. Run the application tests: make test

Go to localhost:8080/swagger-ui/index.html to see the API description.

As you can see on the Makefile script and the docker-Compose File, the whole API is containerized with docker and the API is using the internal DNS to connect with the PostgreSQL instance.