Business & shops

Build a loyalty punch card app for your café (native Android)

A native Android build brief for a digital coffee punch card: the counter phone scans a customer's QR code, adds a stamp, and the tenth drink is free.

Apirex TeamUpdated AndroidiOS
On this page
  1. Screens
  2. Data model
  3. Native features
  4. Android notes (Kotlin and Jetpack Compose)
  5. iPhone notes (Swift and SwiftUI)
  6. Copy-paste prompt
  7. Acceptance test
  8. Frequently asked questions
5screens
4data tables
166word prompt
2platforms: Android, iOS

Paper punch cards get lost in wallets, washed in jeans and faked with a pen. This brief swaps them for a QR card on the customer's phone and a scanner on the café's counter phone: scan, buzz, one stamp, and the tenth coffee is free. Android comes first because the counter device is usually a cheap Android phone, and CameraX with on-device barcode scanning reads a code in under a second. The iPhone version uses a camera data scanner and needs a Mac with Xcode to build. The first proof is a full card: ten scans on ten separate visits unlock one free drink, and a second scan in the same minute adds nothing.

Screens

  • Scan: A live camera view at the counter that reads the customer's card and shows their stamps.
  • Stamp result: A big tick, the new count out of ten and a short buzz.
  • Reward: When the card is full, a Redeem button that the barista taps after handing over the drink.
  • Customers: Search by card nickname, see stamps and fix a mistake with a reason.
  • Card page: A simple web page or screen the customer saves, showing their QR code and stamps.

Data model

Punch card records
TableKey fieldsPurpose
cardsid (uuid), code (text unique), nickname (text), created_at (timestamptz)One card per customer; the QR holds only the random code.
stampsid (uuid), card_id (uuid), staff_id (uuid), stamped_at (timestamptz), voided (bool), void_reason (text)Every stamp kept as its own row, so mistakes are voided rather than deleted.
redemptionsid (uuid), card_id (uuid), staff_id (uuid), redeemed_at (timestamptz)Each free drink handed over, which resets the visible count.
rulesid (int), stamps_needed (int), cooldown_min (int), reward_text (text)The café's own terms: how many stamps, how long between stamps and what the reward is.

A single counter phone can run fully offline with Room. As soon as there are two counter phones or a customer card page, the cards and stamps must live in one place: connect your own Supabase, let only signed-in staff insert stamps through a database function, and make that function enforce the cooldown so two baristas scanning the same card at once still create one stamp. The QR code should carry a random card code, never a phone number or name.

Native features

The counter experience decides whether staff actually use it. The camera should open straight into scanning, read the code without a tap, give a clear buzz and a big tick, then be ready for the next person. CameraX with on-device barcode scanning handles poor café lighting well, and nothing about the customer needs to be sent anywhere for the scan itself.

FeatureAndroid (Kotlin)iPhone (SwiftUI)Notes
Scanning the cardCameraX ImageAnalysis with ML Kit barcode scanningVisionKit DataScannerViewController for QR codesRead QR only, ignore other barcode types and debounce repeat reads of the same code.
Stamp feedbackVibrator one-shot effect plus a soundsensoryFeedback success plus a soundStaff should know it worked without looking at the screen.
Customer QRZXing or a Compose QR drawing for the card screenCoreImage CIQRCodeGeneratorShow the code large with high contrast so it scans through a cracked screen.
Shared counterssupabase-kt calling a stamp functionsupabase-swift calling the same functionThe server applies the cooldown and the stamps-needed rule.

Android notes (Kotlin and Jetpack Compose)

Lock the counter app to portrait and keep the screen on while the Scan screen is visible, since staff will prop the phone against the till. Hold scan state in a ViewModel so a phone call or rotation never repeats the last stamp.

  • Bind CameraX Preview and ImageAnalysis to the lifecycle with STRATEGY_KEEP_ONLY_LATEST, pass frames to the ML Kit barcode scanner restricted to FORMAT_QR_CODE, and ignore the same code for three seconds after a read.
  • Call the stamp function and show the server's answer, not a local guess: success with the new count, too soon with the minutes left, or unknown card. If offline, queue the stamp locally and mark it pending until it syncs.
  • On a real phone in a dim room, scan a customer card shown on another phone at 30 per cent brightness. Then scan it twice within ten seconds and confirm only one stamp row exists.

iPhone notes (Swift and SwiftUI)

On iPhone, DataScannerViewController can recognise QR codes live and return the payload to SwiftUI through a representable wrapper. It needs a real device with a camera, so all scanning tests happen on hardware.

  • Check DataScannerViewController.isSupported and isAvailable before showing the scanner, and fall back to manual code entry if camera access is denied.
  • Keep staff signed in with the Supabase session in the Keychain so the counter phone does not ask for a password mid-rush.
  • Test on a physical iPhone held at an angle over a phone screen with glare, and time how long a scan-to-tick takes; aim for about a second.

Copy-paste prompt

Build this yourself 164 words · Android
Build a coffee punch card app for my friend's café so customers stop losing paper cards. Make the counter app native Android. Screens: Scan, Stamp result, Reward, Customers and a Card page the customer saves with their QR code. When the barista scans a customer's QR, add one stamp, show a big tick and the count out of ten, and buzz the phone. On the tenth stamp show a Redeem button for a free coffee. Store cards, stamps, redemptions and rules in my own Supabase with row-level security, and add stamps only through a server function that blocks a second stamp on the same card within 30 minutes. The QR should hold only a random card code, never a phone number. Let staff void a wrong stamp with a reason instead of deleting it. Handle no camera permission, an unknown card, a lost connection and a full card. Acceptance: ten stamps on separate visits unlock one free coffee and a double scan adds nothing.

Opens Apirex with this prompt in the box. Pick the Android · Kotlin tab before you send.

Acceptance test

  1. Create a card and open its Card page on a second phone; scan it from the counter app and confirm one stamp and a buzz.
  2. Scan the same card again straight away and confirm the app says it is too soon and no new stamp row exists.
  3. Add stamps until the card shows ten of ten, tap Redeem and confirm the visible count resets while history keeps the old stamps.
  4. Void one stamp with a reason and check the count drops by one and the void is visible in Customers.
  5. Deny camera permission and confirm manual code entry still adds a stamp through the same server rule.

Run one fake busy hour before going live: two counter phones, twenty quick scans and a few deliberate mistakes. The stamp count for each card in the database should match what staff saw, and the café owner should be able to read who stamped what without opening a spreadsheet.

Frequently asked questions

Do customers need to install an app?

No. In this brief the customer card is a simple page or screen with a QR code they can save. Only the café's counter phone runs the scanning app.

Can a customer cheat by screenshotting someone else's QR?

They can share a card, as with paper, but the server cooldown stops rapid repeat stamps and every stamp records which staff member added it, so unusual patterns are easy to spot.

Can it handle several branches?

Yes, if all counters connect to your own Supabase project. Add a branch field to stamps and decide whether cards are shared across branches before you build.

Build this blueprint

The blueprint prompt, ready for your platform. Edit anything before you send it.

AndroidKotlin · Jetpack ComposeReal source on your computer

Opens Apirex with this prompt. Pick the Android · Kotlin tab before you send. The Free plan includes 5 Rex Credits a day.