Monorepo Toolkit
The monorepo toolkit is a collection of CLI scripts generated into your project at devtools/scripts/. These tools help you manage a large Flutter monorepo — from dependency analysis to build preparation to asset optimization.
All commands are run from your project root via melos:
melos run <command>TIP
The toolkit is generated into your project so it works in CI without requiring the Archipelago CLI at build time. You own the code and can customize it.
Detailed Guides
Each script has a dedicated guide with config formats, examples, and CI integration:
Core Scripts (Free):
- Run App — Interactive flavor and device selection
- Build Prepare — Debug/release dependency swapping
- Environment Sync — .env management across flavors
- Flavor Manager — Flavor configuration (dev/staging/production)
- Dependency Graph — Visualization and enforcement
- Dependency Manager — Centralized version management
- Workspace Setup — Workspace initialization
- App Scaffold — Add new apps to workspace
- Asset Generator — Type-safe asset enums
- UI Kit Manager — Component and theme management
Extension Scripts (Pro/Enterprise):
- Affected Packages — Git-based change detection Enterprise
- Test Coverage — Coverage pipeline with thresholds Pro
- Size Guard — File size enforcement Pro
- Asset Optimizer — SVG/PNG/JPEG optimization Pro
affected
Detect which packages changed since the last release and run targeted operations only on affected packages.
affected list
List packages affected by changes since the given ref.
melos run affected:listaffected analyze
Run static analysis only on affected packages.
melos run affected:analyzeaffected test
Run tests only on affected packages.
melos run affected:testaffected run
Run a custom melos script only on affected packages.
melos run affected:run -- <script-name>TIP
Use affected in CI to skip unchanged packages and reduce pipeline time. It compares against the merge base of your PR branch.
build-prepare
Swap debug dependencies with no-op implementations for production builds, or restore them for development.
build-prepare debug
Restore debug/development dependencies.
melos run build-prepare:debugbuild-prepare release
Swap to release (no-op) dependencies for production builds.
melos run build-prepare:releaseHow it works
Reads build_prepare.yaml at the workspace root and modifies pubspec.yaml files to swap dependency paths. Both debug and noop packages implement the same API contract, so the app compiles with either.
# build_prepare.yaml
swaps:
- package: apps/your_app
debug_dep: monitoring_impl
release_dep: monitoring_noop
dep_path: infrastructure/monitoringWARNING
Always run build-prepare:debug after a release build to restore development dependencies. The Fastlane integration handles this automatically.
coverage
Manage test coverage across the monorepo.
coverage init
Initialize coverage configuration for all packages.
melos run coverage:initcoverage run
Run tests with coverage collection.
melos run coverage:runcoverage combine
Combine coverage reports from all packages into a single report.
melos run coverage:combinecoverage check
Check that coverage meets the minimum threshold.
melos run coverage:checkKey flags:
| Flag | Description |
|---|---|
--min-coverage | Minimum coverage percentage (default: 80) |
coverage full
Run the full coverage pipeline: test, combine, and check.
melos run coverage:fullTIP
Use coverage full in CI as a single command that runs tests, combines reports, and fails the build if coverage drops below the threshold.
deps
Manage dependencies across the monorepo.
deps add
Add a dependency to one or more packages.
melos run deps:add -- <package-name> --target <target-package>deps remove
Remove a dependency from one or more packages.
melos run deps:remove -- <package-name> --target <target-package>deps internal
List all internal (workspace) dependencies for a package.
melos run deps:internal -- <package-name>deps external
List all external (pub.dev) dependencies for a package.
melos run deps:external -- <package-name>env
Manage environment variables and flavor configurations.
env init
Initialize environment configuration for the project.
melos run env:initenv add
Add a new environment variable.
melos run env:addenv sync
Sync the flavor enum with the current flavors.yaml configuration.
melos run env:syncFlavor workflow
- Define flavors in
flavors.yamlat the workspace root - Run
env:syncto generate the Dart enum - Each flavor has its own
.envfile (e.g.,.env.dev,.env.staging,.env.prod) - Environment variables are code-generated with
enviedin theapp_configpackage
flavor
Manage app flavors (variants like dev, staging, production).
flavor list-apps
List all apps in the workspace that support flavors.
melos run flavor:list-appsflavor list
List all defined flavors.
melos run flavor:listflavor add
Add a new flavor to the project.
melos run flavor:addflavor generate
Generate flavor-specific configuration files.
melos run flavor:generateflavor sync
Sync flavor definitions across all apps.
melos run flavor:syncgraph
Analyze and visualize the dependency graph of the monorepo.
graph visualize
Generate a visual dependency graph.
melos run graph:visualizegraph stats
Show dependency statistics (counts, depth, fan-in/fan-out).
melos run graph:statsgraph cycles
Detect circular dependencies in the workspace.
melos run graph:cyclesWARNING
Circular dependencies break the layered architecture. Run graph:cycles in CI to prevent them from being introduced.
graph validate
Validate the dependency graph against architecture rules (layer violations, forbidden dependencies).
melos run graph:validatesize-guard
Monitor and enforce app binary size budgets.
size-guard check
Check the app binary size against defined budgets.
melos run size-guard:checkTIP
Configure size budgets in your project config. The guard fails the build if the binary exceeds the limit, catching size regressions early.
assets
Manage and optimize image and media assets.
assets optimize
Optimize all image assets (compress PNGs, JPEGs, etc.).
melos run assets:optimizeasset-gen
Generate Dart constants for assets.
asset-gen generate
Generate type-safe asset references from files in the assets directory.
melos run asset-gen:generateExample output
// Generated — do not modify
class AppAssets {
static const String logo = 'assets/images/logo.png';
static const String onboarding1 = 'assets/images/onboarding_1.svg';
}ui-kit
Manage UI kit components in the design system package.
ui-kit list
List all registered UI kit components.
melos run ui-kit:listui-kit add
Add a new component to the UI kit.
melos run ui-kit:addui-kit remove
Remove a component from the UI kit.
melos run ui-kit:removeui-kit status
Show the status of all UI kit components (documented, tested, etc.).
melos run ui-kit:statusui-kit create
Scaffold a new UI kit package from scratch.
melos run ui-kit:createtheme-variant
Manage theme variants (light, dark, high-contrast, brand-specific themes).
melos run theme-variantworkspace
Workspace-level setup and configuration.
workspace setup
Run initial workspace setup (install dependencies, generate code, verify configuration).
melos run workspace:setupTIP
Run this after cloning the repo or when onboarding a new team member. It handles dart pub get, code generation, and environment setup in one command.
app
Manage app targets in the monorepo.
app create
Scaffold a new app target in the apps/ directory.
melos run app:createconfig
Manage project-wide configuration.
config list
List all configuration values.
melos run config:listconfig publish
Publish configuration to the workspace (syncs settings across packages).
melos run config:publishQuick Reference
| Command | Description |
|---|---|
affected:list | List changed packages |
affected:test | Test changed packages only |
build-prepare:release | Swap to release deps |
build-prepare:debug | Restore debug deps |
coverage:full | Full coverage pipeline |
graph:cycles | Detect circular deps |
graph:validate | Validate architecture rules |
workspace:setup | Initial workspace setup |
env:sync | Sync flavors |
assets:optimize | Optimize images |
asset-gen:generate | Generate asset constants |