# Implementer — F-016 Inventory module

## Summary
Implemented an isolated inventory module with atomic stock counters, public `InventoryService`, PostgreSQL persistence, API routes, migration, and regression tests.

## Files changed
- `project/migrations/011_inventory.js`
- `project/src/app/build-app.ts`
- `project/src/app/tests/inventory.itest.ts`
- `project/src/modules/inventory/index.ts`
- `project/src/modules/inventory/api/inventory.routes.ts`
- `project/src/modules/inventory/application/inventory-service.ts`
- `project/src/modules/inventory/domain/errors.ts`
- `project/src/modules/inventory/domain/ports.ts`
- `project/src/modules/inventory/domain/stock.ts`
- `project/src/modules/inventory/infrastructure/pg-inventory-repository.ts`
- `project/src/modules/inventory/tests/boundary.test.ts`
- `project/src/modules/inventory/tests/inventory-service.test.ts`

## Acceptance evidence
- AC1 concurrent last-unit reservation: `project/src/app/tests/inventory.itest.ts` covers 10 concurrent reservations; exactly one succeeds when DB integration tests are enabled.
- AC2 zero-stock reservation: `project/src/app/tests/inventory.itest.ts` covers rejection and non-negative counters; DB CHECK constraints also enforce non-negative stock.
- AC3 catalog isolation: `project/src/modules/inventory/tests/boundary.test.ts` scans catalog source for inventory table/import coupling.
- AC4 checkout service dependency: `project/src/modules/inventory/index.ts` exports the public `InventoryServicePort` and `InventoryService` for future checkout injection.
- `verify.sh`: passed.

## Commands run
- `cd project && npm run typecheck` — passed
- `cd project && npm test` — passed; DB integration tests skipped because `TEST_DATABASE_URL` is not set
- `cd project && npm run build` — passed
- `cd project && npx prettier --write ...` — formatted inventory files
- `cd project && npm run lint` — passed
- `./scripts/verify.sh` — passed

## Notes
- No new runtime dependency was added.
- Reservation correctness uses a single predicate `UPDATE ... WHERE available >= quantity`, not application read-before-write.
- Product/variant ids are opaque UUIDs to keep inventory independent from catalog internals.
