# mainawycliffe/graphql_flutter_bloc_example architecture

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

- Interactive diagram: https://gitdiagram.com/mainawycliffe/graphql_flutter_bloc_example
- Repository: https://github.com/mainawycliffe/graphql_flutter_bloc_example

## Overview

##### Project type and purpose
- This is a Flutter mobile-app example (Android & iOS) demonstrating how to integrate the GitHub GraphQL API with Flutter using the `graphql` client library and `flutter_bloc` for state management.
- The app’s purpose is to fetch a user’s repositories, display them, and provide star/unstar functionality via GraphQL queries and mutations.

##### File structure
- Top-level Flutter platform folders: `android/` and `ios/` (native project files, build scripts, manifests, xcworkspace, Gradle wrappers).
- The core app lives in `lib/`:
- `main.dart` – app entry point; initializes GraphQL client and BlocProviders.
- `blocs/repos/` – business-logic components: events, states, and the `MyReposBloc`.
- `graphql_operation/queries` and `graphql_operation/mutations` – GraphQL documents for reading repos and (un)starring.
- `repository.dart` – a wrapper that uses the GraphQL client to execute operations and convert raw responses into models.
- There’s no custom backend code—only an external dependency on GitHub’s GraphQL API.

##### README for additional insights
- Requires a `local.dart` in `lib/` exporting your GitHub personal access token constant.
- Confirms use of `graphql` (core GraphQL client) and `flutter_bloc` for separation of UI and business logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Presentation Layer"
        UI["UI Widgets & App Entry Point"]:::ui
    end

    subgraph "State Management Layer"
        Events["Bloc Events"]:::bloc
        States["Bloc States"]:::bloc
        Models["Bloc Models"]:::bloc
        Bloc["MyReposBloc"]:::bloc
    end

    subgraph "Data Layer"
        Repo["Repository"]:::data
    end

    subgraph "Network Layer"
        Client["GraphQL Client"]:::network
        subgraph "GraphQL Documents"
            Q["readRepositories Query"]:::network
            M1["addStar Mutation"]:::network
            M2["removeStar Mutation"]:::network
            M3["Combined Mutations"]:::network
        end
    end

    External["GitHub GraphQL API"]:::external

    UI -->|"dispatch event"| Bloc
    Bloc -->|"call repository"| Repo
    Repo -->|"use documents"| Q
    Repo -->|"use documents"| M1
    Repo -->|"use documents"| M2
    Repo -->|"use documents"| M3
    Repo -->|"execute operation"| Client
    Client -->|"HTTP request/response"| External

    External -->|"response"| Client
    Client -->|"return data"| Repo
    Repo -->|"emit state"| Bloc
    Bloc -->|"update UI"| UI

    click UI "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/main.dart"
    click Bloc "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/blocs/repos/my_repos_bloc.dart"
    click Events "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/blocs/repos/events.dart"
    click States "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/blocs/repos/states.dart"
    click Models "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/blocs/repos/models.dart"
    click Repo "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/repository.dart"
    click Q "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/graphql_operation/queries/readRepositories.dart"
    click M1 "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/graphql_operation/mutations/addStar.dart"
    click M2 "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/graphql_operation/mutations/removeStar.dart"
    click M3 "https://github.com/mainawycliffe/graphql_flutter_bloc_example/blob/master/lib/graphql_operation/mutations/mutations.dart"

    classDef ui fill:#cce5ff,stroke:#004085,color:#004085,stroke-width:2px;
    classDef bloc fill:#d4edda,stroke:#155724,color:#155724,stroke-width:2px,shape:hexagon;
    classDef data fill:#fff3cd,stroke:#856404,color:#856404,stroke-width:2px,shape:parallelogram;
    classDef network fill:#f5c6cb,stroke:#721c24,color:#721c24,stroke-width:2px;
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d,stroke-width:2px;
```
