flutter_archgen
flutter_archgen is a Dart CLI package that scaffolds a production-minded Flutter architecture with:
app,core,shared, and placeholderfeatureslayersflutter_riverpod,get_it, andinjectablesetup- an always-on
dionetworking stack - optional Firebase, Crashlytics, Sentry, notifications, Hive, SQLite, device info, Shorebird, and Fastlane modules
- generator-owned file markers so reruns stay predictable
What It Generates
Inside the target Flutter app, the generator creates or updates:
lib/main.dartlib/app/**lib/core/**lib/shared/**lib/features/README.mdtest/architecture_smoke_test.dartbuild.yamlanalysis_options.yaml- the target app
pubspec.yaml - a generated README section if the app README already exists
sentry.properties.examplewhen Sentry is enabledtool/release/shorebird/**andshorebird.yaml.examplewhen Shorebird is enabledfastlane/**andGemfilewhen Fastlane is enabled
The generated app includes:
- startup bootstrap and environment loading
- feature-safe placeholder routing
AppEnv, flavors, and compile-time configget_it+injectabledependency wiring- a reusable Dio HTTP client with auth, logging, retry hooks, validation, and error mapping
- shared preferences and secure storage services
- optional Firebase bootstrap, Crashlytics, Sentry, notifications, Hive, SQLite, device info, Shorebird, and Fastlane release scaffolding
Install
Add the package to a Flutter app:
dev_dependencies:
flutter_archgen: ^0.1.0
Then run:
flutter pub get
dart run flutter_archgen:init --app-name MyApp
You can also use the command-runner entrypoint:
dart run flutter_archgen init --app-name MyApp
Basic Usage
Generate the default architecture:
dart run flutter_archgen:init --app-name Orbit
Generate with common optional modules:
dart run flutter_archgen:init \
--app-name Orbit \
--org com.example.orbit \
--flavors dev,staging,prod \
--firebase \
--crashlytics \
--sentry \
--remote-config \
--notifications \
--device-info \
--hive \
--sqlite \
--shorebird \
--fastlane
Flags
| Flag | Purpose |
|---|---|
--app-name |
Sets the generated default app name used by AppEnv. |
--org |
Reserved for future platform tooling helpers. |
--flavors |
Comma-separated flavor names. Use lowercase letters, numbers, and underscores only. |
--firebase |
Adds Firebase core wrappers and dependencies. |
--crashlytics |
Adds Firebase Crashlytics dependencies and bootstrap hooks. Implies Firebase support. |
--sentry |
Adds Sentry monitoring services, env hooks, and sentry.properties.example. |
--remote-config |
Adds Firebase Remote Config service generation. Implies Firebase support. |
--notifications |
Adds local notification scaffolding and optional Firebase messaging dependency when Firebase is enabled. |
--device-info |
Adds a device info service scaffold. |
--hive |
Adds Hive cache service generation with CRUD helpers. |
--sqlite |
Adds SQLite database service generation with CRUD helpers. |
--shorebird |
Adds Shorebird release setup docs and template config files. |
--fastlane |
Adds Fastlane automation scaffolding with a Gemfile, Appfile, and Fastfile. |
--force |
Overwrites user-owned files in addition to generator-owned files. |
--skip-pub-get |
Skips the reminder to run flutter pub get after generation. |
--target-dir |
Generates into a specific Flutter app directory. Defaults to the current directory. |
Generator Rules
- The target must be a Flutter app with
dependencies.flutter.sdk: flutter. - Flavor names are validated before generation to avoid invalid Dart enums.
- Files marked
Generated by flutter_archgen.are safe to refresh on reruns. - User-owned files are not overwritten unless
--forceis used. - The Dio networking layer is always generated because the scaffold depends on it.
Recommended Workflow After Generation
Run these commands inside the generated Flutter app:
flutter pub get
dart run build_runner build
flutter analyze
Then replace the placeholder routes and add your feature modules.
Firebase Setup
If you enabled --firebase, --remote-config, or --crashlytics:
- Add the app to Firebase.
- Run
flutterfire configurefrom the generated Flutter app. - Add the generated Firebase config files for each supported platform.
- If you enabled Crashlytics, rerun
flutterfire configureafter adding Crashlytics so platform setup stays in sync. - If you want to use
DefaultFirebaseOptions.currentPlatform, wire that into bootstrap afterflutterfire configuregeneratesfirebase_options.dart.
Shorebird Setup
When --shorebird is enabled, the generated app adds:
tool/release/shorebird/README.mdshorebird.yaml.example
To finish setup:
- Install the Shorebird CLI.
- Run
shorebird init. - Copy placeholder values from
shorebird.yaml.exampleinto your real Shorebird config. - Run the generated Shorebird commands with your release flavor, usually
prod.
Fastlane Setup
When --fastlane is enabled, the generated app adds:
Gemfilefastlane/Appfilefastlane/Fastfilefastlane/README.md
To finish setup:
- Install Ruby and Bundler.
- Run
bundle install. - Fill in real identifiers and team settings in
fastlane/Appfile. - Store upload credentials in CI environment variables rather than the repository.
Crashlytics Setup
When --crashlytics is enabled, the generated app:
- initializes Firebase before
runApp - enables Crashlytics collection through
AppEnv - records framework and platform-level uncaught errors
- sets basic custom keys like app name and flavor
You still need to complete Firebase platform configuration in the actual app for Crashlytics to report correctly.
Sentry Setup
When --sentry is enabled, the generated app:
- initializes Sentry early in bootstrap
- wires
SentryNavigatorObserverintoMaterialApp - forwards breadcrumbs and monitored exceptions through the shared monitor abstraction
- adds
sentry.properties.example
To finish setup in the generated app:
- Set
SENTRY_DSNthrough--dart-defineor your build system. - Copy
sentry.properties.exampletosentry.properties. - Fill in your real Sentry org, project, and auth token.
- Run
dart run sentry_dart_pluginafter release builds if you use Sentry symbol upload automation.
Environment Variables in Generated Apps
The generated app reads compile-time values such as:
APP_NAMEFLAVORAPI_BASE_URLCONNECT_TIMEOUT_MSRECEIVE_TIMEOUT_MSSEND_TIMEOUT_MSENABLE_VERBOSE_LOGSENABLE_SENTRYENABLE_CRASHLYTICSSENTRY_DSNSENTRY_TRACES_SAMPLE_RATE
Example:
flutter run \
--dart-define=APP_NAME=Orbit \
--dart-define=FLAVOR=dev \
--dart-define=API_BASE_URL=https://api.example.com \
--dart-define=ENABLE_SENTRY=true \
--dart-define=SENTRY_DSN=https://examplePublicKey@o0.ingest.sentry.io/0
Development
dart pub get --no-example
dart test
dart analyze
Notes on Robustness
The generator has been tuned to avoid a few common failure modes:
- invalid flavor names are rejected before files are written
- generation aborts early for non-Flutter targets
- optional modules only inject their imports and registrations when enabled
- generated device info and multipart helpers avoid
dart:ioassumptions where possible for better cross-platform safety - reruns are safe for generator-owned files and conservative for user-owned files