# duytq94/flutter-chat-demo architecture

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

- Interactive diagram: https://gitdiagram.com/duytq94/flutter-chat-demo
- Repository: https://github.com/duytq94/flutter-chat-demo

## Overview

##### Main Components
- Mobile Client (Flutter UI): Represented largely by the lib folder. Split this into:
- Views/UI: Pages (e.g., login, chat, home, settings, splash) and Widgets.
- State Management: Providers (AuthProvider, ChatProvider, HomeProvider, SettingProvider) coordinating user actions and state.
- Business Logic & Models: Models (user, chat messages, menu settings) that encapsulate the data and rules. Constants and utilities help standardize configuration and helper functions.

- Firebase Backend: Although not part of your codebase, Firebase is central to the architecture. Show these components:
- Authentication: Handling Google login.
- Firestore Database: Managing real-time chat messages, user information, and current session data.
- Storage/Push Notifications: For storing images and sending notifications (the README mentions extended push notifications).

- Platform-specific Integration: Because there are separate directories for iOS and Android, include native configuration layers:
- Android: Under the android/ folder, include build configurations, Gradle files, and native manifest setup.
- iOS: Under the ios/ folder, include the Xcode project, Podfile, and other configuration files.

##### Interactions and Data Flow
- Start at the UI: The Flutter client (via lib/pages and lib/widgets) interacts with the Providers.
- Providers: Manage app state and handle network calls to Firebase (send/receive messages, authenticate users).
- Firebase: Acts as the backend that receives authentication requests, processes chat messages, and sends push notifications.
- Native Platforms: Ensure that any platform-specific integrations (like push notifications or platform API special requirements) are clearly depicted, with the Android and iOS layers interfacing with the Firebase-backed Flutter client.

##### Architectural Patterns
- MVVM/MVC-Like Separation: The system separates presentation (UI), state/business logic (providers), and data (models). This structure supports scalability and easier testing.
- Provider Pattern: A clear use of Provider for state management is evident.
- External Service Integration: The Firebase services and Google Sign-In are integral to the design.

##### Technologies and Frameworks
- Flutter Framework (for UI/Client) and Dart language.
- Firebase (Authentication, Cloud Firestore, Cloud Storage, Push Notifications).
- Native build tools for Android (Gradle) and iOS (Xcode, CocoaPods).
- Third-party libraries may also be present for things like image handling, state management, etc.

##### Final Touch – Detail Orientation
- External dependencies like Google Sign-In for authentication.
- Static configuration/data like constants from the lib/constants directory which are used by the rest of the system.
- Explicitly label how each provider (auth, chat, home, setting) fits into the overall architecture and interacts with both UI and backend services.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Mobile Client"
        PAGES["Pages (UI)"]:::ui
        WIDGETS["Widgets (UI)"]:::ui
        PROVIDERS["Providers (State Management)"]:::provider
        MODELS["Models (Business Logic)"]:::model
        CONSTANTS["Constants"]:::utility
        UTILITIES["Utilities"]:::utility
    end

    subgraph "Firebase Backend"
        FIREBASE_AUTH["Firebase Auth & Firestore"]:::firebase
        FIREBASE_STORAGE["Firebase Storage & Notifications"]:::firebase
        GS_ANDROID["Google Services (Android)"]:::firebase
        GS_IOS["Google Service Info (iOS)"]:::firebase
    end

    subgraph "Native Integrations"
        ANDROID_NATIVE["Android Native"]:::native
        IOS_NATIVE["iOS Native"]:::native
    end

    %% Mobile Client UI to State Management
    PAGES -->|"actions"| PROVIDERS
    WIDGETS -->|"triggers"| PROVIDERS

    %% Providers use Business Logic and Utilities
    PROVIDERS -->|"uses"| MODELS
    PROVIDERS -->|"uses"| CONSTANTS
    PROVIDERS -->|"uses"| UTILITIES

    %% Providers interact with Firebase Backend
    PROVIDERS -->|"calls"| FIREBASE_AUTH
    PROVIDERS -->|"calls"| FIREBASE_STORAGE

    %% Firebase Backend configuration details
    FIREBASE_AUTH -->|"configures"| GS_ANDROID
    FIREBASE_AUTH -->|"configures"| GS_IOS

    %% Firebase sends realtime updates and notifications back to Providers
    FIREBASE_AUTH -->|"realtime_updates"| PROVIDERS
    FIREBASE_STORAGE -->|"notifies"| PROVIDERS

    %% Providers also engage with Native Integrations for platform-specific calls
    PROVIDERS -->|"platform_call"| ANDROID_NATIVE
    PROVIDERS -->|"platform_call"| IOS_NATIVE

    %% Click Events
    click PAGES "https://github.com/duytq94/flutter-chat-demo/tree/master/lib/pages"
    click WIDGETS "https://github.com/duytq94/flutter-chat-demo/tree/master/lib/widgets"
    click PROVIDERS "https://github.com/duytq94/flutter-chat-demo/tree/master/lib/providers"
    click MODELS "https://github.com/duytq94/flutter-chat-demo/tree/master/lib/models"
    click CONSTANTS "https://github.com/duytq94/flutter-chat-demo/tree/master/lib/constants"
    click UTILITIES "https://github.com/duytq94/flutter-chat-demo/tree/master/lib/utils"
    click GS_ANDROID "https://github.com/duytq94/flutter-chat-demo/blob/master/android/app/google-services.json"
    click GS_IOS "https://github.com/duytq94/flutter-chat-demo/blob/master/ios/Runner/GoogleService-Info.plist"
    click ANDROID_NATIVE "https://github.com/duytq94/flutter-chat-demo/tree/master/android"
    click IOS_NATIVE "https://github.com/duytq94/flutter-chat-demo/tree/master/ios"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef provider fill:#ABEBC6,stroke:#145A32,stroke-width:2px;
    classDef model fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef firebase fill:#F5B7B1,stroke:#78281F,stroke-width:2px;
    classDef native fill:#D6EAF8,stroke:#21618C,stroke-width:2px;
    classDef utility fill:#FAD7A0,stroke:#AF601A,stroke-width:2px;
```
