CleanForge Bricks is a powerful Mason brick collection designed to streamline Flutter application development using Clean Architecture principles with GetX state management. This toolkit provides two main bricks: cleanforge
for project scaffolding (both new and existing projects) and cleanforge_feature
for feature generation. Currently optimized for GetX state management, with plans to support other state management solutions through community contributions.
CleanForge Bricks implements Clean Architecture in Flutter applications, promoting:
graph TD
A[Presentation Layer] --> B[Domain Layer]
A --> C[Data Layer]
B --> C
subgraph "Clean Architecture Layers"
A
B
C
end
The generated code is optimized for Flutter version 3.35.2. If you’re using a lower Flutter version, you might need to modify some syntax in the generated code to ensure compatibility. Key considerations:
For the best experience, we recommend using Flutter 3.35.2 or later. If you need to use an older version, please review the generated code and make necessary adjustments.
The project follows a modular structure with each file having a specific responsibility:
lib/
├── main.dart # Entry point of the application, configures global settings and initializes app
├── app/
│ ├── app.dart # Root widget of the application, sets up theme and initial routes
│ ├── app_binding.dart # Global dependency injection configuration
│ └── page_not_found.dart # Default 404 error page for invalid routes
├── common/
│ ├── core/
│ │ ├── theme/
│ │ │ ├── theme.dart # Global theme configuration
│ │ │ ├── theme_controller.dart # Controller file to control themes
│ │ │ └── widget_themes/ # Individual widget theme configurations
│ │ │ ├── appbar_theme.dart # AppBar specific theming
│ │ │ ├── bottom_sheet_theme.dart # BottomSheet customization
│ │ │ ├── checkbox_theme.dart # Checkbox styling
│ │ │ ├── elevated_button_theme.dart # Button theming
│ │ │ └── text_theme.dart # Typography definitions
│ │ └── utils/
│ │ ├── errors/
│ │ │ ├── exceptions.dart # Custom exception definitions
│ │ │ └── failures.dart # Error types for domain layer
│ │ ├── helpers/
│ │ │ └── helpers.dart # Utility functions and extensions
│ │ ├── logger/
│ │ │ └── app_logger.dart # Centralized logging configuration
│ │ ├── navigator_observer/
│ │ │ └── app_navigator_observer.dart # Navigation tracking and analytics
│ │ ├── type_def/
│ │ │ └── type_def.dart # Common type definitions and aliases
│ │ └── use_cases/
│ │ │ └── use_cases.dart # Base use case implementations
│ │ └── validators/
│ │ └── app_validators.dart # Base use case implementations
│ ├── resources/
│ │ ├── app_resources/
│ │ │ ├── app_colors.dart # Color palette definitions
│ │ │ ├── app_gaps.dart # Spacing and padding constants
│ │ │ ├── app_gradients.dart # Gradient style definitions
│ │ │ ├── app_sizes.dart # Size constants and breakpoints
│ │ │ ├── app_strings.dart # Localized strings and text constants
│ │ │ └── app_text_styles.dart # Text style definitions
│ │ ├── multimedia_resources/
│ │ │ ├── app_icons.dart # Icon constants and custom icons
│ │ │ └── app_images.dart # Image asset references
│ │ ├── network_resources/
│ │ │ ├── api_endpoints.dart # API endpoint definitions
│ │ │ ├── network_info/
│ │ │ │ └── network_info.dart # Network connectivity handling
│ │ │ └── rest_client/
│ │ │ └──clients/
│ │ │ │ ├──dio_client.dart # makes network requests with features like interceptors,
│ │ │ │ │ automatic response decoding, and request cancellation.
│ │ │ │ └──dio_interceptor.dart # intercept requests, responses, and errors
│ │ │ │ before handled by the Dio client or returned to your application.
│ │ │ │
│ │ │ └── rest_client.dart # Dio client configuration
│ │ └── storage_resources/
│ │ ├── local_client.dart # Local storage implementation
│ │ └── local_keys.dart # Storage key definitions
│ └── widgets/
│ └── toast_message.dart # Global toast/snackbar implementation
│ └── theme_switch_icon.dart # Global icon button widget to switch theme
├── features/
│ └── home/ # Example feature module
│ ├── data/
│ │ ├── datasources/
│ │ │ ├── local/ # Local storage implementations
│ │ │ └── remote/ # API client implementations
│ │ ├── models/
│ │ │ ├── home_model.dart # Data models for API responses
│ │ │ └── home_request_model.dart # Request payload models
│ │ └── repositories/
│ │ └── home_repository_impl.dart # Repository implementation
│ ├── domain/
│ │ ├── entities/
│ │ │ └── home_entity.dart # Business logic entities
│ │ ├── repositories/
│ │ │ └── home_repository.dart # Repository interfaces
│ │ └── usecases/
│ │ └── home_usecase.dart # Business logic use cases
│ └── presentation/
│ ├── bindings/
│ │ └── home_binding.dart # Feature-level dependency injection
│ ├── controllers/
│ │ └── home_controller.dart # GetX controllers
│ ├── pages/
│ │ └── home_page.dart # UI screens
│ ├── states/
│ │ └── home_state.dart # Feature state management
│ └── widgets/
│ └── home_widgets.dart # Feature-specific UI components
└── routes/
├── app_pages.dart # Route definitions and configurations
└── app_routes.dart # Route name constants
To use CleanForge Bricks in your project:
dart pub global activate mason_cli
mason add cleanforge
mason add cleanforge_feature
To help you get started, we maintain a fully implemented example project that demonstrates:
Check out the example project: CleanForge Example
Generate a new Flutter project with Clean Architecture and GetX:
# Interactive mode - follow the prompts
mason make cleanforge
# Or with direct arguments
mason make cleanforge --project_name my_app
mason make cleanforge --mode new_project --project_name my_awesome_app --org com.mycompany --description "My awesome Flutter app"
Note: Some IDE integrated terminals (VS Code, Android Studio) may not handle interactive prompts reliably. If the interactive prompt doesn’t work in your IDE terminal, either:
# Windows PowerShell (example)
cd path\to\your\workspace
mason make cleanforge
# Example: create a project non-interactively
mason make cleanforge --project_name my_app
# Example: create a feature non-interactively
mason make cleanforge_feature --feat auth
These alternatives ensure generation works even when interactive prompts fail.
You can easily integrate Clean Architecture with GetX in your existing Flutter project:
# Navigate to your existing project
cd my_existing_project
# Run CleanForge in interactive mode
mason make cleanforge
# Or specify project name matching your existing project
mason make cleanforge --project_name my_existing_project
This will:
Generate a new feature with all required layers:
mason make cleanforge_feature --feat user_management
CleanForge implements a three-layer Clean Architecture:
flowchart TB
subgraph Presentation Layer
UI[UI Widgets]
Controllers[Controllers]
State[State Management]
end
subgraph Domain Layer
Entities[Entities]
Repositories[Repository Interfaces]
UseCases[Use Cases]
end
subgraph Data Layer
Models[Models]
DataSources[Data Sources]
RepoImpl[Repository Implementations]
end
UI --> Controllers
Controllers --> State
Controllers --> UseCases
UseCases --> Repositories
Repositories --> Entities
RepoImpl --> Repositories
DataSources --> RepoImpl
Models --> Entities
graph LR
A[Theme] --> B[Widget Themes]
B --> C[AppBar Theme]
B --> D[Button Themes]
B --> E[Text Themes]
B --> F[Other Themes]
graph TD
A[REST Client] --> B[Network Info]
A --> C[API Endpoints]
B --> D[Connection Status]
C --> E[API Routes]
# Correct usage for new project
mason make cleanforge --project_name my_app
# Correct usage for new feature
mason make cleanforge_feature --feat auth
If you’re stuck or need inspiration:
We welcome contributions! Please read our contributing guidelines and code of conduct before submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.