Skip to content
$ cd ../projects

// case study · Open source · Nov 2025

Multi-Warehouse Inventory API

A REST API for managing stock across many warehouses in different countries, with safe transfers, a global stock view and daily low-stock reports.

Laravel 12PHP 8.2MySQLJWTPHPUnitOpenAPI
View source on GitHub ↗
my role
Sole developer: design, implementation, tests and docs
the problem
A business with warehouses in several countries needs one source of truth for stock. It must be able to move goods between any two warehouses without stock ever going negative or ending up half-transferred.

Architecture

  1. FormRequest
  2. Controller
  3. Service
  4. Repository
  5. Model / DB

What I built

  • CRUD APIs for countries, warehouses, products and suppliers, with pagination, search, sorting and soft deletes.
  • IN/OUT inventory transactions that reject an OUT when the warehouse doesn't have enough stock.
  • Warehouse-to-warehouse transfers (even across countries) that run inside a single database transaction, so a failure rolls back both sides.
  • A global inventory view that totals stock per product across warehouses, filterable by country, warehouse, name or SKU.
  • A low-stock report endpoint, plus an artisan command scheduled daily that emails the report and can post to Slack.
  • A LowStockReached event dispatched whenever stock falls to its minimum, so new alerts can be added as listeners.

Engineering details

  • Layered structure: FormRequests → Controllers → Services → Repositories → Eloquent models.
  • Shared BaseRepository and SearchAndSort / ApiResponse traits keep every module consistent.
  • Product reads are cached with Cache::remember and invalidated on update and delete.
  • JWT auth protects every business route.
  • OpenAPI 3 docs are generated automatically with Scramble at /docs/api, and a Postman collection is included.
  • PHPUnit tests cover each module, including transfers, transactions and the low-stock report.

The pattern, in code

app/Services/Inventories/InventoryService.php
public function transfer(array $data, User $user): array
{
    return DB::transaction(function () use ($data, $user) {
        // OUT from source: throws if stock is insufficient,
        // which rolls back the whole transfer.
        $out = $this->createTransactionRecord([
            ...$data,
            'warehouse_id'     => $data['from_warehouse_id'],
            'transaction_type' => TransactionType::OUT->value,
        ], $user);

        $in = $this->createTransactionRecord([
            ...$data,
            'warehouse_id'     => $data['to_warehouse_id'],
            'transaction_type' => TransactionType::IN->value,
        ], $user);

        return ['from_transaction' => $out, 'to_transaction' => $in];
    });
}

Outcomes

  • Stock can't go negative or be left half-transferred: transfers are all or nothing.
  • Self-documenting API: interactive OpenAPI docs and a Postman collection.
  • Ops visibility through scheduled low-stock emails and Slack alerts.