Skip to content

andrewlengly.com/tab-split-casestudy :: s p l i t case study

# Scan a receipt and send one link. Friends tap what they had, and tax and tip split to the exact cent.

designed page ......... /tab-split-casestudy

THE SHORT VERSION

  S P L I T splits a restaurant bill from one scanned receipt. Friends tap what they had on
  a shared link, and tax and tip split to the exact cent. It is built with Next.js, Supabase
  and the Claude API, with Frankfurter for exchange rates, and it is live at
  split.andrewlengly.com.

the idea .............. Split the tab without the math. One person scans the receipt, and
                        everyone else taps what they had from a link.
what i did ............ Built a receipt scanner and a shared bill page on top of split math
                        that adds up to the total. Trips settle many receipts across
                        currencies.
where it stands ....... Live at split.andrewlengly.com. 18 tests cover what comes in from
                        receipts and requests, and the split math has none yet.

kind .................. Case study · Build
role .................. Developer
year .................. 2026
tools ................. Next.js, Supabase, Claude API, Frankfurter

what it does .......... Scans a receipt and sends one link. Friends tap what they had, and
                        tax and tip split to the penny.
the brief ............. Let friends split a receipt from their phones, with names that drag
                        or tap onto each item.

WHAT IT DOES

  # One person scans, and everyone else taps what they had.

scan .................. Take a photo of the receipt and Claude reads its line items and
                        totals. You can also type the items in.
paste ................. Copy the receipt text with Live Text or Google Lens and paste it in.
                        It’s parsed on the device with no network call.
who had what .......... Drag a name from the tray onto an item, or tap a name and then tap
                        items. Split everything evenly covers the whole bill in one tap.
one link .............. Friends pick their name on the bill link and tap what they had. The
                        bill page refreshes every 3 seconds, so everyone sees the same
                        claims.
tax and tip ........... Tax is a rate or an amount, and it falls only on taxed items. Tip is
                        a percent or an amount, split by order or evenly.
paying back ........... Each friend sees their amount on buttons for Venmo, Cash App, PayPal
                        and Zelle. The Zelle button copies the handle to paste into a bank
                        app.
trips ................. A trip collects receipts in different currencies and converts them
                        to one. It then lists the payments that settle everyone up.
running tab ........... The home page keeps a running tab across your recent bills, along
                        with saved groups. Both stay on your device.

HOW I BUILT IT

  # Two browsers played host and friend, and every total matched the hand-checked math.

  # From the first pull request to the settle-up fix
  01. First build
      Scan, paste, claims, pay buttons and trips
      Merged November 3, 2026
  02. Host and friend
      Two browser sessions in one Playwright run
      Claims, live updates, pay links and settle-up
      Left out: A real Claude scan and live exchange rates
  03. Its own host
      One rewrite for every path
      Old /split links redirect there
      Checked: Seven other hosts served the same pages as before
  04. Audit fixes
      Each scan logged before the model call
      Why: Scans sent together all got past the old limit
  05. Settle-up copy
      Four places promised the fewest payments
      Now they say who pays whom

  The audit came about a week after launch. A new claim now has to name an item and people
  that are on the bill, and new bills and trips are capped per visitor. On the bill screen
  only one save is in flight at a time, so two saves can’t land out of order.

THE QUESTIONS

  # Every screen answers a question about who owes what.

  Who had what?
    answered by ....... Claims, one row for each person and item
    shows on .......... The bill page

  What does each person owe once tax and tip are in?
    answered by ....... Each item shared among the people who claimed it, with tax, fees,
                        discounts and tip spread on top
    shows on .......... The bill page

  Do the shares add up to the bill?
    answered by ....... Largest remainder rounding to whole cents
    shows on .......... Every total

  Who pays whom after a whole trip?
    answered by ....... Net balances in one currency, then a greedy settle-up
    shows on .......... The trip page

HOW IT WORKS

  # Each browser does the math from one bill kept on the server.

  # How a receipt becomes a split
  01. Receipt
      A photo, shrunk to 2,000 px on its long side
      Or text pasted from Live Text
  02. Scan route
      Posts to the Anthropic Messages API
      A Claude Haiku model by default
      Reply capped at 2,500 tokens
      Every field of the reply checked
      Limits: 3 scans per visitor every 30 minutes, and 200 a day across everyone
  03. Supabase
      Five tables behind row-level security
      Reached only from server routes
  04. Bill page
      Shares computed in the browser
      Refreshed every 3 seconds
      Also reads: ECB daily rates through Frankfurter, cached 12 hours

  Pasted text goes to a parser on the device first. It handles rows printed on one line, and
  the layout where Live Text reads every name before every price. When the result looks off,
  Have Claude sort it sends the text to the model.

  The model’s reply never reaches the browser as is. It has to parse as JSON, and each field
  is read on its own. At most 200 items are kept. The code lives inside this site’s repo,
  which is private.

THE MATH

  # Shares round to whole cents and still add up to the bill.

  # Each person’s share
item share ............ item price / people who claimed it
tax share ............. tax × that person’s taxed items / all taxed items
tip by order .......... tip × that person’s items / all items
total ................. items + tax + fees − discounts + tip
  Fees and discounts follow each person’s part of the item total. A tip split evenly is the
  tip divided by the number of people.

  # Rounding
tax from a rate ....... rate × taxed items, rounded to the cent the way a register does
final shares .......... floored to whole cents, then the leftover cents go one at a time to
                        the largest remainders
  A $10.00 pizza split three ways with 7.25% tax and a 20% tip comes to $12.73. One person
  pays $4.25 and the other two pay $4.24.

  # Trips
balance ............... what a person is owed across the trip’s bills minus what they owe,
                        in the trip’s home currency
settle-up ............. the biggest debt pays the biggest credit, repeated until every
                        balance is zero
  Only unpaid shares count, and balances settle in whole cents.

  New US bills start at California’s statewide 7.25%. The picker holds 24 more city and
  county rates from the CDTFA table effective October 1, 2026, and a tax amount printed on a
  scanned receipt replaces the rate.
source for the california rates
                        CDTFA sales and use tax rates

WHAT IT FOUND

  # The shares add up to the cent, and a trip can take one payment more than it needs.

  The two charts below come from running S P L I T’s own split code, the same functions the
  bill and trip pages call.

  # Each share of the sample sushi bill
zankar ................ $32.51
justin ................ $31.94
nancy ................. $26.87
andrew ................ $24.66
bailey ................ $17.68
  The app’s own sample bill, with Sacramento’s 8.75% tax and an 18% tip split by order. The
  five shares add up to the bill’s $133.66. Rounding to whole cents left 1 cent over, and it
  went to Andrew, whose unrounded share of $24.65345 had the largest fraction of a cent.

  # Payments to settle an example trip
greedy, as the trip page lists them
                        4
shortest possible ..... 3
  Two bills shared by five people. A paid the first, and C and D owe $30 each on it. E owes
  B $50 for the second. Greedy sends E’s $50 to A, so C has to pay both A and B. Paying back
  whoever covered each bill takes 3.

WHAT RECEIPTS GOT WRONG

  # Receipt text shows up out of order.

  Live Text reads names and prices as separate columns
    risk .............. Items paired with the wrong prices
    call .............. The parser handles that layout, and the scan prompt tells the model
                        to pair them up

  Pasted text could close its own tag
    risk .............. Whatever follows reads as instructions to the model
    call .............. Strip any copy of the tag before sending, and check every reply as
                        data

  A long receipt can run past the reply cap
    risk .............. A reply cut off partway through the list
    call .............. Spot the cutoff and ask for the items by hand

  A burst of scans can outrun the counter
    risk .............. Requests slip past the limit before they’re counted
    call .............. Log each scan before the model is called, and stop when the log
                        can’t be written

  Some currencies have no ECB daily rate
    risk .............. A trip total that mixes currencies
    call .............. Count those receipts at face value and say so on the trip page

  Venmo and Cash App only take dollars
    risk .............. A pay button that opens with the wrong amount
    call .............. Hide both buttons on any other currency

DECISIONS

  # Nobody signs in, and a bill deletes itself.

no accounts ........... Starting a bill stores an edit key in that browser, and only that
                        browser can edit the bill. Anyone with the link can claim items and
                        mark themselves paid.
bills expire .......... A bill goes 30 days after its last change, or 7 days after everyone
                        has paid the payer back. An empty trip goes after 30 days.
cleanup with no cron job
                        Expired bills are cleared when someone starts a new one, at most
                        once an hour. Opening an expired link deletes that bill too.
polling ............... The bill page asks the server for the bill every 3 seconds, and only
                        while its tab is visible. Nothing holds a connection open.
no raw ips ............ The limit log stores a SHA-256 hash of the visitor’s IP with the
                        kind of request. Rows are deleted after a day.
caps on what a link can write
                        A bill holds up to 200 items and 40 people. One visitor can start 30
                        bills and 10 trips an hour.
kept out of search .... Bill and trip pages are noindex and blocked in robots.txt.

DESIGN

  # A name drags onto an item, and a tap does the same job.

drag pins ............. Names drag from the tray with a mouse or a finger. Drag a pinned
                        name to another item to move it, or back to the tray to take it off.
a short press on phones
                        A name already pinned to an item needs a 260 ms press before it
                        lifts, so a swipe down the list still scrolls.
scrolling mid-drag .... Hold a name near the top or bottom edge and the page scrolls under
                        it.
a tap path ............ Tap a name, then tap items. It does what the drag does.
a color for each person
                        Names take one of 12 colors, in the tray and on every item they’re
                        pinned to.
scoped styles ......... Every rule sits under .tabsplit, so none of it reaches the rest of
                        the site.

WHERE IT STANDS

  # Live, with tests on what comes in and none on the math.

tests passing ......... 18
tests on the split math
                        0
currencies a bill can use
                        27
california tax rates built in
                        25

  # What the tests cover
columns ............... Tests
receipt text parser ... 4
the model’s scan reply
                        8
claim requests ........ 6
shares and rounding ... 0
trip settle-up ........ 0
  The tested code is the code that takes outside input. S P L I T was added to this site on
  November 3, 2026 and now runs on its own subdomain.

WHAT’S NEXT

  # Tests on the money math come first, then an exact settle-up.

  # Next
math tests ............ Cover the share math and the settle-up, starting with the examples
                        on this page.
shortest settle-up .... Replace the greedy method with one that finds the shortest list of
                        payments. The example trip above is the first test it has to pass.
a real scan ........... Run a real receipt through Claude and a trip on live ECB rates. The
                        first test had neither.
quarterly rates ....... Check the built-in California rates against the CDTFA table when
                        each new quarter starts.

  # Known limits
untested math ......... The share math and the trip settle-up have no tests. The examples on
                        this page each come from a single run of the code.
greedy settle-up ...... The list of payments is not always the shortest one. The method is
                        greedy, and the example trip above takes 4 payments when 3 would do.
tax rates by hand ..... CDTFA changes rates each quarter. The built-in list is dated October
                        1, 2026 and gets updated by hand.
one browser holds the key
                        The edit key lives in one browser’s storage, and there is no sign-in
                        to get it back.
face value ............ A receipt in a currency with no ECB rate counts at its printed
                        number on a trip.

TL;DR

built ................. A receipt scanner and bill link where friends tap what they had and
                        tax and tip split to the cent.
found ................. The sample bill’s five shares add up to its $133.66, and the example
                        trip takes 4 payments where 3 would do.
  # by the numbers
  $133.66 ............. Sample bill, split to the cent
  18 .................. Tests passing
  0 ................... Tests on the split math
the catch ............. The split math has no tests. Each example on this page comes from a
                        single run of the code.
next .................. Write tests for the share math and the settle-up, starting with the
                        examples on this page.

LINKS

open s p l i t ........ split.andrewlengly.com
the developer side .... /machine/developer
the design side ....... /machine/designer

# end of /machine/tab-split-casestudy. andrew.leng.ly@gmail.com · leave machine mode