Context

Bachelor Companion was made for one bachelor party weekend. Guests collect a currency, named after the groom’s surname, in tournaments, 1v1 duels, a quiz about the groom and side quests, and hunt for easter eggs. Some eggs are hidden in the app, and some are printed as QR codes and placed around the venue. Whoever has the most at the end of the weekend wins. The top three had moonshine waiting, plus a T-shirt for first and a cap for second, both with a picture I made of everyone who took part.

The currency can also be spent in the shop, on buffs for yourself or on troll items against the leader or your next opponent. The economy was set up so that a purchase could pay off, even though whatever is spent no longer counts at the end.

I built it alone in September 2025. The same month, 12 people used it for a weekend. In 2026 I made a public demo with synthetic data, where anyone can sign in as the admin.

Problem and constraints

One of those 12 people ran the game, in the middle of the party. To leave a way out for anything unexpected, almost everything could be changed from the admin panel: the bracket after it was generated, how many wins a match is played to (a final to one instead of three, to save time), shop prices through discounts to get people buying, the list of players in case someone dropped out, and the eggs, which could be reset and claimed again once hidden.

For balances, being able to edit was not enough. Mistakes were easy to make, so every entry had to come undone with the balances back exactly where they were. The prizes went by the currency, so no balance could go wrong or drop below zero.

A tournament bracket had to work for any number of players, not only 8 or 16. Every price in the shop had to be payable in paper notes, and the notes in the game could not make 10 or 30.

Decisions

Decision

Change a balance with one conditional operation in the database, and store the balance after each entry.

Alternatives

  • Work the balance out from the sum of all entries each time it is read. Always right, but every ranking and every check adds up the whole history.
  • Read the balance, check it and write the new one, at a stricter isolation level that retries on conflict. Correct too, but every caller has to handle the retry.

Why

The database adds the amount only if the result stays at zero or above. If it would not, nothing changes and the app refuses the entry. The check and the write are one operation, so two entries at the same moment cannot overwrite each other. Each entry stores the balance it left, and the history reads like a bank statement.

The price is a balance kept in two places: on the person and in their last entry. Code that changed the balance without an entry would make the two disagree. So every change to a balance goes through one function.

Decision

Undo every kind of payout the same way: net its entries, and refuse if anyone would drop below zero.

Alternatives

  • An undo written for each action: matches, duels, quiz answers, the audience bonus, whole tournaments. Each one simpler on its own, and five sets of rules to keep right.

Why

Every payout carries the id of the match, duel or quiz question it belongs to. To undo one, the app adds up those entries per person, checks that nobody would go below zero, and writes the opposite. Undoing a whole tournament is the same operation over more entries. A double-points bonus used up by the payout comes back with the undo.

A single entry can also be undone from the history, once. The reversal points at the entry it cancels, so undoing the whole match later does not take the money back twice.

A payout without an id cannot be undone, so every new kind of payout has to carry one. The rule is written down in the repository.

Decision

One shared admin password and a signed session, no user accounts.

Alternatives

  • Accounts for everyone through an auth library. Guests would sign in, and the app would know who did what.

Why

Guests only look at the app and claim the eggs they find, and neither needs an account. One person enters everything else. The password gets them a session token signed with HMAC-SHA256, with its expiry inside. The token is checked with Web Crypto, so the same code runs in Next.js middleware and in the route handlers. The middleware lets a change to data through only from a short public list, and each admin route also checks the session itself.

The app does not record which admin changed what. With one admin, there was no need.

Evidence

The screenshots show the demo’s made-up data, not the real weekend.

A tournament bracket in a dark interface. The qualifying round has 8 best-of-1 matches, 4 of them byes marked as going through automatically. Round 1 has 4 matches paying 40 tokens each, round 2 has 2 best-of-3 matches, and the final is best of 5 for 300 tokens. Admin buttons above show the losers bracket and edit the seeding.
12 players in a bracket of 16, seeded by balance. Four of them skip the first round.
Three entries in the history for one person, newest first: a purchase of Double Points for minus 170 tokens leaving 30, an organising bonus of plus 60 leaving 200, and a match win of plus 40 leaving 140. Undo and delete buttons are active on the purchase and greyed out on the other two.
Each entry shows the balance it left. The older two cannot be undone: with 30 tokens left, taking back 60 or 40 would go below zero.
The shop price list in admin view. A bar at the top switches discounts off and sets them at 20%. Each item shows its price, the old price struck through and a badge: minus 20% on buffs and troll items, and plus 29% on Double Points, which has a price of its own.
A 20% discount on everything except Double Points, which has its own price, above the base one. The badge shows how far a price is from the base: green for a discount, red for a surcharge.
Three paper notes from the game, one above the other: 20, 50 and 100, modelled on Polish złoty and marked Grand Bachelor Party, each with a blurred face. Beside the game's 100 lies a real 100 zł note, and above it a stack of blue, numbered QR code stickers.
The paper notes and the printed eggs from the real weekend, next to an ordinary 100 zł note. The face on the notes is the groom, blurred, at a different age on each: the higher the value, the older the groom.

Outcome

The easter eggs went down well, both the ones in the app and the printed ones. So did the side quests: plenty of people wanted the reward for catching a fish. There were also a lot of 1v1 duels in all sorts of games, from coin tosses for points to billiards and badminton.

Nobody bought double points or a troll item in the shop. We finished one tournament, coin tossing, losers bracket included, because every match there went quickly. A billiards tournament got halfway. The weekend turned out a bit too short to try everything.

I collected the printed eggs once they were found and hid them again. Anyone who had scanned one had its address in their browser history and could claim it a second time. Only a gentleman’s agreement stood in the way.

A year after the weekend I went back to the code, no longer for the game but for myself: I wanted to be happier with it. The API got input validation with Zod, and tests now cover the bracket, the prices, the sessions and the ledger.

What I would not repeat

Going to production for the first time the day before the trip. The build on Netlify kept failing on errors the development server had never shown, and the afternoon went on retyping every API route for Next.js 15.

At the venue, generating a bracket timed out. On the slow server it ran longer than Prisma lets a transaction run by default. I had no laptop, so I pushed the fix, a 60-second limit for that one transaction, from my phone through GitHub’s editor. On Vercel the same bracket takes about 2 seconds, so it was probably the server rather than the code. A week in production before the trip would have brought both problems out earlier.

Reading a balance and writing it in a separate step. Two entries at the same moment could overwrite each other. Luckily that never happened, and I only found and fixed the bug in December 2026, while getting the app ready for this case study.

Adding features up to the last minute. The more I built, the more ideas I had, and I barely finished in time. For the last four days I slept about four hours a night, and I was worn out on the day we left.

Next time I would make more eggs, in the app and on paper, so the same ones would not need hiding again. The eggs were what everyone liked most: months after the weekend, the guests still talk about how much fun they had hunting for them, above all the printed ones hidden around the venue.