Skip to content

Backend API for allocating customer orders to batches of stock in a warehouse.

License

Notifications You must be signed in to change notification settings

msolorio/allocation-service

Repository files navigation

Allocation Service

TypeScript version Node.js version Build Status - GitHub Actions

Backend API for allocating customer orders to batches of stock in a warehouse.

Stack

  • Node.js
  • TypeScript
  • PostgreSQL
  • Express.js
  • Prisma ORM
  • Jest
  • Docker
  • Github Actions

Architecture

The application uses the dependency inversion principle, and creates abstractions around I/O and injects them. This allows us to pass a fake I/O to the service layer for testing the application "edge-to-edge" with fast, in-memory unit tests.

in-memory-implementation


For real-world and E2E testing, the service layer is passed real I/O that talks to a database. Because we have already exhaustively tested the service layer with fast, in-memory tests, less slow E2E tests are needed. We can achieve a healthy testing pyramid with high coverage.

e2e-implementation


A few patterns are used to aid dependency inversion.

Repository - an abstraction around data access. Handles syncing between the domain model and the ORM.
Unit of Work - an abstraction around transactions and atomicity.
Service Layer - the entrypoint for injecting I/O and defines the application's use cases.
Domain Model - an object module of the business domain free of dependencies on data access.
Data Mapper - handles conversion between domain objects and db objects.

Trade-offs - Each pattern adds indirection and congintive load and wouldn't be necessary in a simple application. You could, for example, still achieve dependency inversion and abstracting I/O with only a simple repository and a service layer.

Todo

  • Add consistency boundary with optimistic concurrency -- invariant: a batch's available quantity must be greater than or equal to zero

Setup

Install docker and then run

git clone [email protected]:msolorio/allocation-service.git
cd allocation-service
make build
make up
make migrate
make test

Make Scripts

  • make build - Build docker container
  • make up - Start app and TypeScript
  • make down - Remove containers
  • make logs - Show container logs
  • make test - Run tests
  • make migrate - Run db migrations
  • make run <command> - Run a command in the container

About

Backend API for allocating customer orders to batches of stock in a warehouse.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published