Community Modules
Community modules are self-contained Air Framework modules distributed via Git. They can be added to any Air project with a single command and immediately integrate with the module lifecycle, DI, and routing.
Installing a Community Module
Section titled “Installing a Community Module”# From a GitHub repositoryair module add https://github.com/user/air-analytics.git
# From a local path (useful during development)air module add /path/to/local/moduleThe CLI clones the module into lib/modules/<module-name>/ and registers it in your project. No manual wiring required.
What Happens After Install
Section titled “What Happens After Install”- The module directory is copied to
lib/modules/. - The module class is imported and registered with
ModuleManagerinmain.dart. - Its routes, services, and DI registrations are available immediately.
// main.dart — auto-generated after installawait ModuleManager().register([ AuthModule(), CatalogModule(), AnalyticsModule(), // ← auto-added by air module add]);Creating a Community Module
Section titled “Creating a Community Module”Use the CLI to scaffold a module following the community standards:
air create community-module my_feature_moduleThis generates a standalone Flutter package in the current directory:
my_feature_module/├── lib/│ └── my_feature_module/│ ├── my_feature_module.dart ← Public exports│ ├── my_feature_module_module.dart ← AppModule subclass│ ├── ui/│ │ ├── views/│ │ └── state/│ ├── services/│ └── models/├── test/│ └── my_feature_module_test.dart├── pubspec.yaml└── README.mdCommunity Module Standards
Section titled “Community Module Standards”For a module to work correctly as a community module, it must:
- Extend
AppModuleand implementid,routes,onBind, andonInit. - Declare dependencies explicitly via
AppModule.dependencies(e.g.['auth:^1.0.0']). - Not hard-code infrastructure: Use adapters (HTTP, storage) via
AirDIcontracts rather than direct Dio or SharedPreferences calls. - Include tests: At minimum, unit tests for state controllers and services.
- Document the API: A
README.mdwith installation instructions and configuration options.
Example: A Minimal Community Module
Section titled “Example: A Minimal Community Module”import 'package:air_framework/air_framework.dart';
class AirAnalyticsModule extends AppModule { @override String get id => 'analytics';
@override List<String> get dependencies => [];
@override List<AirRoute> get routes => []; // This module has no UI
@override void onBind(AirDI di) { super.onBind(di); // ⚠️ Required di.registerLazySingleton<AnalyticsService>(() => AnalyticsService()); }
@override Future<void> onInit(AirDI di) async { await super.onInit(di); // ⚠️ Required await di.get<AnalyticsService>().init(); }}Publishing to the Community
Section titled “Publishing to the Community”To share your module with the Air Framework community:
- Push the module to a public GitHub repository.
- Tag a release (e.g.
v1.0.0) following semantic versioning. - Add
air_community_moduleas a topic on GitHub so others can discover it. - Open a PR to the Air Framework community registry to get it listed in the official docs.