Back to projects
2026Full Stack Architect & Developer

PetWMS — On-Premise Warehouse WMS with Immutable Kardex & FEFO

100% offline on-premise WMS built with Django DRF, MySQL 8 InnoDB, and React 19: immutable Kardex, strict FEFO, deadlock-free id ASC row locks, keyset pagination, streaming CSV, and 59 real MySQL tests.

  • Python 3.13
  • Django
  • Django REST Framework
  • MySQL 8 InnoDB
  • React 19
  • Tailwind CSS 4
  • Pytest
  • PowerShell
Architecture diagram of PetWMS combining offline React 19 barcode UI, strict FEFO, deadlock-free id ASC locks, immutable MySQL 8 InnoDB Kardex, and 59 tests

Problem

Pet food, accessories, and veterinary supply warehouses face four recurring operational failures when running on spreadsheets or generic inventory tools:

  • Concurrency & retry stock drift: two operators dispatching the same SKU simultaneously or double-clicking a dispatch form creates negative balances or duplicate deductions.
  • Expiration waste without FEFO enforcement: lacking real per-lot balances and outbound validation causes newer batches to ship first while near-expiry bags sit behind them.
  • Slow sanitary recall tracing: when a manufacturer reports a contaminated batch, tracing its supplier receipt, remaining warehouse balance, and destination branches manually takes hours.
  • Unreliable warehouse connectivity & cloud fees: many warehouses need private, zero-subscription on-premise execution (127.0.0.1) that works 100% offline.

Architecture and decisions

PetWMS is a single-tenant local WMS engineered with Python 3.13, Django, Django REST Framework, MySQL 8.0 (InnoDB), and an offline React 19 + Tailwind CSS 4 warehouse interface:

Accounting integrity, deadlock-free concurrency & strict FEFO

  • Immutable 1:N Kardex ledger: MovimientoIngreso and MovimientoEgreso disallow UPDATE and DELETE; corrections happen strictly through auditable contra-entries (AJUSTE_POSITIVO, AJUSTE_NEGATIVO_MERMA, ANULACION_INGRESO).
  • Batch-level FEFO & printable A4 recalls: StockLote(producto_id, lote) maintains live physical balances. Outbound workflows automatically suggest the earliest valid expiring lot, while the backend rejects expired lots (409 LOTE_VENCIDO) and FEFO skips (409 FEFO_VIOLATION). Bidirectional lot lookup reconstructs supplier, inbound receipts, warehouse remainder, dispatched branches (carrier & document), and shrinkage ready for A4 printouts.
  • Deadlock-free pessimistic locks & “All-or-Nothing” receipts: chose MySQL 8.0 InnoDB (CHECK, ON DELETE PROTECT, DECIMAL(12,3)) over SQLite to run select_for_update() sorted deterministically by id ASC across atomic multi-SKU receipts, preventing InnoDB deadlocks at the root. Any single item failure rolls back the full receipt.
  • Server authority, Keyset pagination & streaming CSV: the server computes stock_actual, stock_resultante, fecha_hora_exacta, and usuario_responsable, requiring a unique UUIDv4 idempotency_key per write. Kardex history uses cursor (Keyset) pagination over (fecha_hora_exacta, tipo, id) with UNION ALL (no OFFSET), while exports stream via StreamingHttpResponse in constant memory with CSV formula injection neutralization (=, +, -, @).
# Deterministic id ASC lock ordering before select_for_update() prevents InnoDB deadlocks
product_ids = sorted({item["producto_id"] for item in items})
locked = {
    p.id: p
    for p in Producto.objects.select_for_update().filter(id__in=product_ids).order_by("id")
}

Offline barcode-first UI & turnkey deployment

  • Warehouse barcode UX: React 19 + Tailwind CSS 4 with zero heavy UI frameworks or blocking CDN fonts; autoFocus, direct Enter barcode resolution free from debounce races, tabular-nums, and printable receipts.
  • 1-click local delivery: automated PowerShell/Batch packaging (instalar_cliente.ps1, PetWMS.bat, PetWMS_Detener.bat) enabling complete Windows workstation deployment with no Node.js or paid cloud services required.

Challenges

  • Real multithreaded last-unit contention: serializing concurrent threads fighting over the last unit of stock via InnoDB select_for_update(), ensuring the winner commits and the runner-up receives 409 STOCK_INSUFICIENTE with zero negative balances or lost updates.
  • Contra-entry & quarantine invariants: entries marked EN_REVISION or DANADO log into the Kardex without inflating dispatchable stock; cancellations (ANULACION_INGRESO) lock the source receipt and block over-cancellation (409 ANULACION_EXCEDIDA); supervisor quarantine releases reject over-release (409 LIBERACION_EXCEDIDA), and product soft-deletion is blocked while positive stock or pending quarantine remains.
  • Operator-focused frontend audit: stripped database jargon from the UI, unified catalog modals with inline validation, added AbortController against async races, and safeguarded operators against silently omitting unadded items on multi-line receipts.

Outcomes

  • 59 automated pytest-django tests executed directly against real MySQL 8.0 InnoDB (no SQLite): covering SQL constraints (CHECK, ON DELETE PROTECT, EXPLAIN-verified indexes), real multithreaded concurrency, strict FEFO, UUIDv4 idempotency, RBAC (OPERARIO vs SUPERVISOR_AUDITOR), atomic token rotation, sanitized 500 JSON responses, CSV formula neutralization, and supervisor-only SQL backups.
  • Turnkey commercial on-premise release: 100% offline operation, instant A4 recall reporting, and 1-click local installation.

A full walkthrough of FEFO dispatching, expired-lot blocking, quarantine releases, recall tracing, and the immutable Kardex is available via the Video demo link in the header and sidebar. Proprietary codebase reserved for commercial licensing.