| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A powerful Flutter code generator that creates clean architecture boilerplate following industry best practices. Generate entities, models, repositories, use cases, remote data sources, dependency injection, and state management code automatically.
Unlike common Dart generators (like freezed or json_serializable) which focus on Derived Generation (creating hidden functional artifacts you never touch), this tool is a Source-to-Source Scaffolding Factory.
We believe the value of Clean Architecture is in the separation of concerns, not the typing of boilerplate. This tool handles the typing so you can focus on the logic, and it does so without taking control away from you.
Clone the repository:
git clone https://github.com/your-username/clean_architecture_code_generator.git
cd clean_architecture_code_generatorInstall CLI globally:
cd cli
dart pub global activate --source path .Note: After activation, you can run clean_arch_cli directly from any project directory.
Initialize the tool in your target project:
cd <your_project_directory>
clean_arch_cli initOptions:
This automatically:
dev_dependencies:
build_runner: any
generators:
git:
url: https://github.com/NonymousMorlock/clean_architecture_code_generator.git
path: generators
mocktail: anyGenerate your source code:
clean_arch_cli generate [options]Options:
The generator uses the parameter names in your TBG class as the keys for JSON serialization. If your API uses specific naming conventions (like snake_case or PascalCase), you should declare the properties in your annotated class using that exact casing.
Important: When generating models, ensure the model is mapped to a feature in feature_scaffolding. See Mapping models to features.
@modelTestGen
@modelGen
@entityGen
class UserTBG {
const UserTBG({
required String id,
required String Email, // Maps to 'Email' in JSON
required String Name, // Maps to 'Name' in JSON
required Address PrimaryAddress, // Maps to 'PrimaryAddress' in JSON
required List<int> favoriteItemIds,
List<Address>? addresses,
DateTime? created_at, // Maps to 'created_at' in JSON
});
}Internal fields in the generated Entity and Model will automatically be converted to camelCase for idiomatic Dart usage, while preserving the original casing in fromMap and toMap for API compatibility.
@repoGen // Generates modifiable abstract repository
@usecaseGen // Generates modifiable use cases
@repoImplGen // Generates modifiable repository implementation
@remoteSrcGen // Generates modifiable remote data source
@adapterGen // Generates modifiable interface adapter
@usecaseTestGen // Generates modifiable use case tests
@repoImplTestGen // Generates modifiable repository tests
@remoteSrcTestGen // Generates modifiable remote data source tests
class AuthRepoTBG {
external ResultFuture<User> login({required String email, required String password});
external ResultFuture<User> register({required String email, required String password});
external ResultFuture<void> logout();
external ResultFuture<User> getCurrentUser();
}To ensure a robust and idiomatic API, the generator automatically converts Optional Positional parameters defined in your TBG blueprints into Optional Named parameters in the generated code.
Why we do this:
Example:
// Your Blueprint (AuthRepoTBG)
external ResultFuture<void> searchUser(String query, [int? limit]);
// The Scaffolded Result (AuthRepository)
ResultFuture<void> searchUser(String query, {int? limit});When you annotate a UserRepoTBG class, the generator scaffolds actual files that follow Clean Architecture conventions. Unlike other generators, you won't find the implementation logic trapped in .g.dart files; it will be in your lib/ directory, ready for you to add your business logic.
lib/src/user/ ├── data/ │ ├── datasources/ │ │ └── user_remote_data_source.dart # Modifiable HTTP/API implementation │ ├── models/ │ │ └── user_model.dart # Modifiable JSON serialization │ └── repositories/ │ └── user_repository_impl.dart # Modifiable Repository implementation ├── domain/ │ ├── entities/ │ │ └── user.dart # Modifiable Domain entity │ ├── repositories/ │ │ └── user_repository.dart # Modifiable Abstract repository │ └── usecases/ │ ├── login.dart # Modifiable Use case │ └── register.dart ├── presentation/ │ └── adapter/ │ ├── user_adapter.dart # Modifiable Adapter │ └── user_state.dart # Modifiable Adapter state ...tests as well. y'know
Think of TBG files as scaffolding instructions.
If you and the generator modify the exact same line, the tool will inject standard Git conflict markers:
<<<<<<< MINE (User Changes)
'email': map['Email'], // Your manual fix
=======
'email': map['email_address'], // New generator update
>>>>>>> THEIRS (Generator Output)To resolve: Simply use Android Studio or VS Code's built-in merge tools to pick the version you want. This ensures you are always the final authority on your codebase. If the IDE doesn't show merge options, you can manually edit the file to resolve the conflicts.
Technical Note: Our engine uses a hybrid approach for conflict resolution. If Git is detected in your environment, it leverages the native 3-way merge algorithm (git merge-file) for granular, character-level precision. If not, it falls back to a strict line-based safe merge to ensure your customizations are never lost.
When generating model tests, the generator creates JSON fixtures. Note that custom types (nested models) are skipped in the generated fixture file to keep it manageable. However, the generated test code automatically "hydrates" these fields in the setUpAll block by injecting CustomType.empty().toMap(), ensuring your serialization tests remain robust.
Create a clean_arch_config.yaml file in your project root to customize your factory:
# Multi-file output is highly recommended for the Scaffolding workflow
multi_file_output:
enabled: true # Recommended: Write to actual feature files
auto_create_targets: true # Auto-create missing filesWhen you add model TBGs with active annotations, make sure the model name is listed under the correct feature in feature_scaffolding. This keeps generation aligned with your feature folders. For example, starting from:
feature_scaffolding:
root_name: src
enabled: true
features:
auth:
methods:
- register
- login
- logout
- verify_token
entities:
- user
user:
methods:
- get_profile
- update_profile
- delete_accountIf you introduce a wishlist_item model under the product feature, update the config before generating:
feature_scaffolding:
root_name: src
enabled: true
features:
auth:
methods:
- register
- login
- logout
- verify_token
entities:
- user
user:
methods:
- get_profile
- update_profile
- delete_account
product:
entities:
- wishlist_itemThat mapping ensures the generator places the model in the intended feature structure.
Happy coding with Clean Architecture! 🚀
For more examples and updates, visit our GitHub repository.
| Back | FazBrowse Home | New Git URL |