# mrhgj/fluttergithub architecture

> Architecture diagram of the GitHub repository mrhgj/fluttergithub, 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/mrhgj/fluttergithub
- Repository: https://github.com/mrhgj/fluttergithub

## Overview

##### Main Components
- Mobile Client (Flutter App): Represent the overall Flutter app that spans both Android (android directory) and iOS (ios directory) native projects.
- UI Layer: Under “lib/routes”, “lib/widgets”, and “lib/res” are the various UI screens (login, home, search, repo detail, personal detail, etc.), custom widgets, and styling resources.
- State Management Layer: “lib/states” and “lib/common/event” are used for shared application state (using provider and event_bus) to manage theme, user profile, and locale settings.
- Business Logic / Networking: “lib/common/net” encapsulates API requests (using dio) with files like NetApi.dart and api.dart. This layer handles interactions with the external GitHub API.
- Data / Model Layer: “lib/models” and accompanying generated files (with .g.dart) hold the data representations for repositories, users, commits, events, etc.
- Local Persistence: “lib/db” for SQLite database management via “sqflite” to store history or cache data.
- Internationalization: “lib/l10n” and “l10n-arb” provide localization resources.
- Third Party Integrations: Various libraries such as cached_network_image, flutter_markdown, and webview_flutter form key external integrations.

##### Relationships and Interactions
- The UI Layer (screens & widgets) interacts with the State Management Layer to reflect changes in theme, locale, and user data.
- UI interacts with the Business Logic layer to fetch data from the GitHub API. Data is passed to/from the Model Layer.
- The Network layer uses API endpoints (requiring GitHub OAuth credentials provided in the “ignore.dart” file) to request data.
- Data fetched from the API can be persisted locally in the Database Layer.
- Event communication (via event_bus) connects disparate parts (like notifying UI updates upon state changes).
- The Internationalization and Theme components tie into the global configurations maintained in the State and Common layers.

##### Architectural Patterns and Design Principles
- MVVM/MVC-like segregations: While not a strict framework, the separation between UI (Routes and Widgets), business logic (States and Common Logic), and data (Models and Database) is a key pattern.
- Layered Architecture: Clear division from presentation (UI) down through domain logic to data and network.
- Dependency Injection / State Management: Use of provider for managing shared states.
- Reusability and Modularity: “lib/common”, “lib/widgets”, and “lib/routes” suggest a modular design with separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Client (Flutter App)
    subgraph "Mobile Client (Flutter App)"
        Android["Android Native"]:::mobile
        IOS["iOS Native"]:::mobile
    end

    %% UI Layer
    subgraph "UI Layer"
        UIScreens["UI Screens"]:::ui
        CustomWidgets["Custom Widgets"]:::ui
        StylingResources["Styling Resources"]:::ui
    end

    %% State Management Layer
    subgraph "State Management Layer"
        GlobalState["Global State & Providers"]:::state
        EventBus["Event Bus"]:::state
    end

    %% Business Logic / Networking
    subgraph "Business Logic / Networking"
        APIClients["API Clients"]:::logic
        GlobalConfig["Global Configurations"]:::logic
    end

    %% Data / Model Layer
    subgraph "Data / Model Layer"
        DataModels["Data Models"]:::data
    end

    %% Local Persistence
    subgraph "Local Persistence"
        SQLiteDB["SQLite DB Management"]:::db
    end

    %% Internationalization & Localization
    subgraph "Internationalization & Localization"
        LocalizationRes["Localization Resources"]:::intl
        ARBFiles["ARB Files"]:::intl
    end

    %% Interconnections
    Android -->|"LoadsUI"| UIScreens
    IOS -->|"LoadsUI"| UIScreens

    UIScreens -->|"StateUpdate"| GlobalState
    GlobalState -->|"UpdateUI"| UIScreens
    CustomWidgets -->|"TriggerEvent"| EventBus

    GlobalState -->|"APIRequest"| APIClients
    GlobalConfig -->|"Configures"| APIClients
    APIClients -->|"ReturnsData"| DataModels
    DataModels -->|"Persist/Retrieve"| SQLiteDB

    UIScreens -->|"LocalizedText"| LocalizationRes

    %% Styling Classes
    classDef mobile fill:#FDEBD0,stroke:#E67E22,stroke-width:2px;
    classDef ui fill:#AED6F1,stroke:#2980B9,stroke-width:2px;
    classDef state fill:#C3E6CB,stroke:#28A745,stroke-width:2px;
    classDef logic fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef data fill:#D7BDE2,stroke:#8E44AD,stroke-width:2px;
    classDef db fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef intl fill:#D6DBDF,stroke:#7F8C8D,stroke-width:2px;

    %% Click Events
    click Android "https://github.com/mrhgj/fluttergithub/tree/master/android/"
    click IOS "https://github.com/mrhgj/fluttergithub/tree/master/ios/"
    click UIScreens "https://github.com/mrhgj/fluttergithub/tree/master/lib/routes/"
    click CustomWidgets "https://github.com/mrhgj/fluttergithub/tree/master/lib/widgets/"
    click StylingResources "https://github.com/mrhgj/fluttergithub/tree/master/lib/res/"
    click GlobalState "https://github.com/mrhgj/fluttergithub/tree/master/lib/states/"
    click EventBus "https://github.com/mrhgj/fluttergithub/blob/master/lib/common/event/event_bus.dart"
    click APIClients "https://github.com/mrhgj/fluttergithub/tree/master/lib/common/net/"
    click GlobalConfig "https://github.com/mrhgj/fluttergithub/blob/master/lib/common/Global.dart"
    click DataModels "https://github.com/mrhgj/fluttergithub/tree/master/lib/models/"
    click SQLiteDB "https://github.com/mrhgj/fluttergithub/tree/master/lib/db/"
    click LocalizationRes "https://github.com/mrhgj/fluttergithub/tree/master/lib/l10n/"
    click ARBFiles "https://github.com/mrhgj/fluttergithub/tree/master/l10n-arb/"
```
