# zulip/zulip-flutter architecture

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

- Interactive diagram: https://gitdiagram.com/zulip/zulip-flutter
- Repository: https://github.com/zulip/zulip-flutter

## Overview

##### Main Components

a. Client-Side Components:
- Frontend Layer (Flutter UI)
- Widget Tree (lib/widgets/)
- Theme and Styling System
- Localization System (assets/l10n/)

b. Application Logic:
- State Management Layer (lib/model/)
- API Integration Layer (lib/api/)
- Local Storage Layer (SQLite)

c. Platform-Specific Components:
- Android Native Integration (android/)
- iOS Native Integration (ios/)
- Notifications System (lib/notifications/)

##### Component Relationships

**[Platform-Specific Layer]**
- ↑↓
**[Flutter UI Layer] ←→ [State Management]**
- ↑↓                     ↑↓
**[API Integration] ←→ [Local Storage]**
- ↑↓
**[Zulip Server API]**

##### Detailed Component Breakdown

- Message List View
- Navigation Components
- Profile Views
- Channel/Stream Views
- Emoji/Reaction Components

- Global Store
- Message Store
- Channel Store
- User Store
- Typing Status
- Unreads Management

- REST API Client
- Event System
- WebSocket Handling
- Authentication
- Error Handling

- SQLite Database
- Cache Management
- Message Storage
- User Data Storage

- Push Notifications
- Deep Linking
- Platform-specific Features
- Native Plugins

##### Implementation Details

Technical choices:
- Flutter Framework (main channel)
- Dart Language
- SQLite for storage
- Custom state management
- Platform-specific code organization

##### Notes Section

Annotations about:
- Server version compatibility (4.0+)
- Desktop development support
- Testing requirements
- Generated code handling

Remember to maintain an appropriate level of abstraction while still showing the key architectural decisions that make this application unique, such as its custom state management system and platform-specific integrations.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Platform
        Android["Android Native"]:::platform
        iOS["iOS Native"]:::platform
        Plugins["Plugin System"]:::platform
    end

    subgraph UI
        Widgets["Widget Tree"]:::frontend
        MessageList["Message List View"]:::frontend
        ComposeBox["Compose Box"]:::frontend
        ProfileView["Profile Views"]:::frontend
        ThemeSystem["Theme System"]:::frontend
        I18n["Internationalization"]:::frontend
    end

    subgraph State
        Store["Global Store"]:::state
        MessageStore["Message Store"]:::state
        ChannelStore["Channel Store"]:::state
        TypingStatus["Typing Status"]:::state
        UnreadsManager["Unreads Management"]:::state
    end

    subgraph API
        CoreAPI["Core API Client"]:::api
        APIModels["API Models"]:::api
        APIRoutes["API Routes"]:::api
        ErrorHandling["Exception Handling"]:::api
    end

    subgraph Storage
        SQLite[(SQLite Database)]:::storage
        DBImpl["Database Implementation"]:::storage
        GeneratedDB["Generated DB Code"]:::storage
    end

    subgraph Notifications
        NotifCore["Core Notifications"]:::notif
        PlatformNotif["Platform Notifications"]:::notif
    end

    %% Relationships
    Platform --> UI
    UI --> State
    State --> API
    API --> Storage
    API --> ZulipServer["Zulip Server API"]:::external
    Notifications --> UI

    %% UI Internal
    Widgets --> MessageList
    Widgets --> ComposeBox
    Widgets --> ProfileView
    Widgets --> ThemeSystem

    %% State Internal
    Store --> MessageStore
    Store --> ChannelStore
    Store --> TypingStatus
    Store --> UnreadsManager

    %% Storage Internal
    SQLite --> DBImpl
    DBImpl --> GeneratedDB

    %% Notifications Flow
    NotifCore --> PlatformNotif

    %% Click Events
    click Widgets "https://github.com/zulip/zulip-flutter/tree/main/lib/widgets/"
    click MessageList "https://github.com/zulip/zulip-flutter/blob/main/lib/widgets/message_list.dart"
    click ComposeBox "https://github.com/zulip/zulip-flutter/blob/main/lib/widgets/compose_box.dart"
    click ProfileView "https://github.com/zulip/zulip-flutter/blob/main/lib/widgets/profile.dart"
    click ThemeSystem "https://github.com/zulip/zulip-flutter/blob/main/lib/widgets/theme.dart"
    click Store "https://github.com/zulip/zulip-flutter/blob/main/lib/model/store.dart"
    click MessageStore "https://github.com/zulip/zulip-flutter/blob/main/lib/model/message.dart"
    click ChannelStore "https://github.com/zulip/zulip-flutter/blob/main/lib/model/channel.dart"
    click TypingStatus "https://github.com/zulip/zulip-flutter/blob/main/lib/model/typing_status.dart"
    click UnreadsManager "https://github.com/zulip/zulip-flutter/blob/main/lib/model/unreads.dart"
    click CoreAPI "https://github.com/zulip/zulip-flutter/blob/main/lib/api/core.dart"
    click APIModels "https://github.com/zulip/zulip-flutter/tree/main/lib/api/model/"
    click APIRoutes "https://github.com/zulip/zulip-flutter/tree/main/lib/api/route/"
    click ErrorHandling "https://github.com/zulip/zulip-flutter/blob/main/lib/api/exception.dart"
    click DBImpl "https://github.com/zulip/zulip-flutter/blob/main/lib/model/database.dart"
    click GeneratedDB "https://github.com/zulip/zulip-flutter/blob/main/lib/model/database.g.dart"
    click Android "https://github.com/zulip/zulip-flutter/tree/main/android/app/src/main/kotlin/com/zulip/flutter/"
    click iOS "https://github.com/zulip/zulip-flutter/tree/main/ios/Runner/"
    click Plugins "https://github.com/zulip/zulip-flutter/tree/main/packages/zulip_plugin/"
    click NotifCore "https://github.com/zulip/zulip-flutter/tree/main/lib/notifications/"
    click PlatformNotif "https://github.com/zulip/zulip-flutter/blob/main/lib/host/android_notifications.dart"
    click I18n "https://github.com/zulip/zulip-flutter/tree/main/assets/l10n/"

    %% Styling
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef state fill:#2ecc71,stroke:#27ae60,color:white
    classDef api fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef platform fill:#e74c3c,stroke:#c0392b,color:white
    classDef notif fill:#f1c40f,stroke:#f39c12,color:black
    classDef external fill:#95a5a6,stroke:#7f8c8d,color:white
```
