# mostafahamed-w/book_hunter_clean_architecture architecture

> Architecture diagram of the GitHub repository mostafahamed-w/book_hunter_clean_architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mostafahamed-w/book_hunter_clean_architecture
- Repository: https://github.com/mostafahamed-w/book_hunter_clean_architecture

## Overview

##### Main Components
- Mobile/Platform Frontends: Represent the platform-specific folders (android, ios, linux, macos, windows, web) which show that the application targets multiple platforms using a single Flutter codebase.
- Core Application Layer (Flutter Code): Focus on the “lib” directory. This contains:
a. Features (e.g., Splash, Home) which are organized using Clean Architecture layers:
- Presentation Layer: UI components, views, widgets, and state management logic (BLoC/Cubit classes) found under “lib/Features/[Feature]/presentation”.
- Domain Layer: Business entities, repositories' interfaces, and use cases (e.g., fetch_featured_books_use_case.dart) defined under “lib/Features/[Feature]/domain”.
- Data Layer: Data sources (local and remote), data models, and repository implementations located in “lib/Features/[Feature]/data”.
b. Core Utilities: The “lib/core” directory includes common utilities (like API services, error handling, service locators, custom widgets, style definitions, and helper functions) that support various parts of the app.
- External Resources: Assets such as fonts and images under the “assets” folder. The API endpoints or services (for fetching book data) can be represented as external systems interacting with the data layer.

##### Relationships and Interactions
- Presentation Layer communicates with the Domain layer by invoking Use Cases through BLoC/Cubit components.
- The Domain layer defines interfaces (repositories) that are implemented in the Data layer.
- The Data layer interacts with external data sources (both local for caching/offline access and remote APIs) to fetch and persist book data.
- Core utilities and common widgets provide shared functionality across features.
- Multiple platform-specific projects (android, ios, etc.) compile and package the Flutter code for their respective environments.

##### Architectural Patterns and Design Principles
- Clean Architecture: The separation into presentation, domain, and data layers emphasizes separation of concerns, making testing and maintenance easier.
- BLoC Pattern: Used for state management, ensuring a unidirectional data flow and clear separation between UI and business logic.
- Dependency Injection: The existence of a service locator in “lib/core/utils/service_locator.dart” indicates that dependency injection is used for managing dependencies across layers.
- Multi-platform Support: The presence of platform-specific directories shows that the Flutter project has been adapted to run on various platforms while sharing the same core logic.

##### Relevant Technologies and Frameworks
- Flutter for the UI and cross-platform development.
- Dart (the programming language used in Flutter).
- BLoC/Cubit for state management.
- Possible external APIs for fetching book data (suggested by the data sources in the home feature).
- Gradle, Xcode, and CMake for building on Android, iOS, and desktop platforms respectively.

##### Specific Elements
- Clear labels for each component: “Platform Frontends”, “Presentation Layer”, “Domain Layer”, “Data Layer”, “Core/Utilities”, “External Data Sources/APIs”, and “Assets”.
- From “Presentation” to “Domain” to indicate that the UI layer calls use cases.
- From “Domain” to “Data” to show repository delegation.

##### Putting It All Together
- The top layer: Presentation (UI screens and widgets, organized by feature such as Splash and Home) using BLoC/Cubit.
- The middle layer: Domain (use cases and business entities).
- The bottom layer: Data (repositories, data sources, models).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Book Hunter App"
        subgraph "Mobile/Platform Frontends"
            A1("Android"):::frontend
            A2("iOS"):::frontend
            A3("Linux"):::frontend
            A4("macOS"):::frontend
            A5("Windows"):::frontend
            A6("Web"):::frontend
        end

        subgraph "Flutter Code (Core Application Layer)"
            subgraph "Presentation Layer"
                P1("Splash Presentation"):::presentation
                P2("Home Presentation"):::presentation
            end
            subgraph "Domain Layer"
                D1("Home Domain"):::domain
            end
            subgraph "Data Layer"
                DT1("Home Data"):::data
            end
        end

        C("Core Utilities"):::core
        E("Assets"):::external
        R("Remote API"):::external
    end

    %% Interactions between Clean Architecture layers
    P1 -->|"callsUseCase"| D1
    P2 -->|"callsUseCase"| D1
    D1 -->|"delegatesRepo"| DT1
    DT1 -->|"fetchesData"| R

    %% Dependency Injection from Core Utilities
    C -->|"injectsDeps"| P1
    C -->|"injectsDeps"| P2
    C -->|"injectsDeps"| D1
    C -->|"injectsDeps"| DT1

    %% Optional connection to Assets for shared resources
    C -->|"providesAssets"| E

    %% Click Events for Component Mappings
    click A1 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/android"
    click A2 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/ios"
    click A3 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/linux"
    click A4 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/macos"
    click A5 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/windows"
    click A6 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/web"
    click P1 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/lib/Features/Splash/presentation"
    click P2 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/lib/Features/home/presentation"
    click D1 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/lib/Features/home/domain"
    click DT1 "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/lib/Features/home/data"
    click C "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/lib/core"
    click E "https://github.com/mostafahamed-w/book_hunter_clean_architecture/tree/main/assets"

    %% Styles
    classDef frontend fill:#add8e6,stroke:#000,stroke-width:1px;
    classDef presentation fill:#87cefa,stroke:#000,stroke-width:1px;
    classDef domain fill:#98fb98,stroke:#000,stroke-width:1px;
    classDef data fill:#ffa07a,stroke:#000,stroke-width:1px;
    classDef core fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef external fill:#f5deb3,stroke:#000,stroke-width:1px;
```
