BlokxBlok — Flutter Fitness Platform
Flutter app, serverless Python backend, and the CI/CD that ships both
- Status
- In progress
- Timeline
- Jan 2025 · ongoing
- Kind
- Professional
- Role
- Lead Developer — Flutter & Backend
- Team
- Lead developer of a cross-functional team (mobile, backend, web, QA): technical direction, PR reviews, client calls, and hands-on delivery across app and backend.
- Client
- BlokxBlok (UK), via Cybage Software
Overview
BlokxBlok is a fitness platform, currently in beta, for CrossFit-style training. Coaches write structured training programs; members discover them in a mobile app, buy them with an in-app currency called BLK, and follow them session by session. As lead developer I designed the Flutter app for iOS and Android from the start, built in-app purchases on both the app and the backend, and own the backend architecture: serverless Python microservices on Firebase and Google Cloud, the schema contracts every part of the platform shares, and the mobile CI/CD.
Problem
A training program is deeply nested — program → bloks → weeks → sessions → sections → pieces → parts → exercises — with more than 200 parameters across formats like AMRAP, EMOM, For Time and Interval. Compiling that on the device was too slow and too complex, and every change to the raw schema risked breaking the app. Payments carried their own risk: the app must never be able to change a user's balance, and a store purchase must never be credited twice — even when a store API times out or a function retries.
Approach
Programs: I proposed splitting the data into two schemas — the raw program coaches author, and a compiled, human-readable display schema the app reads. A Pub/Sub-triggered compiler turns one into the other and writes a new revision each time, so the version history lives in Firestore. If the compiler or schema changes, every program is recompiled and the latest version reaches users — which made a recent raw-schema overhaul easy to roll out, because the app only reads the display schema. Payments: the backend owns the whole flow as an explicit state machine over App Store and Play Store receipt validation. Crediting runs in atomic Firestore transactions with idempotency checks and locks, alongside a transaction ledger. Failures get inline retries, scheduled re-attempts through Cloud Tasks, a safety-net sweep and a user-triggered retry; a final failure notifies the user by email and push. Contracts: JSON Schema is the single source of truth for every Firestore collection, generating typed Dart and Python models released as versioned packages, so the app, the functions and the coach console never drift apart.
Architecture
Each backend domain deploys as its own Firebase Functions codebase, so the backend runs as a set of small serverless microservices. Trusted writes (purchases, credits) go through callable functions with App Check; the app streams everything else straight from Firestore.
- Flutter app
- iOS + Android: library, wallet, hub, training sessionsFlutter · Bloc · get_it
- Transactions
- Receipt validation, BLK crediting, program purchases, retriesPython · Cloud Tasks
- Program compiler
- Raw program → revisioned display documentPython · Pub/Sub
- Notifications
- Push, in-app and email, immediate or scheduledFCM · SendGrid
- Schema contracts
- JSON Schema → Dart + Pydantic packagesTyper CLI · Artifact Registry
- Coach console
- Internal program authoring toolStreamlit · Cloud Run
- Marketing site
- Public site and newsletterHugo
- CI/CD
- PR checks → App Distribution → TestFlight / PlayGitHub Actions
Challenges
Never crediting a purchase twice
Store callbacks, retries and user-triggered retries can all race for the same purchase. The ledger entry is created together with the purchase, and crediting runs inside one Firestore transaction with an idempotency check and a lease, so only one attempt can ever succeed.
Recompiling only when something changed
Moving recompiles from a Firestore trigger to Pub/Sub lets CI, the console or a script request one without calling a function directly. CI publishes only when a fingerprint of schema version, compiler version and content revision changes, and unchanged programs are skipped.
Guest access
Guests could reach purchased-program and user data they shouldn't see. I tightened access so a guest sees only what a guest is allowed to, and guest-to-Google/Apple upgrades keep the user's data.
Stack
- mobile
- Flutter
- In-app Purchases
- Dart
- Bloc
- backend
- Python
- Firebase
- Firebase Cloud Functions
- Pydantic
- SendGrid
- data
- Cloud Firestore
- JSON Schema
- cloud-devops
- Cloud Pub/Sub
- Cloud Tasks
- Google Cloud Platform
- GitHub Actions
- Terraform