# victormanuelfrancodev/supabase_carshop architecture

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

- Interactive diagram: https://gitdiagram.com/victormanuelfrancodev/supabase_carshop
- Repository: https://github.com/victormanuelfrancodev/supabase_carshop

## Overview

Based on our analysis of the file tree and README, this is a Flutter-based mobile (and multi-platform) application that demonstrates a clean architecture approach for a simulated car shop. The app’s primary goal is to showcase how Supabase SQL functions drive backend logic (for purchases, stock updates, and user points) while leveraging Flutter for the frontend.

##### Main Components
- Presentation Layer: This includes the Flutter screens (pages like home_page, car_shop_page, payment_page) and state management (the InheritedWidget and various notifiers such as BuyNotifier, ProductsNotifier, and UserCarProductsNotifier).
- Domain Layer: Represent the entities (e.g., the Product entity), business logic, and use cases that manage the app’s purchase process and cart logic. This is located in lib/domain.
- Data Layer: Show how the repositories, data sources, and models (e.g., shop_element_datasource.dart, product_model.dart) work to interface with the backend. Highlight the repository abstraction (cart_shop_repository) and its implementation.

##### Relationships and Data Flow
- From the UI (Presentation Layer), user actions (e.g., placing an order) are sent to state notifiers.
- The notifiers trigger operations defined in the Domain layer to manage application logic.
- The Domain layer calls into the Repository interfaces within the Data layer.
- The Repository makes API calls (or uses Supabase-specific SDKs) to interact with the external Supabase backend.
- Supabase processes the SQL functions and updates its database tables accordingly.
- Results flow back into the Flutter app to update the UI state (using the InheritedWidget to propagate changes).

##### Architectural Patterns and Design Principles
- Use the Clean Architecture pattern – separate your application into Core (abstract definitions and error/model handling), Data, Domain, and Presentation layers.
- Interaction with external systems separately, showing a clear boundary between the internal business logic and the external API (Supabase).
- State management strategy, which centrally relies on InheritedWidgets, ensuring that the UI updates correctly when backend data changes.

##### Technologies, Frameworks, and Libraries
- Flutter is the framework for the UI, targeting multiple platforms (Android, iOS, web, desktop).
- Supabase acts as the backend and data store, using SQL functions for transactional activities.
- Use of configuration management via an .env file (with SUPABASE_URL and SUPABASE_KEY) should also be highlighted.
- Any packages like the env package are directly related to configuration and security, ensuring safe management of API keys.

- Presentation Layer: Include pages (home, car shop, payment) and state management (notifiers and InheritedWidget).
- Domain Layer: Include business logic for purchase operations.
- Data Layer: Include repository interfaces, datasource classes, and model conversions.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Flutter App"
        UI["Flutter UI"]:::flutter
        subgraph "Presentation Layer"
            HPage["Home Page"]:::presentation
            CarShop["Car Shop Page"]:::presentation
            Payment["Payment Page"]:::presentation
            Provider["User Car Product Provider"]:::presentation
            BuyNotif["Buy Notifier"]:::presentation
            ProdNotif["Products Notifier"]:::presentation
            UserCarNotif["User Car Products Notifier"]:::presentation
        end
        subgraph "Domain Layer"
            ProdEntity["Product Entity"]:::domain
            CartRepoIF["Cart Shop Repo Interface"]:::domain
        end
        subgraph "Data Layer"
            Datasource["Shop Element Datasource"]:::data
            RemoteDatasource["Shop Element Remote Datasource"]:::data
            ProdModel["Product Model"]:::data
            CartRepoImpl["Cart Shop Repo Implementation"]:::data
        end
    end

    subgraph "External Supabase Service"
        Supabase["Supabase Backend"]:::external
    end

    %% UI displays pages
    UI -->|"Display"| HPage
    UI -->|"Display"| CarShop
    UI -->|"Display"| Payment

    %% Presentation layer interactions
    HPage -->|"UI_Action"| Provider
    CarShop -->|"UI_Action"| Provider
    Payment -->|"UI_Action"| Provider

    Provider -->|"TriggerPurchase"| BuyNotif
    BuyNotif -->|"TriggerPurchase"| CartRepoIF
    ProdNotif -->|"UpdateProduct"| ProdEntity
    UserCarNotif -->|"UpdateCart"| CartRepoIF

    %% Domain to Data flow
    CartRepoIF -->|"Repository_Call"| CartRepoImpl
    ProdEntity -->|"Data_Transfer"| ProdModel

    %% Data layer interactions
    CartRepoImpl -->|"API_Call"| RemoteDatasource
    CartRepoImpl -->|"Data_Mapping"| Datasource

    %% Datasource and Remote Datasource to External
    RemoteDatasource -->|"SQL_Function"| Supabase
    Supabase -->|"Response"| RemoteDatasource

    %% Click events for Flutter UI
    click UI "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/main.dart"
    %% Click events for Presentation Layer Pages
    click HPage "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/pages/home/home_page.dart"
    click CarShop "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/pages/car_shop_page.dart"
    click Payment "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/pages/payment_page.dart"
    %% Click events for Presentation Layer State Management
    click Provider "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/inherited/user_car_product_provider.dart"
    click BuyNotif "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/notifiers/buy_notifier.dart"
    click ProdNotif "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/notifiers/products_notifier.dart"
    click UserCarNotif "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/presentation/notifiers/user_car_products_notifier.dart"
    %% Click events for Domain Layer
    click ProdEntity "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/domain/entity/product.dart"
    click CartRepoIF "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/domain/repositories/cart_shop_repository.dart"
    %% Click events for Data Layer
    click Datasource "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/data/resources/shop_element_datasource.dart"
    click RemoteDatasource "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/data/resources/shop_element_remote_datasource.dart"
    click ProdModel "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/model/product_model.dart"
    click CartRepoImpl "https://github.com/victormanuelfrancodev/supabase_carshop/blob/main/lib/repositories/cart_shop_repository_implementation.dart"

    %% Styles
    classDef flutter fill:#D1C4E9,stroke:#673AB7,stroke-width:2px;
    classDef presentation fill:#B3E5FC,stroke:#0277BD,stroke-width:2px;
    classDef domain fill:#C8E6C9,stroke:#2E7D32,stroke-width:2px;
    classDef data fill:#FFF9C4,stroke:#F9A825,stroke-width:2px;
    classDef external fill:#FFCDD2,stroke:#C62828,stroke-width:2px;
```
