How nanosoftonline/clean-flutter works
Project Type and Purpose
• This is a mobile CRM application built in Flutter.
• It implements Clean Architecture to keep business logic (Domain and Use Cases) independent from technical details (UI, data sources, and external APIs).
Main Components
• Presentation Layer (UI):
• Found under the “lib/presentation” directory.
• Contains view files (e.g., views for customers and tasks), view models (with corresponding test files), and shared UI components.
• This layer interacts with the user, and it is where Flutter widgets, screens, and state management live.
• Domain Layer (Business Logic):
• Located in “lib/domain”.
• Contains the core models (like Customer and Task), repository interfaces, and use cases (for customer, lead, and task operations).
• This layer defines the business rules and workflows (use cases like create, update, delete, etc.).
• Data Layer:
• Placed under “lib/data”.
• Implements the actual data handling logic by providing concrete implementations for the interfaces defined in the domain layer (API data sources here such as customer_datasource_impl.dart and task_datasource_impl.dart).
• Contains entity mappers if needed (e.g., converting API responses to domain models).
• Core Layer:
• In “lib/core”.
• Defines cross-cutting concerns such as error handling and failure classes using the functional programming style (for example, the Failure class).
• Platforms/Infrastructure:
• All the Flutter platform-specific folders (android, ios, macos, web, windows, linux) represent the external environment where the application is deployed.
• They house all the native configurations and build settings necessary to run the same Flutter code on different platforms.
• External Dependencies:
• Notably declared in pubspec.yaml, including packages such as Equatable, Dio, dartz, UUID, and others.
• These can be noted as external libraries that enable parts of the application (e.g., network communication, unique id generation, and functional programming support).
Relationships and Data Flow
• The UI (Presentation Layer) interacts with View Models, which in turn invoke the appropriate Use Cases from the Domain Layer.
• The Use Cases call on Repository interfaces to either fetch or mutate data.
• The concrete implementations of these repositories are in the Data Layer, which bridges the business logic and the external data sources (for example, REST APIs).
• Failures (errors) are propagated back, using functional constructs (like Either from dartz) so that the UI can respond appropriately.
• The Clean Architecture layering ensures that the Domain Layer remains independent of the Data and Presentation layers.
Architectural Patterns and Design Principles
• Use of Clean Architecture (dependency inversion, separation of concerns) ensures that the domain models and use cases are at the center of the application.
• The data flow is unidirectional: from the Presentation Layer to the Domain, and then the Data Layer provides outputs.
• The repository pattern is used to abstract away the details of data sources.
• The functional programming approach, in part enabled by dartz, ensures that side effects and failures are handled in a controlled way.