Skip to content

djamseed/shopping-cart

Repository files navigation

Shopping Cart

An application that uses Command Query Responsibility Segregation (CQRS) and Event Sourcing to implement a shopping cart system using the OpenCQRS framework.

Features

  • Event Store and Read Model/Database using EntityFramework Core (InMemory Provider)
  • Swashbuckle to generate API documentation + UI to explore and test endpoints
  • AutoRest to generate a client library
  • Validation with FluentValidation
  • Native .NET Core Dependency Injection

Install

Core Requirements

  • .NET Core 2.1

Optional Requirements

  • Docker

Usage

# build
dotnet build -c Release -o src/ShoppingCart.WebApi

# start the app
dotnet src/ShoppingCart.WebApi/bin/Release/netcoreapp2.1/ShoppingCart.WebApi.dll

# access
https://localhost:5001 # -- this will open Swagger UI

Running on Docker

dotnet restore
dotnet publish -o publish -c Release
docker build -t djamseed/shopping-cart-api .
docker run -it --rm -p 5000:80 -t djamseed/shopping-cart-api .

#access
http://localhost:5000 # -- this will open Swagger UI

Architecture

Based on the Onion Architecture

Onion Architecture


CQRS/ES using OpenCQRS

Architecture

API Endpoints

Create Cart

POST /api/v1/cart
{
  "customerId": "90ab0d48-6253-4189-a7c2-24f1f8862809"
}

Add to Cart

POST /api/v1/cart/{cartId}
{
  "productName": "item-1",
  "price": 500,
  "quantity": 2
}

Update Item Quantity

PUT /api/v1/cart/{cartId}
{
  "productName": "item-1",
  "quantity": 5
}

Remove from Cart

DELETE /api/v1/cart/{cartId}
{
  "productName": "item-1"
}

Clear Cart

DELETE /api/v1/cart/{cartId}/clear

Assumptions

  • Customer already have an account and is authenticated
  • Stock management is done externally

Notes

About

A shopping cart system designed with CQRS and Event Sourcing

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published