# abdulrahmanhatem911/clean_code_test architecture

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

- Interactive diagram: https://gitdiagram.com/abdulrahmanhatem911/clean_code_test
- Repository: https://github.com/abdulrahmanhatem911/clean_code_test

## Overview

##### Project type and purpose
- This is a cross-platform Flutter mobile (and desktop/web) application.
- It follows a “clean architecture” style, structuring code into layers: core, features, data/domain/presentation, and uses state management (Cubit), DI (service_locator), network (Dio) + local caching.

##### File structure
- Top level:
– android / ios / linux / macos / windows / web: platform‐specific runners & configs
– lib: actual Dart code, broken into:
· config (routes, styling, theming)
· core (exports, network helpers, local server stub, translation, utilities, widgets)
· features/posts & features/saved (each: data, domain, presentation)
· services (app observer, cache helper, service locator)
· main.dart / post_app.dart (app bootstrap)
- pubspec.yaml + analysis_options.yaml: dependency and lint config
- test/widget_test.dart: basic widget test

##### README for additional insights
- A boilerplate Flutter project, no custom architecture doc in README
- Clearest clues about architecture come from file naming and structure

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        AllPostsScreen["AllPostsScreen"]:::presentation
        PostDetailsScreen["PostDetailsScreen"]:::presentation
        PostItemWidget["PostItemWidget"]:::presentation
        PostsCubit["PostsCubit"]:::presentation
        PostsState["PostsState"]:::presentation
        SavedCubit["SavedCubit"]:::presentation
        SavedState["SavedState"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer" 
        direction TB
        PostEntity["PostEntity"]:::domain
        GetAllPosts["GetAllPosts UseCase"]:::domain
        PostsRepositoryInterface["PostsRepository Interface"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        PostsModel["PostsModel"]:::data
        PostsRemoteDS["PostsRemoteDataSource"]:::data
        PostLocalDS["PostLocalDataSource"]:::data
        PostRepositoryImpl["PostRepositoryImpl"]:::data
    end

    %% Core Services
    subgraph "Core Services"
        direction TB
        ApiConstant["ApiConstant"]:::core
        DioHelper["DioHelper"]:::core
        DioInterceptor["DioInterceptor"]:::core
        ErrorHandler["ErrorHandler"]:::core
        Logger["Logger"]:::core
        NetworkInfo["NetworkInfo"]:::core
        LocalServer["LocalServer Stub"]:::core
        ServiceLocator["ServiceLocator"]:::core
        CacheHelper["CacheHelper"]:::core
        AppObserver["AppObserver"]:::core
    end

    %% External
    subgraph "External Dependencies"
        direction TB
        RESTAPI["REST API Endpoint"]:::external
        LocalStorage["Local Storage (SharedPreferences)"]:::external
    end

    %% Platform Runners
    subgraph "Platform Runners"
        direction TB
        Android["android/"]:::platform
        iOS["ios/"]:::platform
        Web["web/"]:::platform
        Linux["linux/"]:::platform
        MacOS["macos/"]:::platform
        Windows["windows/"]:::platform
    end

    %% Flow Arrows
    AllPostsScreen -->|interacts with| PostsCubit
    PostDetailsScreen -->|interacts with| PostsCubit
    PostsCubit -->|emits state| PostsState
    SavedCubit -->|emits state| SavedState
    PostsCubit -->|calls| GetAllPosts
    SavedCubit -->|calls| GetAllPosts
    GetAllPosts -->|uses| PostsRepositoryInterface
    PostsRepositoryInterface -->|bound to| PostRepositoryImpl
    PostRepositoryImpl -->|uses| PostsRemoteDS
    PostRepositoryImpl -->|uses| PostLocalDS
    PostsRemoteDS -->|checks| NetworkInfo
    PostsRemoteDS -->|http via| DioHelper
    DioHelper -->|configured by| ApiConstant
    DioHelper -->|intercepts via| DioInterceptor
    DioHelper -->|errors handled by| ErrorHandler
    DioHelper -->|logs via| Logger
    PostLocalDS -->|caches via| CacheHelper
    PostLocalDS -->|fallback stub| LocalServer
    ServiceLocator -->|wires| PostRepositoryImpl
    ServiceLocator -->|provides| DioHelper
    ServiceLocator -->|provides| NetworkInfo
    ServiceLocator -->|provides| CacheHelper
    ServiceLocator -->|provides| AppObserver

    RESTAPI -->|served by| PostsRemoteDS
    LocalStorage -->|served by| PostLocalDS

    PostRepositoryImpl -->|returns Future<List<PostEntity>>| GetAllPosts
    GetAllPosts -->|emits Future<List<PostEntity>>| PostsCubit
    PostsState -->|renders| AllPostsScreen

    %% Platform embedding
    mainApp["Flutter Engine\n(main.dart -> post_app.dart)"]:::bootstrap
    mainApp -->|runs on| Android
    mainApp -->|runs on| iOS
    mainApp -->|runs on| Web
    mainApp -->|runs on| Linux
    mainApp -->|runs on| MacOS
    mainApp -->|runs on| Windows
    mainApp -->|initializes| ServiceLocator
    mainApp -->|observes| AppObserver

    %% Click Events
    click AllPostsScreen "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/presentation/screens/all_posts_screen.dart"
    click PostDetailsScreen "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/presentation/screens/post_details_screen.dart"
    click PostItemWidget "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/presentation/widgets/post_item_widget.dart"
    click PostsCubit "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/presentation/cubit/posts_cubit.dart"
    click PostsState "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/presentation/cubit/posts_state.dart"
    click SavedCubit "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/saved/presentation/cubit/saved_cubit.dart"
    click SavedState "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/saved/presentation/cubit/saved_state.dart"
    click PostEntity "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/domain/entities/posts_entity.dart"
    click GetAllPosts "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/domain/usecases/get_all_posts.dart"
    click PostsRepositoryInterface "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/domain/repositories/posts_repository.dart"
    click PostsModel "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/data/models/posts_model.dart"
    click PostsRemoteDS "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/data/datasources/posts_remote_data_source.dart"
    click PostLocalDS "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/data/datasources/post_local_data_source.dart"
    click PostRepositoryImpl "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/features/posts/data/repositories/post_repository_impl.dart"
    click ApiConstant "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/api/api_constant.dart"
    click DioHelper "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/api/dio_helper.dart"
    click DioInterceptor "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/api/dio_intercepter.dart"
    click ErrorHandler "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/api/error_handler.dart"
    click Logger "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/api/logger.dart"
    click NetworkInfo "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/api/netowork_info.dart"
    click LocalServer "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/core/network/local/local_server.dart"
    click ServiceLocator "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/services/service_locator.dart"
    click CacheHelper "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/services/cache_helper.dart"
    click AppObserver "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/services/app_abserver.dart"
    click mainApp "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/main.dart"
    click mainApp "https://github.com/abdulrahmanhatem911/clean_code_test/blob/main/lib/post_app.dart"

    %% Styles
    classDef presentation fill:#D0E8FF,stroke:#005B9F,stroke-width:1px
    classDef domain fill:#E2F7D4,stroke:#2E7D32,stroke-width:1px
    classDef data fill:#FFE2B4,stroke:#EF6C00,stroke-width:1px
    classDef core fill:#E0E0E0,stroke:#424242,stroke-width:1px
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:1px
    classDef bootstrap fill:#F3E5F5,stroke:#6A1B9A,stroke-width:1px
    classDef platform fill:#FFF9C4,stroke:#F9A825,stroke-width:1px
```
