All projects

Self-Checkout System

A supermarket self-checkout built end to end: touch kiosk, scanner and scale services, card payments and a full test toolbox.

Status
Active
Read
3 min
Source code
Private repository
  • .NET 10
  • C#
  • Avalonia
  • Stateless (state machine)
  • RabbitMQ
  • PostgreSQL
  • ASP.NET Core
  • Stripe (test mode)
  • Python
  • PySide6
  • GitHub Actions
  • Docker
Walkthrough: start screen, scanning and weighing two products, choosing card payment, payment processing, payment successful, receipt

The problem

A self-checkout looks simple: scan, pay, leave. Underneath, it has to trust a scale more than the customer, keep working when a device drops out, and never charge a card twice or lose a payment it cannot confirm. I wanted to build one end to end, to the standard of a real product, and show how I approach that kind of system.

What I built

A complete self-checkout system for supermarkets: the touch kiosk and everything around it:

  • Kiosk app (.NET, Avalonia): the customer flow from welcome screen to receipt, in Romanian and English, with larger text, high contrast and a staff menu behind a PIN.
  • Device services: barcode scanner and scale services that publish readings and heartbeats over RabbitMQ.
  • Payment service: a small web API in front of the card provider, so the kiosk never holds payment keys.
  • Product catalogue and records in PostgreSQL: products, sessions and payments.
  • Test toolbox in Python: a scanner and scale simulator, a product registration tool and a scenario runner that drives the real kiosk end to end.

Key engineering decisions

One state machine decides everything. Every step of a checkout (scanning, weighing, a wrong weight, payment, receipt, out of order) is a state with explicit transitions. The screens only display the current state. This makes edge cases visible and testable, and a test fails if the published state diagram differs from the code.

The scale is the source of truth for loss prevention. Each scanned product must be placed on the scale and match its expected weight within a tolerance, using stable readings rather than single values. Items taken off the scale, unscanned items and wrong weights stop the session with a clear way out instead of a dead end.

Payments are idempotent and never guessed. Every attempt carries an idempotency key, so a retry after a timeout cannot charge twice. A result that cannot be confirmed is never shown as failed or successful: it goes to staff.

One contract, two languages. Message formats and database migrations live in one place and are verified from both the C# app and the Python tools, so the simulator and the kiosk cannot drift apart.

Time is injected. Timers for weighing, inactivity and payment use an injected clock, so tests move time forward instead of waiting, and timing behaviour is tested exactly, without slow or flaky tests.

It fails safely. When a device stops responding the kiosk shows "out of order" and returns to the same basket by itself; sales wait in a durable outbox while the database is down. End-to-end scenarios stop the database and the message broker mid-session to prove it.

Architecture rules are tests too. The state machine may not depend on the UI or the infrastructure, only the payment service may talk to the card provider, and no code reads the system clock or writes to the console. Every requirement is linked to the tests that prove it, and one local command runs every check before a feature is integrated; continuous integration repeats it on a clean machine, with security scans, on the way to a release.

Operations can see inside it. Traces follow a scan from the device service through the kiosk to the payment service, with metrics and correlated logs on a dashboard kept as code. The dashboard screenshot on this page comes from an end-to-end run.

An unhandled error has occurred. Reload 🗙