Food ordering

Cart state on the client creates three classes of problem that are structural, not implementation errors.

Try the live demo →

The client-side state model

In most food ordering SPAs, the cart lives in client-side state, typically a Redux store or context. Item additions, quantity changes, and removals update the local cart immediately. The server is informed at checkout. This produces three structural problems:

  • Price manipulation. The client holds item prices. A user can modify the cart price representation before checkout. Server validation at checkout catches this, but the window exists and must be explicitly closed.
  • Availability staleness. Items in the client cart may have gone out of stock since the page loaded. The client does not know. The failure surfaces at checkout, the worst possible moment.
  • Cart integrity. Multiple tabs, page reloads, and session expiry all create opportunities for client-side cart state to diverge from what the server knows about the order.

What moves to the server under SAUI

  • Cart state: the server owns the cart for the session
  • Item pricing: computed from the server current price table on every render
  • Availability: checked on every add-to-cart action, not at checkout
  • Quantity limits: validated at the gateway before the cart event is appended

The client submits an AddToCart action. The gateway validates it: item exists, item is available, quantity is within limits, price is current. If valid, a CartItemAdded event is appended. The handler returns the updated cart projection. If not, the current truth is returned with an error.

What stays on the client

  • UI animations on cart update (CSS)
  • Quantity input focus state
  • Menu section scroll position

These are legitimate UI-only states. They have no business meaning and no security implication. They live in CSS or minimal JS and are discarded on navigation.

Security properties gained

Price manipulation is structurally impossible: the client never holds prices, only a projection of what the server computed. Availability attacks are eliminated; the server validates availability at action time, not at checkout. Cart tampering has no attack surface because there is no client-side cart object to tamper with.

Testing surface change

Under the SPA model: tests for cart state management, tests for price display accuracy, tests for checkout flow with stale cart, tests for session recovery. All of these test the synchronisation problem.

Under SAUI: one test per action validates the business rule. One test per projection validates the read model. The HTML render test is a snapshot. No synchronisation to test.

Next: Banking