How I structure, build and ship my Flutter apps
30 Nov 2026
I work alone on several mobile apps at the same time. They don’t do the same thing at all, but if you open any of them, you’ll find the same folders, the same commands and the same release button. That’s on purpose: when I come back to an app after two months on another one, I don’t want to remember how this one works.
This post is that shared skeleton: how the code is organized, the tools around it, and how a version goes from my machine to the stores.
- One repository per app, everything inside
- Six packages, one direction
- The backend lives next to the app
- Tools
- Flavors and configuration
- How I ship a version
- What I’d keep if I started again
One repository per app, everything inside
An app is not just the mobile code. It’s also the Cloud Functions, the security rules, the landing page, the store assets. They change together, so they live together:
.
├── mobile/
│ ├── app/ # Flutter app (presentation)
│ ├── packages/
│ │ ├── <app>_domain/
│ │ ├── <app>_data/
│ │ ├── <app>_di/
│ │ ├── <app>_design_system/
│ │ └── <app>_utils/
│ ├── env.dev.json # --dart-define-from-file (git-ignored)
│ └── env.prod.json
├── functions/ # Cloud Functions, TypeScript
├── firebase/ # firestore.rules, storage.rules, indexes, rules tests
├── hosting/ # landing page, sometimes a small backoffice
├── tool/ # release.sh and other scripts
├── .github/workflows/ # ci.yml, release.yml, ship.yml
├── pubspec.yaml # Dart workspace + Melos config
├── .fvmrc # pinned Flutter version
└── CLAUDE.md # the architecture rules, for me and for the AI
A change that adds a Firestore collection touches the model, the repository, the rules, the rules tests and sometimes a function. With one repository, that’s one branch and one pull request, and the CI tests all of it together.
Six packages, one direction
The Flutter side is a Dart pub workspace driven by Melos. It’s split into six packages, and the dependencies only go one way:
app ──────────► di ──────────► data ──────► domain ──► utils
│ │ ▲
│ └──────► design_system │
└────────────────────────────────────────────┘
appseesdomain(models, use cases),di(the providers),design_systemandutils.appnever importsdata. It can’t call Firestore directly, even by accident: the import doesn’t resolve.domainimports neither Flutter nor Firebase.
This is a classic clean architecture. What makes it hold over time isn’t the diagram, it’s that the package boundaries are enforced by the compiler instead of by discipline.
Domain: pure Dart, organized by feature
The domain is grouped by business feature, not by technical type. Each feature folder has the same inside:
<app>_domain/lib/src/
├── core/ # exceptions, shared enums, cross-cutting service interfaces
├── user/
│ ├── models/ # freezed classes
│ ├── repositories/ # interfaces only
│ ├── services/ # interfaces only (analytics, storage, payments…)
│ ├── usecases/
│ └── enums/
├── family/
└── …
Every action of the app is a use case. One class, one public call(), dependencies through the constructor, a name that reads like a sentence: <verb>_<noun>_use_case.dart.
class CountChildrenUseCase {
final FamilyRepositoryInterface _familyRepository;
CountChildrenUseCase({required FamilyRepositoryInterface familyRepository})
: _familyRepository = familyRepository;
Future<Either<AppException, int>> call(String familyId) =>
_familyRepository.countChildren(familyId);
}
Many use cases are this short, and that’s fine. They give the app a single list of everything it can do (the usecases/ folders), a single place to add a rule later, and a trivial unit to mock in a widget test.
Nothing throws across layers. A fallible operation returns Either<AppException, T>; an operation with no result returns Unit; an absent value is an Option<T>. Every error is a subclass of the app’s exception hierarchy, which the UI knows how to translate. The compiler forces the caller to handle the failure, and the error screen never shows a raw FirebaseException.
Data: the only place that knows Firebase
<app>_data/lib/src/
├── datasources/ # thin wrappers around Firebase SDKs (Firestore, Storage, Auth, Functions…)
├── dtos/ # what's stored, json_serializable
├── mappers/ # dto ⇄ domain model
├── repositories/ # implementations of the domain interfaces
├── services/ # implementations of the domain services
└── converters/, extensions/, enums/
All Firestore access goes through one generic datasource, by collection path: getDoc, setDoc, updateDoc, getSnapshots, count… It’s the one place that turns Firebase errors into domain exceptions and reports the unexpected ones to Crashlytics. Collection paths come from one FirestorePaths class, with the ids as required parameters, so a typo in a path is a compilation error.
DTOs and domain models are separate on purpose. The DTO is the shape of the document (timestamps, nullable fields from old versions); the model is what the app wants to work with. The mapper is where the migration logic goes when a schema changes.
DI: public and internal providers
The dependency injection is Riverpod with code generation, and the package has two folders:
<app>_di/lib/src/providers/
├── internals/ # Firebase instances, datasources, repositories
└── publics/ # use cases and a few services, exported to the app
Only publics/ is exported. The app can ref.watch(createFamilyUseCaseProvider), it cannot reach a repository. This package is also where the environment lives: the flavor, the Environment read from the dart-defines, the Firebase setup.
App: one folder per feature
app/lib/
├── main_dev.dart
├── main_prod.dart
└── src/
├── app/ # MaterialApp, startup, observers
├── router/ # go_router, route names with their permissions
├── features/
│ ├── family/
│ │ ├── family_screen.dart
│ │ ├── family_providers.dart # screen state, @riverpod
│ │ └── widgets/
│ ├── onboarding/
│ └── …
├── forms/ # validators and their translated messages
└── extensions/
A feature folder holds a screen, its providers and its private widgets. Generated providers are only allowed in *_providers.dart files, so a screen file is only UI. Widgets use flutter_hooks with hooks_riverpod: controllers, focus nodes and animations live in hooks instead of StatefulWidget boilerplate.
Design system and utils
The design system package owns the theme (AppColors, AppFonts, AppDimens as theme extensions), the shared widgets, the assets and the bundled fonts: nothing is fetched at runtime. The rule in features is simple and greppable: no literal color, always Theme.of(context).appColors.
The utils package is small: Either, Option, Unit, the logger and a few extensions. Everything else depends on it, it depends on nothing.
The backend lives next to the app
The backend is Firebase: Auth, Firestore, Storage, Cloud Functions, Hosting, Crashlytics, Analytics, App Check, sometimes Remote Config and Messaging.
- Functions are in TypeScript on Node 22, one folder per domain (
users/,families/,notifications/,premium/…), deployed in a European region. - Rules are code.
firestore.rulesandstorage.ruleshave their own tests, run on the Firebase emulators with ademo-…project, so they can never touch real data. - A new collection or query always comes with its rules, its rules tests and, if needed, its composite index in the same PR.
Tools
| Tool | What for |
|---|---|
| FVM | Flutter version pinned per repository in .fvmrc. The CI reads the same file. |
| Melos | Every command of the project is a Melos script (below). |
| freezed / json_serializable | Immutable models, unions, DTO serialization. |
| riverpod_generator, hooks_riverpod | DI and state, with code generation. |
| go_router | Navigation, with redirects driven by the auth state. |
| slang | Type-safe i18n from JSON files (t.settings.title), French and English always updated together. |
| mocktail, fake_async | Unit and widget tests. |
| Firebase emulators | Rules and Cloud Functions tests, locally and in CI. |
RevenueCat (purchases_flutter) |
Subscriptions and in-app purchases on both stores. |
GitHub, gh, GitHub Actions |
Code, PRs, CI, release automation. |
| Claude Code | Pair programmer, constrained by a CLAUDE.md (see my previous post). |
Dependencies are declared once, in the root pubspec.yaml, under the Melos bootstrap config. melos bootstrap syncs the versions into every package, so two packages can never drift to two versions of cloud_firestore.
The Melos scripts are the same in every repository:
melos bootstrap # install, build the functions, generate, format
melos run generate # code generation, package by package, in dependency order
melos run watch # build_runner + slang in watch mode
melos run format # dart format -l 120, generated files excluded
melos run format:check # same, fails on a diff (CI)
melos run analyze # dart analyze --fatal-infos in every package
melos run test # every package with a test/ folder, with coverage and JUnit reports
melos run coverage # merged lcov + HTML report
melos run build:android # prod app bundle, obfuscated, Crashlytics symbols uploaded
melos run build:ios # prod IPA, obfuscated
melos run start-release x.y.z
melos run close-release x.y.z
The point is that the CI runs exactly these scripts. There’s no “works locally but CI does something else”: if melos run test passes on my machine, the CI step that runs melos run test passes too.
A few rules the CI enforces, because I know I’d skip them otherwise:
--fatal-infoson the analyzer: an info is a failure. A lint left “for later” is never fixed.- Generated files are committed, and the CI runs
melos run generatethengit diff --exit-code. A forgottenbuild_runnerfails the build instead of failing on someone else’s checkout. - Line length 120, the same for hand-written and generated files.
Flavors and configuration
Every app has two flavors, dev and prod, each with its own entry point (main_dev.dart, main_prod.dart), bundle id suffix and app name. The values that change between them (API keys, feature flags, useEmulator) come from a JSON file passed with --dart-define-from-file:
fvm flutter run --flavor dev -t lib/main_dev.dart --dart-define-from-file=../env.dev.json
These files are git-ignored; only an env.example.json is committed. In CI they’re rebuilt from secrets (see below). The prod build is always obfuscated with --split-debug-info, and the symbols are uploaded to Crashlytics so the stack traces stay readable.
How I ship a version
Branches
A light git-flow:
mainis what’s in the stores. I never commit on it directly.developis the integration branch.- Work happens on
feat/…orfix/…branches fromdevelop, merged with a PR. - A version goes through a
release/x.y.zbranch.
The CI runs on every merge into develop, not on every feature PR: with a single runner, I’d rather keep it free, and the release PR is where the full test suite has to pass anyway.
Start a release
melos run start-release 1.4.0
A small bash script (tool/release.sh) does what I used to do by hand and occasionally get wrong:
- creates
release/1.4.0from an up-to-datedevelop; - sets
version: 1.4.0+Nin the app’spubspec.yaml, where N is the highest build number ofdevelopandmain, plus one (the stores refuse a build number already used); - commits, pushes, and opens the PR
Release: 1.4.0tomain.
The PR runs release.yml: a version check (the branch name must match the pubspec version, and the version must have a build number) and the full CI.
Ship in one click
Shipping is a manual workflow, ship.yml: Actions → Ship → Run workflow on the release branch, with three boxes: Android, iOS, Firebase.
check version ─► tests (skipped if already green on this commit)
│
┌───────────┼──────────────┐
▼ ▼ ▼
Android bundle iOS archive firebase deploy
│ │
└─────┬─────┘
▼
both builds OK? ─► Play internal track + TestFlight
The details that make it reliable:
- Tests aren’t run twice. The workflow asks the GitHub API whether the test jobs already passed on this exact commit. If yes, it skips them; if they’re running, failed or missing, it runs them in the same run. No waiting.
- All or nothing. The store uploads wait for every requested build. If the iOS build fails, the Android bundle isn’t published either, so both stores always get the same version.
- Builds are kept per commit. The bundle and the IPA are copied to a builds folder named after the commit SHA. If an upload fails (an expired key, a store API error), Re-run failed jobs uploads the same build again instead of rebuilding it. Builds older than 30 days are pruned.
- Firebase deploy is opt-in and runs without
--force: a function removed from the code makes the deploy fail instead of silently deleting it in production.
Android goes to the internal track, iOS to TestFlight. Promoting to production is still a manual step in each console, after I’ve tested the build on a real device.
Close the release
melos run close-release 1.4.0
The script checks that every check of the PR to main is green, merges it with a merge commit, tags 1.4.0 on that merge commit, merges the release branch back into develop, deletes it, and updates my local branches. If the merge into develop conflicts, main is already released and tagged: I fix the PR and run the command again, it picks up where it stopped.
A self-hosted runner on my Mac
Every workflow runs on a self-hosted GitHub Actions runner on my own Mac, not on GitHub’s machines:
- no Actions minutes: macOS minutes are the expensive ones, and an iOS build takes a while;
- the toolchain is the one I use every day (FVM cache, Xcode, Android SDK, Firebase CLI, Java for the emulators), so a build behaves like a local build;
- iOS signing uses the certificate and profile already in my keychain. The job signs a test file first and fails in 60 seconds with a clear message if the keychain is locked, instead of hanging until the timeout.
Several apps share the same runner, which brought a few problems to solve:
- Firebase emulators use fixed ports. The emulator tests take a file lock shared by every repository, so two apps never start emulators at the same time.
- Global Dart tools differ between repositories. Each repository gets its own pub cache, so one job activating another Melos version doesn’t delete the executable another job is running.
- The runner only takes jobs when the Mac is awake, and it runs with my user’s rights. That’s fine for private repositories with one contributor; I’d never do it on a public one, where a fork’s PR could run code on my machine.
Secrets: one value per secret
The CI needs the prod config, the Android keystore, a Firebase service account, the Play Console and App Store Connect keys. Instead of storing whole files as secrets, each secret holds one value, and a script (write-secrets.sh) rebuilds the files the build needs from a list of names:
# .github/secrets/app-config: <json key>=<secret name>
apiKey=APP_API_KEY
useEmulator=APP_USE_EMULATOR
A missing secret fails the job with its name, the values are never printed, and the files are written in the runner’s temp folder or removed at the end of the job. A companion script sets the secrets from my local files, so adding a key is one command.
What I’d keep if I started again
- The same skeleton everywhere. The most valuable thing isn’t any single choice, it’s that every app makes the same ones. Switching projects costs nothing.
- Package boundaries over conventions. “The UI doesn’t call Firestore” is a rule someone breaks on a Friday evening. “The
apppackage doesn’t depend ondata” can’t be broken. Eitherinstead of exceptions. More verbose, but I haven’t had an unhandled error reach the screen since.- Melos scripts as the single entry point, used by me, by the CI and by the AI.
- A release that’s two commands and a button. I release more often since shipping stopped being a half-day of manual steps, and every version in the stores has a tag on
main.