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

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       │
 └────────────────────────────────────────────┘

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.

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:

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:

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:

  1. creates release/1.4.0 from an up-to-date develop;
  2. sets version: 1.4.0+N in the app’s pubspec.yaml, where N is the highest build number of develop and main, plus one (the stores refuse a build number already used);
  3. commits, pushes, and opens the PR Release: 1.4.0 to main.

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:

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:

Several apps share the same runner, which brought a few problems to solve:

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