Stockroom: Inventory & Purchase Order ERP
An inventory and purchase-order ERP where receiving is atomic and stock history is append-only, enforced by the database.
- TypeScript
- React
- Node.js
- Express
- SQLite
The problem
A small shop or café sits between two mistakes: order too much and cash sits on shelves, order too little and sales are lost. Stockroom tracks stock, suppliers and orders and suggests what to reorder. The stock count must never drift, even when two people receive the same delivery at once.
Architecture
How Stockroom handles a request
Browser
- React 18 and TypeScript
Express 5 API
- Bearer JWT
- Zod validation
RBAC policy (rbac.js)
- Route permissions
- Row scope
- Per-record policy
- Field masking
Services
- Inventory
- Purchase orders
- Dashboard
SQLite (node:sqlite)
- BEGIN IMMEDIATE … COMMIT
- Triggers: stock history, order state machine
Key decisions
- Receiving is atomic.
- Receiving sets the status only where it is still ordered; zero rows matched means it was already received, so the request returns 409 and rolls back. A double click or two receivers cannot add stock twice.
- Stock only changes through history.
- A trigger rejects direct edits to a product’s stock, history rows cannot be edited or deleted, and a CHECK constraint aborts anything that would take stock below zero.
- The order lifecycle lives in the database.
- Draft, awaiting approval, ordered, received and cancelled transitions are enforced by a trigger, not just by the app, and received or cancelled orders are frozen.
- Four layers of access control on the server.
- Route permissions, row-level scope, per-record policy with separation of duties (a manager cannot approve their own order) and field masking that strips costs from staff responses. The browser only hides buttons and is never trusted.
Proof
- permissions across 3 roles
- cumulative layout shift
- undersized tap targets fixed
Roles, permissions and the four layers
server/src/rbac.js in the Stockroom: Inventory & Purchase Order ERP repository
Triggers and constraints that guard stock
server/src/schema.sql in the Stockroom: Inventory & Purchase Order ERP repository
Data-integrity tests
server/test/integrity.test.js in the Stockroom: Inventory & Purchase Order ERP repository
Headless-Chrome UX audit: 175 runs, CLS and tap targets
docs/ux/REPORT.md in the Stockroom: Inventory & Purchase Order ERP repository
What it doesn’t do yet
- The demo runs on a free plan: after it has been idle the first visit takes about 30 seconds, and its data resets whenever the service restarts.
- It is one Node process with SQLite running in-process, with no separate database server.