Setting Up Core Infrastructure
What you'll learn
- Generating the core infrastructure SDK for your Flutter app
- Understanding DI setup, base patterns, and logging foundations
- Configuring the FeatureSDK and FeatureRegistry contracts
- Connecting core infrastructure to feature packages
Prerequisites
- An existing Archipelago monorepo (see Monorepo Scaffolding)
Step 1: Generate the Core Infrastructure
bash
archipelago generate core_infrastructure_packageYou will be prompted for:
- appName —
MyApp(your application name) - organization —
MyCompany(your organization name) - domain —
com(top-level domain) - prefix —
App(prefix for component naming) - isForMonorepo —
true - includeGenerated —
false(whether generated files go into git)
Or use a config file:
json
{
"appName": "MyApp",
"organization": "MyCompany",
"domain": "com",
"prefix": "App",
"isForMonorepo": true,
"includeGenerated": false
}bash
archipelago generate core_infrastructure_package --config core_config.jsonStep 2: Understand the Generated Structure
The core infrastructure provides the foundation every other package depends on:
packages/
└── core_infrastructure/
└── lib/
├── core_infrastructure.dart # Barrel exports
└── src/
├── di/
│ ├── global_di.dart # Global GetIt instance
│ └── feature_di.dart # Per-feature scoped DI
├── feature/
│ ├── feature_sdk.dart # FeatureSDK contract
│ └── feature_registry.dart # Self-registration registry
├── base/
│ ├── base_repository.dart # Repository base class
│ ├── base_usecase.dart # UseCase base class
│ └── base_exception.dart # Typed exception hierarchy
├── logging/
│ └── logger.dart # Structured logging
└── config/
└── flavor.dart # Build flavor enumStep 3: Register Features with the Registry
Every feature SDK implements FeatureSDK and self-registers:
dart
class AuthSdkImpl extends FeatureSDK {
@override
void registerDependencies() {
// Register repos, datasources, usecases
}
@override
List<RouteBase> get routes => [authRoutes];
}
// In bootstrap.dart
FeatureRegistry.register(AuthSdkImpl());
FeatureRegistry.register(PaymentSdkImpl());
FeatureRegistry.initAll(); // Calls registerDependencies on eachStep 4: Use Base Classes
The generated base classes enforce consistent patterns:
dart
class GetUserUseCase extends BaseUseCase<String, User> {
final UserRepository _repository;
GetUserUseCase(this._repository);
@override
Future<Result<User>> execute(String userId) {
return _repository.getUser(userId);
}
}Key Customization Points
| Customization | Where to Change |
|---|---|
| Add global singletons (SDKs, infra) | global_di.dart |
| Change exception hierarchy | base_exception.dart — add domain-specific errors |
| Modify base patterns | base/ — adjust repository, usecase contracts |
| Add new build flavors | flavor.dart — extend the enum |
| Configure logging output | logger.dart — adjust formatters and sinks |
Next Steps
- Scaffold a new app that uses core infrastructure
- Set up the Network SDK built on top of core
- Add utilities for common helpers