How getdutchie/brick works
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.