Clean Architecture
Note: Clean Architecture is one of the supported patterns in easy_init_cli.
easy_init_cli implements Clean Architecture, separating code into three main layers: Data, Domain, and Presentation. This ensures independence, scalability, and testability.
Feature-Wise Separation
The architecture organizes code by features rather than technical layers. Each feature is a self-contained module with its own data, domain, and presentation layers.
Advantages
- Modularity: Features are independent and can be developed, tested, and maintained in isolation
- Scalability: Easy to add new features without affecting existing ones
- Team Collaboration: Multiple developers can work on different features simultaneously without conflicts
- Code Reusability: Shared utilities and widgets are placed in
common/for cross-feature use - Maintainability: Changes to one feature don't ripple through the entire codebase
- Testability: Each feature can be unit tested independently with clear boundaries
Project Structure
lib/
├── app.dart # Main application widget
├── app_runner.dart # Application runner configuration
├── main.dart # Application entry point
├── common/ # Reusable components, utilities, and shared logic
│ └── widgets/ # Common UI components
├── core/ # Core functionalities and cross-cutting concerns
│ ├── api_endpoints/ # API endpoint definitions
│ ├── base_usecase/ # Base use case definitions
│ ├── config/ # Application configuration
│ ├── dependency_injection/ # Dependency injection setup
│ ├── extensions/ # Dart extensions
│ ├── failures/ # Custom failure classes
│ ├── network/ # Network client and handling
│ ├── routes/ # Application routing definitions
│ ├── services/ # Core services
│ └── theme/ # Application theme and colors
└── features/ # Feature-specific modules
└── <feature_name>/
├── data/ # Data layer
│ ├── data_sources/ # Remote and local data sources
│ ├── models/ # Data transfer objects (DTOs)
│ └── repositories_impl/ # Repository implementations
├── domain/ # Domain layer
│ ├── entities/ # Core business entities
│ ├── repositories/ # Repository interfaces
│ └── usecases/ # Business logic (use cases)
└── presentation/ # Presentation layer
├── blocs/ # BLoC for state management
├── screens/ # Screens/Pages
└── widgets/ # Feature-specific UI components
AI Documentation
The project includes an /ai_docs folder in the root directory containing curated guidelines for AI-assisted development:
api_flow_guide.md- Comprehensive guide on API call flow, error handling patterns, and network layer best practicesstyling_guide.md- Styling conventions, theme usage, widget patterns, and UI consistency guidelines
These guides enable vibe coding - AI-powered development that maintains consistency with your project's architecture and conventions. When using AI assistants, reference these documents to ensure generated code follows your established patterns.
Resources
For a deep dive into this architecture, we recommend Reso Coder's Flutter Clean Architecture Course.
Note: A "Number Trivia" feature is generated by default to demonstrate the architecture's flow. You can use this as a reference or remove it when you start building your core features.
Core Packages
The Clean Architecture implementation uses the following packages to maintain separation of concerns and efficient state management:
Dependencies
dartz- Functional programming for error handling with Either typeflutter_bloc- BLoC pattern implementation for state managementinjectable- Code generation for dependency injection setupfreezed_annotation- Annotations for generating immutable models and unionsget_it- Service locator for dependency injectiondio- HTTP client for API requestsintl- Internationalization and localization supportgo_router- Declarative routing solution
Dev Dependencies
build_runner- Code generation tool runnerfreezed- Code generator for immutable classes and unionsinjectable_generator- Code generator for injectable dependency injectionmocktail- Mocking library for unit tests
These packages work together to provide:
- Dependency Injection:
get_itandinjectablehandle service registration and retrieval - State Management:
flutter_blocmanages application state with events and states - Error Handling:
dartzprovides functional Either types for clean error handling - Data Models:
freezedgenerates immutable entities and models with copyWith, equality, and toString - Networking:
dioprovides a robust HTTP client with interceptors - Routing:
go_routerenables type-safe, declarative navigation - Testing:
mocktailallows easy mocking for unit tests