# thunder-app/thunder architecture

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

- Interactive diagram: https://gitdiagram.com/thunder-app/thunder
- Repository: https://github.com/thunder-app/thunder

## Overview

##### Overall Project Type and Purpose
- Thunder is a Flutter client built primarily for mobile (iOS/Android) with additional support on web, Linux, macOS, and Windows.
- Its role is to consume and display content from Lemmy instances while managing user sessions, local preferences, and caching (via Drift for SQLite).

##### Major Components
a. Platform-Specific Shells/Builds:
- These components provide the required platform wrappers and build configurations.

b. Presentation/UI Layer:
- Flutter UI layer located mostly in the “lib” directory.
- Modular structure – for example, separate feature areas such as account, comment, community, feed, post, search, settings, and notification. Each of these is organized with a “pages”, “widgets”, and often “bloc” subdirectory.
- That the UI is built using Flutter’s widget system, Material design principles, and custom theming (supported by components under lib/core/theme).

c. Business Logic / State Management Layer:
- Extensive use of the BLoC and Cubit patterns across the project (e.g., lib/account/bloc, lib/feed/bloc, lib/moderator/bloc, lib/user/bloc, etc.).

d. Data Access & Persistence Layer:
- Local database component that uses Drift (a wrapper around SQLite) as found in lib/core/database and its associated migrations, schema versions, and type converters.
- How this layer interacts with the business logic layer to cache account information, posts, favorites, settings, etc.
- To include the migration/update process (documented in the README) for schema evolution.

e. Network/API Integration:
- Although not directly visible as “network” directories, note that there are helper files (such as in lib/core/auth/helpers and lib/instance/utils) which likely manage RESTful API calls and server integrations with Lemmy.
- Directional flows for fetching posts, communities, notifications, etc. from Lemmy instances, and pushing user actions (like votes, post creation) back to the server.

f. Shared Components & Utilities:
- A component for shared utilities (lib/shared, lib/utils) responsible for common functionality such as navigation, error handling, theming, media, and language support.
- These typically intersect both the UI and business logic layers.

g. Build & Deployment Pipeline:

##### Relationships and Data Flows
- From the business logic layer, show calls to the Data Access layer (for local caching and database read/write operations) and to external API integrations (for network operations).
- Return paths where data or state updates propagate back to the UI.
- Configuration and settings flows (e.g., the theme, localization, and app settings available via lib/settings).

##### Additional Details
- Don’t overcomplicate by adding every file—focus instead on major directories and modules to provide a high-level view that still conveys the essential architecture.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Platform-Specific Shells
    subgraph "Platform-Specific Shells"
        AA("Android"):::platform
        BB("iOS"):::platform
        CC("Linux"):::platform
        DD("macOS"):::platform
        EE("Windows"):::platform
    end

    %% Presentation/UI Layer
    subgraph "Presentation/UI Layer"
        UI("Flutter UI"):::ui
        THEME("Theming"):::ui
        UI_PAGES("Pages: Account, Feed, Comment, Community, Inbox, Instance, Moderator, Modlog, Post, Search, Thunder, User"):::ui
        UI -->|"uses"| THEME
        UI -->|"contains"| UI_PAGES
    end

    %% Business Logic / State Management Layer
    subgraph "Business Logic / State Management"
        BLOC("BLoC/Cubit"):::logic
    end

    %% Data Access & Persistence Layer
    subgraph "Data Access & Persistence"
        DB("Drift Local Database"):::data
    end

    %% Network/API Integration
    subgraph "Network/API Integration"
        NET("API Manager"):::network
    end

    %% Shared Components & Utilities
    subgraph "Shared Components & Utilities"
        SHARED("Shared & Utility Widgets"):::shared
    end

    %% Build & Deployment Pipeline
    subgraph "Build & Deployment Pipeline"
        BUILD("CI/CD & Build Scripts"):::build
    end

    %% Interactions / Data Flows
    UI -->|"triggers"| BLOC
    BLOC -->|"reads/writes"| DB
    BLOC -->|"calls"| NET
    BLOC -->|"utilizes"| SHARED
    UI -->|"accesses"| SHARED
    DB -- "updates" --> BLOC
    NET -- "responses" --> BLOC
    BLOC -- "state updates" --> UI

    %% Platform Hosting Relationships
    AA -->|"hosts"| UI
    BB -->|"hosts"| UI
    CC -->|"hosts"| UI
    DD -->|"hosts"| UI
    EE -->|"hosts"| UI

    %% Deployment Arrows
    BUILD -->|"deploys to"| AA
    BUILD -->|"deploys to"| BB
    BUILD -->|"deploys to"| CC
    BUILD -->|"deploys to"| DD
    BUILD -->|"deploys to"| EE

    %% Click Events for Component Mapping
    click AA "https://github.com/thunder-app/thunder/tree/develop/android/"
    click BB "https://github.com/thunder-app/thunder/tree/develop/ios/"
    click CC "https://github.com/thunder-app/thunder/tree/develop/linux/"
    click DD "https://github.com/thunder-app/thunder/tree/develop/macos/"
    click EE "https://github.com/thunder-app/thunder/tree/develop/windows/"
    click BUILD "https://github.com/thunder-app/thunder/tree/develop/docker/"
    click BUILD "https://github.com/thunder-app/thunder/tree/develop/.github/workflows/"
    click BUILD "https://github.com/thunder-app/thunder/tree/develop/fastlane/"
    click BUILD "https://github.com/thunder-app/thunder/tree/develop/scripts/"
    click UI "https://github.com/thunder-app/thunder/tree/develop/lib/"
    click THEME "https://github.com/thunder-app/thunder/tree/develop/lib/core/theme/"
    click BLOC "https://github.com/thunder-app/thunder/tree/develop/lib/account/bloc"
    click DB "https://github.com/thunder-app/thunder/tree/develop/lib/core/database/"
    click NET "https://github.com/thunder-app/thunder/blob/develop/lib/core/auth/helpers/fetch_account.dart"
    click SHARED "https://github.com/thunder-app/thunder/tree/develop/lib/shared/"
    click SHARED "https://github.com/thunder-app/thunder/tree/develop/lib/utils/"

    %% Styles
    classDef platform fill:#b3e5fc,stroke:#0288d1,stroke-width:2px;
    classDef ui fill:#c8e6c9,stroke:#388e3c,stroke-width:2px;
    classDef logic fill:#fff9c4,stroke:#fbc02d,stroke-width:2px;
    classDef data fill:#ffe0b2,stroke:#f57c00,stroke-width:2px;
    classDef network fill:#d1c4e9,stroke:#673ab7,stroke-width:2px;
    classDef shared fill:#f8bbd0,stroke:#c2185b,stroke-width:2px;
    classDef build fill:#d7ccc8,stroke:#5d4037,stroke-width:2px;
```
