---
name: commerce-integrity
description: "Preserve order and inventory integrity in a transactional backend. Use for inventory, SQLite, transactions."
---

# Остатки и заказы

Preserve order and inventory integrity in a transactional backend.

## Implementation decisions

1. Validate current stock inside the transaction and commit order plus stock changes atomically.
2. Bind each unique idempotency key to a canonical payload hash and reject different-payload reuse.
3. Parameterize values, allowlist sort keys and enforce quantity/body limits.
4. Do not hold a transaction open across external payment network requests.

## Working source

Read [starters/commerce/server.py](../webcraft-shared/source/starters/commerce/server.py) when implementing this capability. The example belongs to the WEBCRAFT React/Three.js playground except the Python commerce starter, which runs without third-party dependencies. Use [shared catalog](../webcraft-shared/source/lib/catalog.ts) only to resolve related examples. Adapt the source to the target framework and preserve existing project conventions.

## Verify observable behavior

- Only one order wins the last unit of stock.
- An exact replay returns its original order.
- An invalid line rolls back every decrement.

## Scope

Use only the parts relevant to the requested task. This skill does not grant permission to publish, spend money, change account access or expose secrets. The original brief and environment rules remain authoritative.

Version 2.0.0 · Original WEBCRAFT content · MIT
