# neon-20/chatbotai architecture

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

- Interactive diagram: https://gitdiagram.com/neon-20/chatbotai
- Repository: https://github.com/neon-20/chatbotai

## Overview

##### Project type and purpose
- This is a full-stack AI chat application (“Domus AI”) built with Next.js 14 and React on the frontend, Supabase (PostgreSQL, Auth, Storage) on the backend, and multiple external AI model integrations. It provides real-time chat, file attachments, workspaces, role-based access, and multi-locale support.

##### File structure
- **app/**: Next.js 14 “app router” pages, layouts, API routes under `app/api/…`.
- **components/**: UI broken into feature folders—chat, analytics, sidebar, models, setup, etc.
- **lib/**: Shared utilities (prompt building, stream consumption, i18n, supabase wrappers).
- **db/**: Schema wrappers for all tables (chats, messages, files, workspaces, roles).
- **supabase/**: Local Supabase config, migrations, seed.
- **public/**: Static assets, locale JSON.
- **context/**, **types/**, **worker/**: global React context, TypeScript types, background workers.
- **Tests**: unit tests in __tests__, end-to-end in Playwright.
- Configuration (next.config.js, tailwind.config.ts, env examples).

##### README for additional insights
- Layers described as Frontend, Backend (Supabase), Integration (AI APIs, WebSockets, REST).
- Features & components: chat interface, file handler, workspace management, RBAC.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Browser Layer
    subgraph "User’s Browser" 
        direction TB
        Pages["Next.js Frontend Pages"]:::frontend
        ChatUI["Chat UI Components"]:::frontend
        Sidebar["Sidebar Components"]:::frontend
        AnalyticsUI["Analytics UI Components"]:::frontend
        SetupWizard["Setup Wizard Components"]:::frontend
        SharedUI["Shared UI & Utilities"]:::frontend
    end

    %% Next.js Server Layer
    subgraph "Next.js Server (API Gateway & SSR)" 
        direction TB
        APIGateway["Serverless API Routes"]:::backend
        subgraph "Chat Integrations" 
            direction TB
            OpenAIAPI["OpenAI Chat Integration"]:::integration
            AzureAPI["Azure OpenAI Chat Integration"]:::integration
            AnthropicAPI["Anthropic Chat Integration"]:::integration
            GoogleAPI["Google AI Chat Integration"]:::integration
            MistralAPI["Mistral Chat Integration"]:::integration
            CustomAPI["Custom Chat Integration"]:::integration
        end
        subgraph "Retrieval Endpoints"
            direction TB
            RetrieveProc["Retrieval Process Endpoint"]:::backend
            RetrieveGet["Retrieval Retrieve Endpoint"]:::backend
        end
        AuthCallback["Supabase Auth Callback"]:::backend
        subgraph "Server Utilities & Libraries"
            direction TB
            SBClient["Supabase Browser Client"]:::backend
            SBServer["Supabase Server Client"]:::backend
            SBMiddleware["Supabase Middleware"]:::backend
            PromptUtil["Prompt Building Utility"]:::backend
            StreamUtil["Streaming & Server Helpers"]:::backend
            RetrievalLib["Retrieval Library"]:::backend
            SuggestionEng["Suggestion Engine"]:::backend
        end
    end

    %% Supabase Layer
    subgraph Supabase 
        direction TB
        AuthService["Auth Service"]:::database
        Database[(PostgreSQL Database)]:::database
        SchemaWrappers["DB Schema Wrappers"]:::database
        StorageService["Storage Service"]:::database
        StorageSchemas["Storage Schema Definitions"]:::database
        RealtimeService["Realtime Subscriptions"]:::database
        Config["Supabase Config & Migrations"]:::database
    end

    %% Worker Layer
    Worker["Background Worker Process"]:::process

    %% External AI Services Layer
    subgraph "External AI Services"
        direction TB
        ExtOpenAI["OpenAI"]:::external
        ExtAzure["Azure OpenAI"]:::external
        ExtAnthropic["Anthropic"]:::external
        ExtGoogle["Google AI"]:::external
        ExtMistral["Mistral"]:::external
        ExtCustom["Custom AI"]:::external
    end

    %% Connections
    Pages -->|"HTTP/HTTPS"| APIGateway
    ChatUI --> Pages
    Sidebar --> Pages
    AnalyticsUI --> Pages
    SetupWizard --> Pages
    SharedUI --> Pages

    APIGateway -->|"calls"| SBClient
    APIGateway -->|"calls"| SBServer
    APIGateway -->|"uses"| SBMiddleware
    APIGateway -->|"routes to"| OpenAIAPI
    APIGateway -->|"routes to"| AzureAPI
    APIGateway -->|"routes to"| AnthropicAPI
    APIGateway -->|"routes to"| GoogleAPI
    APIGateway -->|"routes to"| MistralAPI
    APIGateway -->|"routes to"| CustomAPI
    APIGateway -->|"routes to"| RetrieveProc
    APIGateway -->|"routes to"| RetrieveGet
    APIGateway -->|"routes to"| AuthCallback

    OpenAIAPI -->|"REST"| ExtOpenAI
    AzureAPI -->|"REST"| ExtAzure
    AnthropicAPI -->|"REST"| ExtAnthropic
    GoogleAPI -->|"REST"| ExtGoogle
    MistralAPI -->|"REST"| ExtMistral
    CustomAPI -->|"REST"| ExtCustom

    SBClient --> Database
    SBClient --> StorageService
    SBClient --> AuthService
    SBServer --> Database
    SBServer --> StorageService
    SBServer --> AuthService
    SBServer --> RealtimeService

    Database --> SchemaWrappers
    StorageService --> StorageSchemas
    Config --> SchemaWrappers
    Config --> StorageSchemas
    RealtimeService --> Pages

    Worker -->|"batch tasks"| SBServer
    Worker -->|"reads/writes"| Database
    Worker -->|"reads/writes"| StorageService

    RetrievalLib --> RetrieveProc
    RetrievalLib --> RetrieveGet
    SuggestionEng --> APIGateway
    PromptUtil --> OpenAIAPI
    PromptUtil --> AzureAPI
    PromptUtil --> AnthropicAPI
    PromptUtil --> GoogleAPI
    PromptUtil --> MistralAPI
    PromptUtil --> CustomAPI
    StreamUtil --> OpenAIAPI
    StreamUtil --> AzureAPI

    %% Click Events
    click Pages "https://github.com/neon-20/chatbotai/blob/master/app/[locale]/[workspaceid]/chat/[chatid]/page.tsx"
    click ChatUI "https://github.com/neon-20/chatbotai/tree/master/components/chat/"
    click Sidebar "https://github.com/neon-20/chatbotai/tree/master/components/sidebar/"
    click AnalyticsUI "https://github.com/neon-20/chatbotai/tree/master/components/analytics/"
    click SetupWizard "https://github.com/neon-20/chatbotai/tree/master/components/setup/"
    click SharedUI "https://github.com/neon-20/chatbotai/tree/master/components/ui/"
    click SharedUI "https://github.com/neon-20/chatbotai/tree/master/components/utility/"
    click APIGateway "https://github.com/neon-20/chatbotai/tree/master/app/api/"
    click OpenAIAPI "https://github.com/neon-20/chatbotai/blob/master/app/api/chat/openai/route.ts"
    click AzureAPI "https://github.com/neon-20/chatbotai/blob/master/app/api/chat/azure/route.ts"
    click AnthropicAPI "https://github.com/neon-20/chatbotai/blob/master/app/api/chat/anthropic/route.ts"
    click GoogleAPI "https://github.com/neon-20/chatbotai/blob/master/app/api/chat/google/route.ts"
    click MistralAPI "https://github.com/neon-20/chatbotai/blob/master/app/api/chat/mistral/route.ts"
    click CustomAPI "https://github.com/neon-20/chatbotai/blob/master/app/api/chat/custom/route.ts"
    click RetrieveProc "https://github.com/neon-20/chatbotai/blob/master/app/api/retrieval/process/route.ts"
    click RetrieveGet "https://github.com/neon-20/chatbotai/blob/master/app/api/retrieval/retrieve/route.ts"
    click AuthCallback "https://github.com/neon-20/chatbotai/blob/master/app/auth/callback/route.ts"
    click SBClient "https://github.com/neon-20/chatbotai/blob/master/lib/supabase/browser-client.ts"
    click SBServer "https://github.com/neon-20/chatbotai/blob/master/lib/supabase/server.ts"
    click SBMiddleware "https://github.com/neon-20/chatbotai/blob/master/lib/supabase/middleware.ts"
    click PromptUtil "https://github.com/neon-20/chatbotai/blob/master/lib/build-prompt.ts"
    click StreamUtil "https://github.com/neon-20/chatbotai/blob/master/lib/consume-stream.ts"
    click StreamUtil "https://github.com/neon-20/chatbotai/blob/master/lib/server/server-chat-helpers.ts"
    click RetrievalLib "https://github.com/neon-20/chatbotai/tree/master/lib/retrieval/processing/"
    click RetrievalLib "https://github.com/neon-20/chatbotai/blob/master/lib/retrieval/summary.ts"
    click SuggestionEng "https://github.com/neon-20/chatbotai/tree/master/lib/suggestions/"
    click SchemaWrappers "https://github.com/neon-20/chatbotai/tree/master/db/"
    click StorageSchemas "https://github.com/neon-20/chatbotai/tree/master/db/storage/"
    click Config "https://github.com/neon-20/chatbotai/blob/master/supabase/config.toml"
    click Config "https://github.com/neon-20/chatbotai/tree/master/supabase/migrations/"
    click Worker "https://github.com/neon-20/chatbotai/blob/master/worker/index.js"

    %% Styles
    classDef frontend fill:#D0E8FF,stroke:#0366d6,color:#0366d6;
    classDef backend fill:#E6FFED,stroke:#028A0F,color:#028A0F;
    classDef database fill:#FFF5D1,stroke:#D4A90B,color:#D4A90B;
    classDef external fill:#FFE2E2,stroke:#D93025,color:#D93025;
    classDef integration fill:#FFEBCD,stroke:#D2691E,color:#D2691E;
    classDef process fill:#F0F0F0,stroke:#A0A0A0,color:#555555;
```
