# floris-xlx/supabase_rs architecture

> Architecture diagram of the GitHub repository floris-xlx/supabase_rs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/floris-xlx/supabase_rs
- Repository: https://github.com/floris-xlx/supabase_rs

## Overview

##### Project Type Analysis
This is a Rust SDK (Software Development Kit) that serves as a client library for interacting with Supabase services. It's primarily focused on database operations with planned expansions for Auth, Realtime, and Storage features.

##### Main Components

a. Core Components:
- Database Operations Module
- GraphQL Module (Nightly Feature)
- Storage Module
- Request/Client Handler
- Error Handling System

b. External Systems:
- Supabase Backend Services
- Supabase Database
- Supabase Storage
- GraphQL Endpoint

**┌─ Client Application Layer ─────────────────────┐**

- Uses supabase_rs SDK                      │

- ┬───────────────────────────┤

- Core Client     │     Feature Modules       │
- (src/lib.rs)    │                          │

- ┬───────┴──────┬──────────┬────────┤

- Database │   GraphQL    │  Storage │ Future │
- Ops     │   (Nightly) │          │ Modules│

- ┴──────────────┴──────────┴────────┘

##### Specific Component Details

a. Database Operations Module:
- CRUD operations (insert.rs, update.rs, delete.rs, query.rs)
- Query Builder subsystem (query_builder/)
- Filtering and sorting capabilities

b. GraphQL Module:
- Parser component (graphql/parsing/)
- Query handling (graphql/query.rs)
- Client operations (graphql/client.rs)

c. Storage Module:
- Download/upload operations
- Bucket management

##### Important Implementation Details

Notes about:
- Feature flags (nightly, storage, rustls)
- Environment configuration requirements
- Authentication flow
- Error handling patterns

##### The extensibility of the system for future features

This structure will provide a clear understanding of the SDK's architecture while maintaining the flexibility needed for ongoing development and feature additions.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Application Layer"]
        App[Client Application]
    end

    subgraph SDK["Core SDK Layer"]
        Core["Core Client"]:::core
        ErrorSystem["Error Handling System"]:::core
        RequestHandler["Request/Client Handler"]:::core
    end

    subgraph Features["Feature Modules Layer"]
        subgraph DB["Database Operations"]
            CRUD["CRUD Operations"]:::stable
            QB["Query Builder"]:::stable
            
            subgraph CRUDOps["CRUD Components"]
                Create["Create"]:::stable
                Read["Read"]:::stable
                Update["Update"]:::stable
                Delete["Delete"]:::stable
            end
            
            subgraph QBComponents["Query Builder Components"]
                Filter["Filtering"]:::stable
                Sort["Sorting"]:::stable
            end
        end

        subgraph GQL["GraphQL Module (Nightly)"]
            GQLHandler["GraphQL Handler"]:::nightly
            Parser["Parser Component"]:::nightly
            QueryHandler["Query Handler"]:::nightly
            ClientOps["Client Operations"]:::nightly
            GQLUtils["GraphQL Utils"]:::nightly
        end

        subgraph Storage["Storage Module"]
            StorageHandler["Storage Handler"]:::stable
            Download["Download Operations"]:::stable
        end

        subgraph Other["Additional Features"]
            Realtime["Realtime Features"]:::planned
            Router["Routing System"]:::stable
            Utils["Utility Functions"]:::stable
        end
    end

    subgraph External["External Services"]
        SupabaseDB[(Supabase Database)]
        SupabaseStorage[(Supabase Storage)]
        GraphQLEndpoint["GraphQL Endpoint"]
    end

    %% Connections
    App --> Core
    Core --> ErrorSystem
    Core --> RequestHandler
    
    RequestHandler --> DB
    RequestHandler --> GQL
    RequestHandler --> Storage
    RequestHandler --> Other

    CRUD --> CRUDOps
    QB --> QBComponents

    %% External Connections
    DB -.-> SupabaseDB
    Storage -.-> SupabaseStorage
    GQL -.-> GraphQLEndpoint

    %% Click Events
    click Core "https://github.com/floris-xlx/supabase_rs/blob/main/src/lib.rs"
    click ErrorSystem "https://github.com/floris-xlx/supabase_rs/blob/main/src/errors.rs"
    click Create "https://github.com/floris-xlx/supabase_rs/blob/main/src/insert.rs"
    click Read "https://github.com/floris-xlx/supabase_rs/blob/main/src/select.rs"
    click Update "https://github.com/floris-xlx/supabase_rs/blob/main/src/update.rs"
    click Delete "https://github.com/floris-xlx/supabase_rs/blob/main/src/delete.rs"
    click QB "https://github.com/floris-xlx/supabase_rs/tree/main/src/query_builder/"
    click Filter "https://github.com/floris-xlx/supabase_rs/blob/main/src/query_builder/filter.rs"
    click Sort "https://github.com/floris-xlx/supabase_rs/blob/main/src/query_builder/sort.rs"
    click GQLHandler "https://github.com/floris-xlx/supabase_rs/blob/main/src/graphql/mod.rs"
    click Parser "https://github.com/floris-xlx/supabase_rs/tree/main/src/graphql/parsing/"
    click QueryHandler "https://github.com/floris-xlx/supabase_rs/blob/main/src/graphql/query.rs"
    click ClientOps "https://github.com/floris-xlx/supabase_rs/blob/main/src/graphql/client.rs"
    click GQLUtils "https://github.com/floris-xlx/supabase_rs/tree/main/src/graphql/utils/"
    click StorageHandler "https://github.com/floris-xlx/supabase_rs/blob/main/src/storage/mod.rs"
    click Download "https://github.com/floris-xlx/supabase_rs/blob/main/src/storage/download.rs"
    click RequestHandler "https://github.com/floris-xlx/supabase_rs/blob/main/src/request/mod.rs"
    click Realtime "https://github.com/floris-xlx/supabase_rs/blob/main/src/realtime/mod.rs"
    click Router "https://github.com/floris-xlx/supabase_rs/blob/main/src/routing/mod.rs"
    click Utils "https://github.com/floris-xlx/supabase_rs/blob/main/src/utils/mod.rs"

    %% Styling
    classDef core fill:#2374ab
    classDef stable fill:#57a773
    classDef nightly fill:#ffc857
    classDef planned fill:#95a5a6
    classDef external fill:#34495e

    %% Legend
    subgraph Legend
        CoreL["Core Components"]:::core
        StableL["Stable Features"]:::stable
        NightlyL["Nightly Features"]:::nightly
        PlannedL["Planned Features"]:::planned
        ExternalL["External Services"]:::external
    end
```
