lib/
│
├── core/
│ ├── base/
│ │ ├── base_usecase.dart
│ │ └── base_viewmodel.dart
│ ├── di/
│ │ └── dependency_injection.dart
│ ├── service/
│ │ ├── local/
│ │ │ └── app_prefs.dart
│ │ └── remote/
│ │ ├── api_service.dart
│ │ ├── dio_factory.dart
│ │ ├── error_handler.dart
│ │ ├── failure.dart
│ │ └── network_info.dart
│ ├── utils/
│ ├── extensions.dart
│ └── functions.dart
│
├── data/
│ ├── data_source/
│ │ ├── local_data_source.dart
│ │ └── remote_data_source.dart
│ ├── mapper/
│ │ └── mapper.dart
│ ├── repository/
│ │ └── repository_imp.dart
│ ├── response/
│ ├── login_response.dart
│ └── other_response_files.dart
│
├── domain/
│ ├── models/
│ │ ├── user_model.dart
│ │ └── other_model_files.dart
│ ├── repository/
│ │ └── repository.dart
│ ├── request/
│ │ ├── login_request.dart
│ │ └── other_request_files.dart
│ ├── usecase/
│ ├── login_usecase.dart
│ └── other_usecase_files.dart
│
├── presentation/
│ ├── resources/
│ │ ├── assets_manager.dart
│ │ ├── color_manager.dart
│ │ ├── constants_manager.dart
│ │ ├── routes_manager.dart
│ │ └── other_resource_files.dart
│ ├── views/
│ │ ├── screen_folder/
│ │ │ ├── screen1.dart
│ │ │ ├── screen2.dart
│ │ │ └── other_screens.dart
│ │ └── other_view_files.dart
│ ├── widgets/
│ ├── component1.dart
│ ├── component2.dart
│ └── other_components.dart
│
└── main.dart
Core
The core
directory contains foundational components and services that are essential across the entire application. It helps maintain a clean separation between the app's infrastructure and business logic.
- base/
- base_usecase.dart: A base class for use cases, providing a template for executing business logic in a structured way.
- base_viewmodel.dart: A base class for ViewModels, containing common logic and properties that all ViewModels will inherit.
- di/
- dependency_injection.dart: This file sets up dependency injection across the app, using a service locator like
GetIt
. All dependencies, such as ViewModels, repositories, and services, are registered here.
- service/
- local/:
- app_prefs.dart: Manages shared preferences or local storage, handling user settings, authentication tokens, and other persistent data.
- remote/:
- api_service.dart: Defines the API service using Retrofit and Dio, managing the HTTP client and endpoint definitions.
- dio_factory.dart: Configures Dio, setting up the HTTP client with options like timeouts, base URL, and interceptors.
- error_handler.dart: Handles errors related to network requests, converting Dio errors into more manageable forms within the app.
- failure.dart: Defines failure models used across the app to represent different error states (e.g., network failure, server failure).
- network_info.dart: A utility for checking the network status, determining if the device is connected to the internet.
- utils/
- extensions.dart: Provides extension methods, adding utility functions to existing classes or data types.
- functions.dart: Contains helper functions used throughout the app, promoting code reuse and reducing duplication.
Data
The data
directory is responsible for data handling, including fetching, caching, and mapping data between the API and the domain layer. It separates concerns related to how data is retrieved and processed.
- data_source/:
- local_data_source.dart: Manages data retrieval and storage from local sources, such as SQLite or SharedPreferences.
- remote_data_source.dart: Handles data fetching from remote sources, such as REST APIs, utilizing the Retrofit and Dio setup.
- mapper/:
- mapper.dart: Contains mapping logic, converting data between API response models and domain models. This ensures that the app's core logic works with consistent and simplified data structures.
- repository/:
- repository_imp.dart: Implements the repository interfaces defined in the domain layer, combining data from local and remote sources, and applying business logic where necessary.
- response/:
- login_response.dart and other files: These are data models that represent the structure of the API responses. They map the JSON responses directly to Dart objects, which are then used in the app.
Domain
The domain
directory contains the core business logic of the app. It includes models, repository interfaces, request models, and use cases that define how data should be manipulated and what operations should be performed.
- models/:
- user_model.dart and other files: Core data models used throughout the app. These models represent the structure of data that the business logic and UI will work with, independent of where the data comes from.
- repository/:
- repository.dart: Defines the interfaces for repositories. These interfaces are implemented in the data layer and are used by the use cases to interact with data sources.
- request/:
- login_request.dart and other files: Models that represent the structure of requests made to the API. These are used to send data to the server, such as in login operations.
- usecase/:
- login_usecase.dart and other files: Encapsulates business logic related to specific features, such as logging in a user or fetching user details. Use cases interact with repositories to retrieve or update data.
Presentation
The presentation
directory handles everything related to the UI. It contains resources, views (screens), and widgets that define how the app looks and how users interact with it.
- resources/:
- assets_manager.dart: Manages the paths to asset files (e.g., images, fonts) used in the app.
- color_manager.dart: Centralizes the color definitions for the app, ensuring a consistent color scheme.
- constants_manager.dart: Stores constant values used throughout the app, such as API endpoints, keys, and fixed strings.
- routes_manager.dart: Manages the routing in the app, defining how navigation is handled between different screens.
- views/:
- screen_folder/: Each screen or feature of the app gets its own folder within
views
. For example:
- login_view.dart: Defines the UI and behavior for the login screen.
- user_view.dart: Handles the display of user-related information.
- Additional screens would follow a similar pattern.
- These screens interact with their corresponding ViewModels, observing state changes and updating the UI accordingly.
- widgets/:
- component1.dart, component2.dart: Reusable UI components that can be used across multiple screens, such as custom buttons, text fields, or dialogs. These components are designed to be modular and easily configurable.