# getdutchie/brick architecture

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

- Interactive diagram: https://gitdiagram.com/getdutchie/brick
- Repository: https://github.com/getdutchie/brick

## Overview

##### Project Type and Purpose
- This is a data persistence and synchronization framework for Dart applications.
- It provides an extensible query interface that abstracts multiple data providers (REST, GraphQL, Supabase, SQLite) with offline-first functionality.
- Its “repository” pattern centralizes data operations and automatically generates code for (de)serialization, migrations, and offline queueing.

##### And Separate Primary Components
a. Client Application / Business Logic:
– Represents the application’s usage of Brick. (For example, models marked with “.model.dart” and repository usage in the example.)
– The application calls the repository to fetch or mutate models.
b. Repository Layer:
– Central component (e.g., the OfflineFirstWithRestRepository and similar ones for GraphQL and Supabase) that provides a unified API for the client.
– Responsible for coordinating between local data (SQLite, memory/cache) and remote providers (REST, GraphQL, Supabase).
c. Data Providers:
– REST Provider (handled by brick_rest and its generators)
– SQLite Provider (brick_sqlite and its migration files, memory cache, etc.)
– GraphQL Provider (brick_graphql, with generated code and associated builders)
– Supabase Provider (brick_supabase with similar patterns)
d. Offline Queue Management:
– For handling offline mutations. For instance, components like RestRequestSqliteCacheManager in brick_offline_first_with_rest, or similar components in GraphQL/Supabase builds.
e. Code Generation and Build Tools:
– Libraries like brick_build, brick_graphql_generators, brick_sqlite_generators, etc.
– These take the annotated models and generate (de)serialization and migration code.
f. Core Logic and DSL:
– Central modeling concepts provided by brick_core (query DSL, base model classes, and annotations).

##### Illustrating Relationships and Data Flows
– The local SQLite provider, responsible for caching and offline data storage.
– The remote provider (REST, GraphQL, or Supabase) for online data access.
– An offline queue manager that buffers mutations when offline and synchronizes later.
- Code generation component as a supporting process that automatically generates adapters, migrations, and serialization code feeding into each provider.

##### Architectural Patterns
- The Repository Pattern – to centralize data access, abstraction of persistence implementations.
- Offline-first Pattern – local caching, offline request queuing, and automatic sync strategies.
- Code Generation and Migrations – these are handled by distinct build packages (brick_build, brick_offline_first_build, etc.) that tie into build_runner to produce adapters and schemas.

– Off to the side (or at the bottom), include the code generation/build module that feeds into the provider implementations.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Application Layer"
        Client["Client Application / Business Logic"]:::client
    end
    
    subgraph "Repository Layer"
        Repo["Repository Layer"]:::repository
    end
    
    subgraph "Data Providers"
        RestProvider["REST Provider"]:::provider
        SqliteProvider["SQLite Provider"]:::provider
        GraphQLProvider["GraphQL Provider"]:::provider
        SupabaseProvider["Supabase Provider"]:::provider
    end

    subgraph "Offline Management"
        OfflineQ["Offline Queue Manager"]:::offline
    end

    subgraph "Supporting Tools"
        CodeGen["Code Generation & Build Tools"]:::build
        CoreDSL["Core Logic & DSL"]:::core
    end

    Client -->|"calls"| Repo
    Repo -->|"local_cache"| SqliteProvider
    Repo -->|"remote_sync"| RestProvider
    Repo -->|"remote_sync"| GraphQLProvider
    Repo -->|"remote_sync"| SupabaseProvider
    Repo -->|"buffers"| OfflineQ

    CodeGen -.->|"generates_adapters"| RestProvider
    CodeGen -.->|"generates_adapters"| SqliteProvider
    CodeGen -.->|"generates_adapters"| GraphQLProvider
    CodeGen -.->|"generates_adapters"| SupabaseProvider

    CoreDSL -->|"defines_models"| Repo

    %% Click Events for Client Application (Models and Repositories)
    click Client "https://github.com/getdutchie/brick/tree/main/example_graphql/lib/brick/models"
    click Client "https://github.com/getdutchie/brick/tree/main/example_rest/lib/brick/models"
    click Client "https://github.com/getdutchie/brick/tree/main/example_supabase/lib/brick/models"
    click Repo "https://github.com/getdutchie/brick/blob/main/example_graphql/lib/repository.dart"
    click Repo "https://github.com/getdutchie/brick/blob/main/example_rest/lib/brick/repository.dart"
    click Repo "https://github.com/getdutchie/brick/blob/main/example_supabase/lib/brick/repository.dart"

    %% Click Events for Data Providers (Core Provider Code and Generators)
    click RestProvider "https://github.com/getdutchie/brick/blob/main/packages/brick_rest/lib/brick_rest.dart"
    click RestProvider "https://github.com/getdutchie/brick/tree/main/packages/brick_rest_generators"
    click SqliteProvider "https://github.com/getdutchie/brick/blob/main/packages/brick_sqlite/lib/brick_sqlite.dart"
    click SqliteProvider "https://github.com/getdutchie/brick/tree/main/packages/brick_sqlite_generators"
    click GraphQLProvider "https://github.com/getdutchie/brick/blob/main/packages/brick_graphql/lib/brick_graphql.dart"
    click GraphQLProvider "https://github.com/getdutchie/brick/tree/main/packages/brick_graphql_generators"
    click SupabaseProvider "https://github.com/getdutchie/brick/blob/main/packages/brick_supabase/lib/brick_supabase.dart"
    click SupabaseProvider "https://github.com/getdutchie/brick/tree/main/packages/brick_supabase_generators"
    
    %% Click Events for Offline Queue Management
    click OfflineQ "https://github.com/getdutchie/brick/blob/main/packages/brick_offline_first/lib/offline_queue.dart"
    click OfflineQ "https://github.com/getdutchie/brick/blob/main/packages/brick_offline_first_with_rest/lib/src/offline_queue/rest_request_sqlite_cache_manager.dart"
    click OfflineQ "https://github.com/getdutchie/brick/blob/main/packages/brick_offline_first_with_graphql/lib/src/graphql_request_sqlite_cache_manager.dart"
    
    %% Click Events for Code Generation & Build Tools
    click CodeGen "https://github.com/getdutchie/brick/blob/main/packages/brick_build/lib/builders.dart"
    click CodeGen "https://github.com/getdutchie/brick/tree/main/packages/brick_offline_first_build"
    click CodeGen "https://github.com/getdutchie/brick/tree/main/packages/brick_offline_first_with_rest_build"
    click CodeGen "https://github.com/getdutchie/brick/tree/main/packages/brick_offline_first_with_graphql_build"
    click CodeGen "https://github.com/getdutchie/brick/tree/main/packages/brick_offline_first_with_supabase_build"

    %% Click Event for Core Logic & DSL
    click CoreDSL "https://github.com/getdutchie/brick/blob/main/packages/brick_core/lib/core.dart"

    %% Styles
    classDef client fill:#ffde59,stroke:#333,stroke-width:2px;
    classDef repository fill:#ff9a76,stroke:#333,stroke-width:2px;
    classDef provider fill:#a0e7e5,stroke:#333,stroke-width:2px;
    classDef offline fill:#b4f8c8,stroke:#333,stroke-width:2px;
    classDef build fill:#f1a9a0,stroke:#333,stroke-width:2px;
    classDef core fill:#caffbf,stroke:#333,stroke-width:2px;
```
