Trawler
Case Study
Overview
A Spring Boot REST API that tracks stock against par levels across stores and drafts supplier orders automatically, with a web client where every stock line is a fish in a whirlpool.
Built to flag stock below par and raise supplier orders automatically, based on how I ran stock-takes at restaurants.
Where it started
The inspiration came from how frustrating and boring inventory systems are in restaurants.
Trawler takes the tedious part off your hands: it flags anything below par and drafts the supplier orders, the way stock-takes are run in restaurants, in an app that's actually pleasant to open.
Par levels, not guesswork
Every stock line shows what's on hand against its par, how many units it's short, what's already on order, and how many days of cover are left based on the last 14 days of usage. One endpoint lists everything below par, biggest shortfall first; another raises the order.
src/main/java/dev/sayef/trawler/StockController.java
@RestController
@RequestMapping("/api/stock")
class StockController {
private final StockService stock;
StockController(StockService stock) { this.stock = stock; }
@GetMapping("/low")
List<StockItem> lowStock(@RequestParam long storeId) {
return stock.belowPar(storeId);
}
@PostMapping("/orders")
@ResponseStatus(HttpStatus.CREATED)
PurchaseOrder reorder(@Valid @RequestBody ReorderRequest req) {
return stock.raiseOrder(req.storeId(), req.supplierId());
}
}
Ordering that doesn't double up
A reorder tops each line back to par, nets off stock already on open orders, rounds up to whole cases, and merges into an open draft for that supplier instead of starting a second one. Concurrent edits get a clear 409 instead of overwriting each other.
src/main/java/dev/sayef/trawler/StockService.java
/** Adds what each line needs to reach par, net of stock already on the way, in whole cases. */
private static int topUp(PurchaseOrder order, List<StockLevel> due, Map<Long, Integer> onOrder) {
int added = 0;
for (StockLevel level : due) {
Product product = level.getProduct();
int needed = level.getPar() - level.getOnHand() - onOrder.getOrDefault(product.getId(), 0);
int quantity = product.roundUpToPack(needed);
if (quantity > 0) {
order.addLine(product, quantity);
added++;
}
}
return added;
}
Autopilot
For stores that opt in, a scheduled job drafts one order per supplier every morning at 5 am, before anyone's on the floor. Drafts wait for a person to check and send them.
src/main/java/dev/sayef/trawler/ReorderAutopilot.java
/** Drafts supplier orders every morning for stores that opted in, before anyone's on the floor. */
@Scheduled(cron = "${trawler.reorder.cron:0 0 5 * * *}", zone = "${trawler.timezone:Australia/Sydney}")
void run() {
for (Store store : stores.findByAutoReorderTrue()) {
List<PurchaseOrder> raised = stock.raiseOrders(store.getId(), OrderSource.AUTO);
if (!raised.isEmpty()) {
log.info("Autopilot drafted {} order(s) for {}", raised.size(), store.getName());
}
}
}
Tested against a real database
Alongside 18 unit tests, 38 integration tests spin up a real PostgreSQL 17 in Testcontainers and call the API over HTTP, behind an 85% line-coverage gate.
src/test/java/dev/sayef/trawler/StockControllerIT.java
@Test
void reorderRaisesADraftThatBringsTheSupplierLinesBackToPar() {
ResponseEntity<String> res = post("/api/stock/orders", """
{"storeId": %d, "supplierId": %d}""".formatted(bondi, molino));
assertThat(res.getStatusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(JsonPath.<String>read(res.getBody(), "$.status")).isEqualTo("DRAFT");
assertThat(JsonPath.<List<String>>read(res.getBody(), "$.lines[*].sku")).containsExactly("CHIP-1KG", "TORT-12");
assertThat(JsonPath.<List<Integer>>read(res.getBody(), "$.lines[*].quantity")).containsExactly(12, 50);
}
A whirlpool of stock
To make stock less boring to look at, every line is drawn as a fish made of stars. Lines at or above par circle the rim, and the further below par a line runs, the deeper and faster it's pulled toward the centre. Hover to read a fish, click to open it, or drag to spin the whole shoal.