# アーキテクチャ構成図

## システム全体構成図

```mermaid
graph TB
    subgraph "Mobile App (Flutter)"
        subgraph "Presentation Layer"
            UI[Screens / Widgets]
        end

        subgraph "Application Layer"
            BLoC[BLoC Components]
            Event[Events]
            State[States]
        end

        subgraph "Domain Layer"
            RepoInterface[Repository Interfaces]
        end

        subgraph "Data Layer"
            RepoImpl[Repository Implementations]
            ApiClient[API Client]
            GraphQL[GraphQL Client]
            Mutations[Mutations / Queries]
        end

        subgraph "Infrastructure Layer"
            SharedPref[SharedPreferenceHelper]
            Hive[(Hive Storage)]
            GetStorage[(GetStorage)]
            FCM[Firebase Cloud Messaging]
            Notifications[Local Notifications]
        end
    end

    subgraph "External Services"
        Backend[Bagisto Backend<br/>GraphQL API]
        Firebase[Firebase Services]
        PayPal[PayPal API]
        GoogleMaps[Google Maps API]
    end

    UI --> BLoC
    BLoC --> Event
    BLoC --> State
    State --> UI
    BLoC --> RepoInterface
    RepoInterface --> RepoImpl
    RepoImpl --> ApiClient
    ApiClient --> GraphQL
    GraphQL --> Mutations
    Mutations --> Backend

    SharedPref --> GetStorage
    GraphQL --> Hive
    FCM --> Firebase
    Notifications --> UI
```

## レイヤー構成図

```mermaid
graph TD
    subgraph "Presentation Layer"
        direction LR
        Screen[Screen Widget]
        ViewWidget[View Widgets]
        CommonWidget[Common Widgets]
    end

    subgraph "Application Layer (BLoC)"
        direction LR
        Bloc[BLoC Class]
        EventClass[Event Classes]
        StateClass[State Classes]
    end

    subgraph "Domain Layer"
        direction LR
        RepoAbstract[Repository<br/>Abstract Class]
    end

    subgraph "Data Layer"
        direction LR
        RepoConc[Repository<br/>Implementation]
        API[ApiClient]
        GraphQLClient[GraphQlApiCalling]
    end

    subgraph "Infrastructure Layer"
        direction LR
        Storage[Storage Services]
        Push[Push Notifications]
        Auth[Auth Link]
    end

    Screen -->|"BlocProvider"| Bloc
    Screen -->|"BlocBuilder"| StateClass
    ViewWidget --> Screen
    CommonWidget --> ViewWidget

    Bloc -->|"calls"| RepoAbstract
    Bloc -->|"emits"| StateClass
    EventClass -->|"triggers"| Bloc

    RepoAbstract -.->|"implements"| RepoConc
    RepoConc -->|"calls"| API
    API -->|"uses"| GraphQLClient

    GraphQLClient -->|"uses"| Auth
    GraphQLClient -->|"caches to"| Storage
    Push -->|"delivers to"| Screen
```

## BLoCパターン データフロー図

```mermaid
sequenceDiagram
    participant User
    participant Widget as Screen Widget
    participant Bloc as BLoC
    participant Repo as Repository
    participant API as ApiClient
    participant GQL as GraphQL Server

    User->>Widget: User Action (tap button)
    Widget->>Bloc: add(Event)
    Bloc->>Bloc: mapEventToState()
    Bloc->>Repo: callMethod()
    Repo->>API: apiMethod()
    API->>GQL: GraphQL Query/Mutation
    GQL-->>API: Response
    API-->>Repo: Parsed Model
    Repo-->>Bloc: Data Model
    Bloc->>Bloc: emit(NewState)
    Bloc-->>Widget: State Update
    Widget-->>User: UI Update
```

## 画面別モジュール構成図

```mermaid
graph LR
    subgraph "Screen Module Structure"
        direction TB
        ScreenDir[screens/home_page/]

        subgraph "BLoC Layer"
            bloc_dir[bloc/]
            home_bloc[home_page_bloc.dart]
            home_event[home_page_event.dart]
            home_state[home_page_state.dart]
            home_repo[home_page_repository.dart]
        end

        subgraph "View Layer"
            view_dir[view/ or root]
            home_page[home_page.dart]
        end

        subgraph "Widget Layer"
            widget_dir[widget/]
            carousel[carousal_slider.dart]
            banner[details_banner.dart]
            product_view[new_product_view.dart]
        end

        subgraph "Utils Layer"
            utils_dir[utils/]
            index[index.dart]
            helper[route_argument_helper.dart]
        end

        subgraph "Data Model Layer"
            data_dir[data_model/]
            theme_model[theme_customization.dart]
            product_model[new_product_data.dart]
        end
    end

    ScreenDir --> bloc_dir
    ScreenDir --> view_dir
    ScreenDir --> widget_dir
    ScreenDir --> utils_dir
    ScreenDir --> data_dir

    bloc_dir --> home_bloc
    bloc_dir --> home_event
    bloc_dir --> home_state
    bloc_dir --> home_repo

    view_dir --> home_page

    widget_dir --> carousel
    widget_dir --> banner
    widget_dir --> product_view

    utils_dir --> index
    utils_dir --> helper

    data_dir --> theme_model
    data_dir --> product_model
```

## 外部連携構成図

```mermaid
graph TB
    subgraph "Flutter Mobile App"
        App[Bagisto Mobile App]
        GQLClient[GraphQL Client]
        FCMClient[FCM Client]
        PayPalSDK[PayPal SDK]
        MapsSDK[Google Maps SDK]
    end

    subgraph "Backend Services"
        Bagisto[Bagisto Laravel Backend]
        GraphQLEndpoint["/graphql Endpoint"]
        HeadlessAPI[Headless eCommerce API]
    end

    subgraph "Firebase Services"
        FCM[Firebase Cloud Messaging]
        Analytics[Firebase Analytics]
    end

    subgraph "Payment Services"
        PayPalAPI[PayPal API]
    end

    subgraph "Google Services"
        Maps[Google Maps Platform]
        Geocoding[Geocoding API]
    end

    App --> GQLClient
    GQLClient --> GraphQLEndpoint
    GraphQLEndpoint --> Bagisto
    Bagisto --> HeadlessAPI

    App --> FCMClient
    FCMClient --> FCM

    App --> PayPalSDK
    PayPalSDK --> PayPalAPI

    App --> MapsSDK
    MapsSDK --> Maps
    MapsSDK --> Geocoding
```

## データ永続化構成図

```mermaid
graph TD
    subgraph "Application"
        App[Flutter App]
        SharedPrefHelper[SharedPreferenceHelper]
        HiveAdapter[Hive Adapters]
        GraphQLCache[GraphQL Cache]
    end

    subgraph "Local Storage"
        GetStorageBox[(GetStorage<br/>configurationStorage)]
        HiveBox[(Hive Box<br/>GraphQL Cache)]
    end

    subgraph "Stored Data"
        subgraph "GetStorage Contents"
            Token[Customer Token]
            UserInfo[User Info]
            Settings[App Settings]
            Currency[Currency/Language]
            Theme[Theme Preference]
        end

        subgraph "Hive Contents"
            Products[NewProductsModel]
            Categories[HomeCategoriesData]
            Reviews[Reviews Data]
            GQLResponses[GraphQL Responses]
        end
    end

    App --> SharedPrefHelper
    SharedPrefHelper --> GetStorageBox
    GetStorageBox --> Token
    GetStorageBox --> UserInfo
    GetStorageBox --> Settings
    GetStorageBox --> Currency
    GetStorageBox --> Theme

    App --> HiveAdapter
    App --> GraphQLCache
    HiveAdapter --> HiveBox
    GraphQLCache --> HiveBox
    HiveBox --> Products
    HiveBox --> Categories
    HiveBox --> Reviews
    HiveBox --> GQLResponses
```

## 認証フロー図

```mermaid
sequenceDiagram
    participant User
    participant SignInScreen
    participant SignInBloc
    participant SignInRepo
    participant ApiClient
    participant GraphQL
    participant SharedPref

    User->>SignInScreen: Enter credentials
    SignInScreen->>SignInBloc: add(SignInEvent)
    SignInBloc->>SignInRepo: getSignInData(email, password)
    SignInRepo->>ApiClient: getSignInData()
    ApiClient->>GraphQL: customerLogin mutation
    GraphQL-->>ApiClient: SignInModel (token, user data)
    ApiClient-->>SignInRepo: SignInModel
    SignInRepo-->>SignInBloc: SignInModel

    alt Login Success
        SignInBloc->>SharedPref: setCustomerToken(token)
        SignInBloc->>SharedPref: setCustomerLoggedIn(true)
        SignInBloc->>SharedPref: setCustomerDetails(data)
        SignInBloc-->>SignInScreen: emit(SignInSuccess)
        SignInScreen-->>User: Navigate to Home
    else Login Failure
        SignInBloc-->>SignInScreen: emit(SignInFailed)
        SignInScreen-->>User: Show Error Message
    end
```

## プッシュ通知フロー図

```mermaid
sequenceDiagram
    participant FCM as Firebase Cloud Messaging
    participant PushManager as PushNotificationsManager
    participant LocalNotif as FlutterLocalNotifications
    participant App as Flutter App
    participant User

    Note over FCM,User: App Foreground
    FCM->>PushManager: onMessage (RemoteMessage)
    PushManager->>PushManager: Parse notification data
    PushManager->>LocalNotif: showNotification()
    LocalNotif->>User: Display system notification

    Note over FCM,User: App Background/Terminated
    FCM->>PushManager: onBackgroundMessage()
    PushManager->>PushManager: Handle in background

    Note over FCM,User: User taps notification
    User->>LocalNotif: Tap notification
    LocalNotif->>PushManager: onDidReceiveNotificationResponse
    PushManager->>App: Navigate to relevant screen
```

## 依存関係グラフ

```mermaid
graph BT
    subgraph "Core Dependencies"
        Flutter[flutter]
        FlutterBloc[flutter_bloc]
        Provider[provider]
        GraphQLFlutter[graphql_flutter]
    end

    subgraph "Data & Storage"
        Hive[hive]
        GetStorage[get_storage]
        JsonAnnotation[json_annotation]
    end

    subgraph "Network"
        Dio[dio]
        Retrofit[retrofit]
        Http[http]
    end

    subgraph "Firebase"
        FirebaseCore[firebase_core]
        FirebaseMessaging[firebase_messaging]
        LocalNotifications[flutter_local_notifications]
    end

    subgraph "UI Components"
        CarouselSlider[carousel_slider]
        CachedImage[cached_network_image]
        Lottie[lottie]
        GoogleFonts[google_fonts]
    end

    subgraph "Platform Integration"
        PayPal[flutter_paypal_payment]
        GoogleMaps[google_maps_flutter]
        Location[location]
        LocalAuth[local_auth]
    end

    App[Bagisto Mobile App]

    App --> Flutter
    App --> FlutterBloc
    App --> Provider
    App --> GraphQLFlutter
    App --> Hive
    App --> GetStorage
    App --> FirebaseCore
    App --> FirebaseMessaging
    App --> PayPal
    App --> GoogleMaps

    GraphQLFlutter --> Hive
    FlutterBloc --> Provider
    FirebaseMessaging --> FirebaseCore
```
