# amitaymanor/ai-sdk-server architecture

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

- Interactive diagram: https://gitdiagram.com/amitaymanor/ai-sdk-server
- Repository: https://github.com/amitaymanor/ai-sdk-server

## Overview

##### Main Components

a) Core Server Components:
- Main API Server (Go-based)
- Authentication Layer
- Request Handlers
- Middleware Services
- Model Management

b) External Services:
- Supabase Integration
- HuggingFace Inference API
- Storage Service

**External Clients → API Layer → External Services**

##### Detailed Component Breakdown

a) API Layer (Go Server):
- Three main handler components:
- Auth Handler
- Model Request Handler
- Storage Handler
- Middleware components:
- Authentication Middleware
- Validation Middleware

b) Supabase Integration:
- On the right side
- Connection to:
- Database
- Authentication
- Storage

c) Serverless Functions:
- HuggingFace inference function
- Processor and types components

##### Connection Flows

- Client requests → API Server
- API Server → Supabase
- Supabase Functions → HuggingFace API
- Data flow between components

##### Important Details

- Configuration management (.env, config.toml)
- Authentication flow
- Model inference pipeline
- Storage handling
- Request validation flow

##### Specific Implementation Notes

Clear separation between:
- Request handling layer (handlers/)
- Business logic layer (models/)
- Infrastructure layer (config/)
- Serverless functions (supabase/functions/)

##### Configuration management and environment separation

Level of Detail:

- Keep main components visible at a glance
- Technology stack indicators (Go, Deno, Supabase, HuggingFace)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "External Clients"
        Client[Client Requests]
    end

    subgraph "API Layer"
        API[Main API Server]:::server
        click API "https://github.com/AmitayManor/ai-sdk-server/blob/main/main.go"

        subgraph "Handlers"
            AuthH[Auth Handler]:::handler
            click AuthH "https://github.com/AmitayManor/ai-sdk-server/blob/main/handlers/auth.go"
            ModelH[Model Request Handler]:::handler
            click ModelH "https://github.com/AmitayManor/ai-sdk-server/blob/main/handlers/model_requests.go"
            StorageH[Storage Handler]:::handler
            click StorageH "https://github.com/AmitayManor/ai-sdk-server/blob/main/handlers/storage.go"
        end

        subgraph "Middleware"
            AuthMW[Authentication Middleware]:::middleware
            click AuthMW "https://github.com/AmitayManor/ai-sdk-server/blob/main/middleware/auth.go"
            ValidMW[Validation Middleware]:::middleware
            click ValidMW "https://github.com/AmitayManor/ai-sdk-server/blob/main/middleware/validation.go"
        end

        subgraph "Models"
            Types[Type Definitions]:::types
            click Types "https://github.com/AmitayManor/ai-sdk-server/blob/main/models/types.go"
        end

        subgraph "Config"
            SupaConfig[Supabase Config]:::config
            click SupaConfig "https://github.com/AmitayManor/ai-sdk-server/blob/main/config/supabase.go"
            EnvConfig[Environment Config]:::config
            click EnvConfig "https://github.com/AmitayManor/ai-sdk-server/blob/main/.env.example"
        end
    end

    subgraph "External Services"
        subgraph "Supabase"
            SupaAuth[Authentication]:::supabase
            SupaDB[Database]:::supabase
            SupaStorage[Storage]:::supabase
            
            subgraph "Serverless Functions"
                HFInference[HuggingFace Inference]:::serverless
                click HFInference "https://github.com/AmitayManor/ai-sdk-server/blob/main/supabase/functions/hf-inference/index.ts"
                Processor[Processor]:::serverless
                click Processor "https://github.com/AmitayManor/ai-sdk-server/blob/main/supabase/functions/hf-inference/shared/processor.ts"
                ServerlessTypes[Types]:::serverless
                click ServerlessTypes "https://github.com/AmitayManor/ai-sdk-server/blob/main/supabase/functions/hf-inference/shared/types.ts"
            end
        end

        HF[HuggingFace API]:::external
        click HF "https://github.com/AmitayManor/ai-sdk-server/blob/main/supabase/functions/hf-inference/shared/huggingface.ts"
    end

    %% Connections
    Client --> API
    API --> AuthH & ModelH & StorageH
    AuthH & ModelH & StorageH --> AuthMW
    AuthMW --> ValidMW
    ValidMW --> Types
    AuthH --> SupaAuth
    ModelH --> HFInference
    StorageH --> SupaStorage
    HFInference --> Processor
    Processor --> HF
    SupaConfig --> SupaAuth & SupaDB & SupaStorage

    %% Styles
    classDef server fill:#3498db,stroke:#2980b9,color:white
    classDef handler fill:#2ecc71,stroke:#27ae60,color:white
    classDef middleware fill:#9b59b6,stroke:#8e44ad,color:white
    classDef types fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef config fill:#e74c3c,stroke:#c0392b,color:white
    classDef supabase fill:#f1c40f,stroke:#f39c12,color:black
    classDef serverless fill:#1abc9c,stroke:#16a085,color:white
    classDef external fill:#e67e22,stroke:#d35400,color:white

    %% Legend
    subgraph Legend
        L1[Server]:::server
        L2[Handler]:::handler
        L3[Middleware]:::middleware
        L4[Types]:::types
        L5[Config]:::config
        L6[Supabase]:::supabase
        L7[Serverless]:::serverless
        L8[External]:::external
    end
```
