How devmuaz/flutter-clean-architecture works
This project is a Flutter mobile application built using a Clean Architecture approach. The core objective is to separate concerns by dividing the app into distinct layers—Presentation, Domain, and Data—which makes the codebase easier to maintain, test, and extend.
Main Components
• Mobile Platforms: Represent the platform-specific layers (Android and iOS) as the underlying runtime environments where the Flutter app is deployed.
• Presentation Layer: This is found under the lib/src/presentation directory. It includes the UI components (views and widgets) and state management (cubits in the cubits subfolder). This layer is responsible for handling user interactions.
• Domain Layer: Located in lib/src/domain, this layer contains the core business models, request/response models, and repository interface definitions that represent the business logic.
• Data Layer: Located in lib/src/data, this layer comprises:
• Data Sources: Separated into local (using a SQLite-like database system with generated code, like in app_database.dart and its converters/DAOs), and remote data sources (defined in news_api_service files which interface with external APIs).
• Repository Implementations: Found in data/repositories. They provide concrete implementations that satisfy the interfaces defined in the Domain.
• Configuration and Dependency Injection: Components such as the configuration settings (router settings in lib/src/config/router and theme settings in lib/src/config/themes) and the dependency injection setup (locator.dart) are vital for wiring the layers together.
Relationships and Interactions
• The Flutter UI (Presentation layer) communicates with cubits (state management components) to handle events.
• Cubits interact with the Domain layer via repository interfaces. This ensures business logic isn’t coupled to specific data implementations.
• The Domain layer passes the requests to the Data layer’s repositories, which in turn access remote APIs (through news_api_service) or local databases (through app_database and its associated components).
• The Data layer provides the retrieved or processed data back up the chain.
• Dependency Injection (via locator.dart) ensures that the correct repository implementations and other dependencies are provided at runtime.
Architectural Patterns and Design Principles
• Clean Architecture: Strict separation into Presentation, Domain, and Data layers.
• Dependency Inversion: The Domain layer defines interfaces that the Data layer implements.
• State Management with Cubits: Controllers for managing UI state and business events.
• Separation of Concerns: Configuration, theming, and routing are kept in dedicated config folders.
Relevant Technologies, Frameworks, and Libraries
• Flutter: The core framework for building the UI.
• Dart: Programming language used for the app.
• State Management: Cubits (from the presentation layer).
• Local Database: Utilizes code generation for app_database (as seen with app_database.g.dart), possibly using a package like Floor or Moor.
• Remote API Services: Implemented in the news_api_service files with generated code (news_api_service.g.dart).
• Dependency Injection: Set up in locator.dart.
• Mobile-specific Build Systems: Android and iOS directories contain platform-specific configuration and build files.