flutter_architecture_generator 1.0.0
flutter_architecture_generator: ^1.0.0 copied to clipboard
A powerful, production-ready CLI tool to instantly scaffold professional Flutter applications following Clean Architecture principles. Supports BLoC, Riverpod, Provider, GetX, GoRouter, AutoRoute, D [...]
๐๏ธ Flutter Architecture Generator #
A powerful, production-ready CLI tool to instantly scaffold professional Flutter applications following Clean Architecture principles.
Stop wasting hours on boilerplate. Generate a complete, scalable project architecture in seconds โ with dependency injection, networking, routing, state management, theming, and tests all wired up and ready to go.
โจ Why This Tool? #
| Feature | |
|---|---|
| ๐ | Zero to Production โ Generates a complete architecture with DI, Networking, Routing, and Material 3 Theming in seconds |
| ๐งฑ | Clean Architecture โ Strictly follows Domain โ Data โ Presentation separation |
| ๐ง | Context-Aware โ Remembers your project config (state management, routing) so subsequent commands "just work" |
| โก | Auto-Wiring โ New features auto-register in your DI container and router โ no manual wiring |
| ๐จ | Premium Auth UI โ Includes polished Login & Register pages out of the box |
| ๐ฆ | Latest Packages โ All dependencies pinned to the most recent stable versions on pub.dev |
| ๐งช | Test Ready โ Generates repository tests with mock data sources for every feature |
| ๐ | Secure by Default โ .gitignore auto-generated to protect .env secrets |
๐ Table of Contents #
- Supported Features
- Package Versions
- Installation
- Quick Start
- Commands Reference
- Generated Structure
- Generated Code Examples
- How Auto-Wiring Works
- Configuration Persistence
- Post-Generation Steps
- FAQ
- Contributing
- License
๐ฏ Supported Features #
State Management #
| Option | Generated Code |
|---|---|
| BLoC | Bloc + Event + State files with Equatable, part directives |
| Riverpod | FutureProvider with proper camelCase naming |
| Provider | ChangeNotifier with loading state pattern |
| GetX | GetxController with .obs reactive variables |
Routing #
| Option | Generated Code |
|---|---|
| GoRouter | GoRouter config with GoRoute entries, auto-registration of new pages |
| AutoRoute | @AutoRouterConfig with @RoutePage() annotations, auto-registration |
| Navigator | Basic Navigator 2.0 placeholder |
Networking & Data #
| Feature | Details |
|---|---|
| Dio HTTP Client | Pre-configured with connectTimeout, receiveTimeout, LogInterceptor |
| GetIt DI | Service locator pattern with lazy singleton and factory registrations |
| Freezed Models | @freezed models with fromJson / toJson via json_serializable |
| Environment Config | .env.dev and .env.prod with flutter_dotenv |
Additional Features #
| Feature | Details |
|---|---|
| Firebase | firebase_core initialization in main.dart |
| Localization (L10n) | ARB files, l10n.yaml, flutter_localizations delegates |
| Material 3 Theming | Light + Dark theme with ColorScheme.fromSeed |
| Error Handling | Failure abstract class + ServerFailure, CacheFailure, GeneralFailure |
| Unit Tests | Repository tests with mock data sources generated per feature |
| Security | .gitignore with .env*, IDE files, and generated code exclusions |
๐ฆ Package Versions (Latest) #
All generated dependencies use the latest stable versions from pub.dev:
| Package | Version | Purpose |
|---|---|---|
dio |
^5.9.1 | HTTP networking |
get_it |
^9.2.1 | Dependency injection |
flutter_bloc |
^9.1.1 | BLoC state management |
equatable |
^2.0.8 | Value equality for BLoC states |
flutter_riverpod |
^3.2.1 | Riverpod state management |
provider |
^6.1.5 | Provider state management |
get |
^4.7.3 | GetX state management |
go_router |
^17.1.0 | Declarative routing |
auto_route |
^11.1.0 | Code-generated routing |
freezed_annotation |
^3.1.0 | Immutable models (annotations) |
json_annotation |
^4.11.0 | JSON serialization (annotations) |
flutter_dotenv |
^6.0.0 | Environment variables |
firebase_core |
^4.4.0 | Firebase initialization |
intl |
^0.20.2 | Internationalization |
build_runner |
^2.11.1 | Code generation runner |
freezed |
^3.0.6 | Immutable models (generator) |
json_serializable |
^6.13.0 | JSON serialization (generator) |
auto_route_generator |
^11.0.1 | AutoRoute code generator |
๐ Installation #
Global Activation (Recommended) #
dart pub global activate flutter_architecture_generator
This adds the flutter_arch_gen command to your PATH.
Verify Installation #
flutter_arch_gen --help
โก Quick Start #
1. Create a Flutter project #
flutter create my_awesome_app
cd my_awesome_app
2. Initialize the architecture #
flutter_arch_gen init
You'll be prompted to choose:
? Select state management: (Use arrow keys)
โฏ bloc
riverpod
provider
getx
? Select routing:
โฏ goRouter
autoRoute
navigator
? Enable localization? (Y/n)
? Enable Firebase? (y/N)
? Enable tests? (Y/n)
3. Install dependencies & generate code #
flutter pub get
dart run build_runner build --delete-conflicting-outputs
4. Run your app #
flutter run
That's it! You now have a complete Clean Architecture project with DI, routing, theming, networking, and an example auth feature โ all production-ready.
๐ Commands Reference #
flutter_arch_gen init #
Initializes the complete project architecture with interactive prompts.
flutter_arch_gen init
What it generates:
- Directory structure (
core/,features/,routes/,di/) main.dartwith initialization pipelineapp.dartwithMaterialApp.routerconfigurationinjection_container.dartwith GetIt setupapi_client.dartwith Dio configurationapp_theme.dartwith Material 3 light/dark themesapp_router.dartwith routing configurationfailures.dartwith error hierarchy.env.dev/.env.prodenvironment files.gitignorewith security exclusions- Example
authfeature with Login & Register pages - Localization files (if enabled)
- Test scaffolding (if enabled)
flutter_arch_gen feature <name> #
Generates a complete Clean Architecture feature module.
# Basic usage
flutter_arch_gen feature products
# With positional arg
flutter_arch_gen feature user_profile
# PascalCase input is auto-normalized
flutter_arch_gen feature UserProfile # โ features/user_profile/
What it generates:
features/user_profile/
โโโ data/
โ โโโ datasources/user_profile_remote_datasource.dart
โ โโโ models/user_profile_model.dart
โ โโโ repositories/user_profile_repository_impl.dart
โโโ domain/
โ โโโ entities/user_profile_entity.dart
โ โโโ repositories/user_profile_repository.dart
โ โโโ usecases/get_user_profile_usecase.dart
โโโ presentation/
โโโ bloc/ # (or riverpod/ or provider/ or getx/)
โ โโโ user_profile_bloc.dart
โ โโโ user_profile_event.dart
โ โโโ user_profile_state.dart
โโโ pages/user_profile_page.dart
โโโ widgets/
Auto-wiring:
- โ
Registers
DataSource,Repository,UseCase, andBlocininjection_container.dart - โ
Adds route + import to
app_router.dart(GoRouter or AutoRoute) - โ
Generates repository test in
test/features/user_profile/
flutter_arch_gen model <name> [-f feature] #
Generates a Freezed model with JSON serialization.
# Inside a feature
flutter_arch_gen model Product -f shop
# Standalone (in lib/core/models/)
flutter_arch_gen model AppUser
Generated code:
import 'package:freezed_annotation/freezed_annotation.dart';
part 'product.freezed.dart';
part 'product.g.dart';
@freezed
class Product with _$Product {
const factory Product({
required int id,
}) = _Product;
factory Product.fromJson(Map<String, dynamic> json) => _$ProductFromJson(json);
}
flutter_arch_gen page <name> [-f feature] #
Generates a new page with optional router auto-registration.
# Inside a feature
flutter_arch_gen page Settings -f settings
# Standalone page
flutter_arch_gen page About
Auto-wiring:
- โ
GoRouter: Adds
GoRoutewith path and import toapp_router.dart - โ
AutoRoute: Adds
@RoutePage()annotation andAutoRoute(page: ...)entry
๐ Generated Structure #
lib/
โโโ main.dart # App entry point with initialization
โโโ app.dart # MaterialApp with theme & routing
โโโ core/
โ โโโ constants/
โ โ โโโ app_constants.dart # Global constants
โ โโโ errors/
โ โ โโโ failures.dart # Failure hierarchy (Server, Cache, General)
โ โโโ network/
โ โ โโโ api_client.dart # Dio HTTP client with interceptors
โ โโโ services/ # Shared services
โ โโโ theme/
โ โ โโโ app_theme.dart # Material 3 light + dark themes
โ โโโ utils/ # Shared utilities
โโโ di/
โ โโโ injection_container.dart # GetIt DI setup (auto-updated)
โโโ features/
โ โโโ auth/ # Example auth feature
โ โโโ data/
โ โ โโโ datasources/
โ โ โโโ models/
โ โ โโโ repositories/
โ โโโ domain/
โ โ โโโ entities/
โ โ โโโ repositories/
โ โ โโโ usecases/
โ โโโ presentation/
โ โโโ bloc/ # State management (BLoC/Riverpod/etc.)
โ โโโ pages/ # Login & Register pages
โ โโโ widgets/
โโโ routes/
โ โโโ app_router.dart # GoRouter or AutoRoute config
โโโ .env.dev # Dev environment variables
โโโ .env.prod # Prod environment variables
โโโ .gitignore # Security exclusions
โโโ .flutter_arch_gen.json # Persisted project config
test/
โโโ features/
โ โโโ auth/
โ โโโ auth_repository_test.dart # Auto-generated repository test
โโโ unit/
โ โโโ sample_test.dart
โโโ widget/
โโโ integration/
๐ก Generated Code Examples #
main.dart #
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
import 'package:my_app/app.dart';
import 'package:my_app/di/injection_container.dart' as di;
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await SystemChrome.setPreferredOrientations([
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
await dotenv.load(fileName: ".env.dev");
await di.init();
runApp(const MyApp());
}
injection_container.dart (after generating features) #
import 'package:get_it/get_it.dart';
import 'package:dio/dio.dart';
import 'package:my_app/core/network/api_client.dart';
final sl = GetIt.instance;
Future<void> init() async {
// External
sl.registerLazySingleton(() => Dio());
// Core
sl.registerLazySingleton(() => ApiClient(sl()));
// Features
// Auth Feature
sl.registerLazySingleton<IAuthRemoteDataSource>(() => AuthRemoteDataSourceImpl(sl()));
sl.registerLazySingleton<IAuthRepository>(() => AuthRepositoryImpl(sl()));
sl.registerLazySingleton(() => GetAuthUseCase(sl()));
sl.registerFactory(() => AuthBloc(getAuthUseCase: sl()));
}
BLoC (auto-generated) #
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:my_app/features/auth/domain/usecases/get_auth_usecase.dart';
part 'auth_event.dart';
part 'auth_state.dart';
class AuthBloc extends Bloc<AuthEvent, AuthState> {
final GetAuthUseCase getAuthUseCase;
AuthBloc({required this.getAuthUseCase}) : super(AuthInitial()) {
on<GetAuthDataEvent>((event, emit) async {
emit(AuthLoading());
try {
final data = await getAuthUseCase();
emit(AuthLoaded(data: data.id.toString()));
} catch (e) {
emit(AuthError(message: e.toString()));
}
});
}
}
๐ How Auto-Wiring Works #
When you run flutter_arch_gen feature <name>, three things happen automatically:
1. DI Registration #
New imports and registrations are injected into injection_container.dart:
// Imports added at top
import 'package:my_app/features/products/data/datasources/products_remote_datasource.dart';
import 'package:my_app/features/products/data/repositories/products_repository_impl.dart';
// ...
// Registrations added under "// Features"
sl.registerLazySingleton<IProductsRemoteDataSource>(() => ProductsRemoteDataSourceImpl(sl()));
sl.registerLazySingleton<IProductsRepository>(() => ProductsRepositoryImpl(sl()));
sl.registerLazySingleton(() => GetProductsUseCase(sl()));
sl.registerFactory(() => ProductsBloc(getProductsUseCase: sl()));
2. Router Registration #
GoRouter:
// Import added
import 'package:my_app/features/products/presentation/pages/products_page.dart';
// Route added
GoRoute(
path: '/products',
builder: (context, state) => const ProductsPage(),
),
AutoRoute:
// Import added
import 'package:my_app/features/products/presentation/pages/products_page.dart';
// Route added
AutoRoute(page: ProductsRoute.page),
3. Test Generation #
A repository test is created at test/features/products/products_repository_test.dart with a mock data source.
๐พ Configuration Persistence #
After running init, your choices are saved in .flutter_arch_gen.json:
{
"stateManagement": "bloc",
"routing": "goRouter",
"localization": true,
"firebase": false,
"tests": true
}
All subsequent commands (feature, model, page) automatically read this config โ no need to pass flags for state management or routing every time.
๐ง Post-Generation Steps #
After running flutter_arch_gen init:
# 1. Install all dependencies
flutter pub get
# 2. Generate Freezed models and AutoRoute (if applicable)
dart run build_runner build --delete-conflicting-outputs
# 3. Configure your API base URL
# Edit .env.dev and .env.prod with your actual endpoints
# 4. Run your app
flutter run
โ FAQ #
Q: Can I use this on an existing project? #
A: Yes! Run flutter_arch_gen init in your existing Flutter project root. It will add files alongside your existing code. Existing files with the same names will be overwritten, so commit first.
Q: Does it modify my existing pubspec.yaml? #
A: Yes, it adds the required dependencies under dependencies and dev_dependencies. Existing dependencies are not overwritten โ only new ones are added.
Q: Can I generate features with different state management? #
A: The tool uses the state management from your saved config (.flutter_arch_gen.json). To change it, re-run flutter_arch_gen init or manually edit the config file.
Q: Does it support Cubit? #
A: Currently, BLoC with Bloc (event-driven) is generated. You can easily convert the generated Bloc to a Cubit since both come from flutter_bloc.
Q: What naming convention is used? #
A: All file names and directory names use snake_case. Class names use PascalCase. Variable names use camelCase. Input like UserProfile or user_profile both work correctly.
Q: Does it work on Windows? #
A: Yes! All path handling uses cross-platform normalization to ensure correct imports on Windows, macOS, and Linux.
๐ค Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License #
This project is licensed under the MIT License โ see the LICENSE file for details.
Made with โค๏ธ for the Flutter community