Context
The mobile version of Sportify, built with Flutter on the phone and Supabase behind it. It works end to end on Android and in the iOS simulator and has not been released to a store.
What made it hard
People who want to play a sport often have no one at their level to play with, and training alone gives no feedback on whether the movement is right. The app pairs people by shared sports and close skill levels, lets them open and join games, and coaches form through the camera.
The interesting problems are all about things happening at the same moment: two people liking each other at once, several people tapping Join on the last slot, and chat messages sent while offline.
Key decisions
The rules live in the database, not in the app
Matching, joining a game, sending a message and finding candidates are SQL functions behind row level security, tested with pgTAP. The app is only a client of those rules and cannot skip them, and the service key is never shipped in it. I accepted that logic is harder to change in SQL than in Dart, in exchange for rules that no client bug can bypass.
No counter for open slots
A stored counter that is read before it is written sells the last slot twice. Joining a game counts the participants while holding a lock on that game, so a game never has more players than its limit. Swipes use a single insert-or-update on one row per pair, so two simultaneous right swipes always see each other and a retry is harmless.
Pose estimation on the phone, and a rep is a whole movement
Inference runs on the device, so workout video never leaves it. Detectors jitter and lose people, so the coach smooths the angles and only counts a rep after a full stand, descent, bottom, rise and stand. A wobble is not a rep. That logic is plain Dart, tested on invented bodies, and the cost is that accuracy depends on the phone someone owns.
What shipped
- Sign-in with a session that refreshes itself, onboarding for sports and skill levels, and a swipe deck ranked by shared sports and close levels.
- Open play games: create, join, leave, edit, cancel, search and filter. One chat per match and per game, kept in order and surviving being offline.
- Push notifications for new messages on Android, and an AI coach that counts squats and says what to fix.
- 558 app tests and 224 database tests, plus scripted concurrency runs where swipes, joins and messages race and the counts must come out exact.
- A load report, architecture decision records, and CI for both the app and the database.
