# supabase-community/database-build architecture

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

- Interactive diagram: https://gitdiagram.com/supabase-community/database-build
- Repository: https://github.com/supabase-community/database-build

## Overview

##### Main System Components

a) Frontend Layer (Next.js Web Application):
- Main web interface components
- AI chat interface
- Database management UI

b) Core Processing Layer:
- PGLite WASM Instance
- IndexedDB Storage
- AI/LLM Integration
- WebSocket Communication

c) Backend Services:
- Browser Proxy Service
- Deploy Worker Service
- Supabase Integration
- Redis (KV Store)

##### Component Relationships

**[Web Application (Next.js)]**

- ► [PGLite WASM Instance] ←──► [IndexedDB]

- ► [AI/LLM Service]

- ► [WebSocket Connection] ←──► [Browser Proxy]

- ► [Deploy Worker] ←──► [Supabase]

##### Specific Implementation Details

a) Frontend Layer (apps/web):
- Main application routes (/db, /deploy, /import, /export)
- Components directory structure
- UI components and tools

b) Browser Proxy (apps/browser-proxy):
- TCP Server
- WebSocket Server
- Connection Manager
- Protocol Handlers

c) Deploy Worker (apps/deploy-worker):
- Deployment Service
- Supabase Integration
- Database Management

##### Key Technical Elements to Highlight

- WASM integration for PGLite
- IndexedDB storage mechanism
- WebSocket/TCP proxy communication
- Authentication flow
- AI/LLM integration points

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles and Classes
    classDef frontend fill:#3498db,stroke:#2980b9,color:white
    classDef database fill:#2ecc71,stroke:#27ae60,color:white
    classDef ai fill:#9b59b6,stroke:#8e44ad,color:white
    classDef communication fill:#e67e22,stroke:#d35400,color:white
    classDef deployment fill:#e74c3c,stroke:#c0392b,color:white
    classDef storage fill:#95a5a6,stroke:#7f8c8d,color:white

    %% Frontend Layer
    subgraph Frontend
        WebApp["Next.js Web Application"]:::frontend
        DbUI["Database UI"]:::frontend
        ChatUI["AI Chat Interface"]:::frontend
        DeployUI["Deployment UI"]:::frontend
        SchemaUI["Schema Management"]:::frontend
        Tools["Import/Export Tools"]:::frontend
    end

    %% Core Processing Layer
    subgraph Core
        PGLite["PGLite WASM Instance"]:::database
        IndexedDB["IndexedDB Storage"]:::storage
        LLMI["AI/LLM Integration"]:::ai
        WSProtocol["WebSocket Protocol"]:::communication
    end

    %% Backend Services
    subgraph Backend
        BrowserProxy["Browser Proxy Service"]:::communication
        TCPServer["TCP Server"]:::communication
        WSServer["WebSocket Server"]:::communication
        ConnManager["Connection Manager"]:::communication
    end

    %% Deployment Layer
    subgraph Deployment
        DeployWorker["Deploy Worker"]:::deployment
        SupabaseInt["Supabase Integration"]:::deployment
        Redis["Redis KV Store"]:::storage
    end

    %% Relationships
    WebApp --> DbUI
    WebApp --> ChatUI
    WebApp --> DeployUI
    WebApp --> SchemaUI
    WebApp --> Tools
    
    DbUI --> PGLite
    PGLite --> IndexedDB
    ChatUI --> LLMI
    WSProtocol --> BrowserProxy
    BrowserProxy --> TCPServer
    BrowserProxy --> WSServer
    BrowserProxy --> ConnManager
    
    DeployUI --> DeployWorker
    DeployWorker --> SupabaseInt
    DeployWorker --> Redis

    %% Click Events
    click WebApp "https://github.com/supabase-community/database-build/tree/main/apps/web"
    click DbUI "https://github.com/supabase-community/database-build/tree/main/apps/web/app/(main)/db"
    click ChatUI "https://github.com/supabase-community/database-build/blob/main/apps/web/components/chat.tsx"
    click DeployUI "https://github.com/supabase-community/database-build/tree/main/apps/web/components/deploy"
    click SchemaUI "https://github.com/supabase-community/database-build/tree/main/apps/web/components/schema"
    click PGLite "https://github.com/supabase-community/database-build/tree/main/apps/web/lib/db"
    click IndexedDB "https://github.com/supabase-community/database-build/blob/main/apps/web/lib/indexed-db.ts"
    click LLMI "https://github.com/supabase-community/database-build/blob/main/apps/web/lib/llm-provider.ts"
    click WSProtocol "https://github.com/supabase-community/database-build/blob/main/apps/web/lib/websocket-protocol.ts"
    click BrowserProxy "https://github.com/supabase-community/database-build/tree/main/apps/browser-proxy"
    click TCPServer "https://github.com/supabase-community/database-build/blob/main/apps/browser-proxy/src/tcp-server.ts"
    click WSServer "https://github.com/supabase-community/database-build/blob/main/apps/browser-proxy/src/websocket-server.ts"
    click ConnManager "https://github.com/supabase-community/database-build/blob/main/apps/browser-proxy/src/connection-manager.ts"
    click DeployWorker "https://github.com/supabase-community/database-build/tree/main/apps/deploy-worker"
    click SupabaseInt "https://github.com/supabase-community/database-build/tree/main/packages/deploy/src/supabase"
    click Tools "https://github.com/supabase-community/database-build/blob/main/apps/web/components/tools/csv-import.tsx"
```
