# tomerzcod7/twitter-bookmarks-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/tomerzcod7/twitter-bookmarks-chatbot
- Repository: https://github.com/tomerzcod7/twitter-bookmarks-chatbot

## Overview

##### Main Components

a. Client-Side Layer:
- Next.js Frontend (App Router based)
- UI Components (shadcn/ui components)
- Authentication Interface
- Chat Interface
- File Upload Interface

b. Server-Side Layer:
- Next.js Server Components
- Server Actions
- Authentication System (NextAuth.js)
- API Routes

c. External Services:
- LLM Providers (OpenAI, Anthropic, Cohere)
- Vercel Postgres Database
- Vercel Blob Storage
- Authentication Providers

**┌─ Client Layer ─────────────────────────┐**
- React Components                     │
- UI Framework (shadcn/ui)            │
- Client-side State Management        │
- ┬───────────────────┘
- ↕
**┌─ Application Layer ───────────────────┐**
- ┌─ Next.js App Router ──────────────┐ │
- Server Components               │ │
- Server Actions                  │ │
- API Routes                      │ │
- ┘ │
- ┌─ Core Services ──────────────────┐  │
- Auth Service                   │  │
- Chat Service                   │  │
- File Management               │  │
- ┘  │
- ┬───────────────────────┘
- ↕
**┌─ External Services ──────────────────┐**
- AI Models (OpenAI, etc.)          │
- Vercel Postgres                   │
- Vercel Blob Storage              │
- Auth Providers                    │
- ┘

##### Key Relationships to Highlight

a. Authentication Flow:
- Flow from auth forms → NextAuth.js → External providers
- Session management between client and server

b. Chat Flow:
- User input → Server processing → AI Model interaction → Response handling
- Real-time updates and streaming

c. Data Persistence:
- Chat history storage in Postgres
- File storage in Blob Storage
- User data management

##### Implementation Details

- Annotations for important configuration points (auth.config.ts, middleware.ts)
- Version information for critical dependencies

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        UI["UI Components"]
        AuthUI["Authentication UI"]:::auth
        ChatUI["Chat Interface"]:::chat
        FileUI["File Upload Interface"]:::file
        Editor["Editor Components"]:::editor
    end

    subgraph AppRouter["Application Layer (Next.js App Router)"]
        subgraph Auth["Authentication System"]
            AuthConfig["Auth Config"]:::auth
            AuthRoutes["Auth Routes"]:::auth
            AuthActions["Auth Actions"]:::auth
        end

        subgraph Chat["Chat System"]
            ChatAPI["Chat API"]:::chat
            ChatPage["Chat Interface"]:::chat
            HistoryAPI["History Management"]:::chat
            FileAPI["File Upload API"]:::file
        end

        subgraph Core["Core Services"]
            AILayer["AI Integration Layer"]:::ai
            DBLayer["Database Layer"]:::db
            FileHandler["Document Handler"]:::file
        end
    end

    subgraph External["External Services"]
        AIModels["AI Models (OpenAI, Anthropic, Cohere)"]:::external
        Postgres["Vercel Postgres"]:::external
        BlobStorage["Vercel Blob Storage"]:::external
        AuthProviders["Auth Providers"]:::external
    end

    UI --> AuthUI
    UI --> ChatUI
    UI --> FileUI
    
    AuthUI --> AuthRoutes
    AuthRoutes --> AuthConfig
    AuthConfig --> AuthProviders
    AuthActions --> DBLayer
    
    ChatUI --> ChatAPI
    ChatAPI --> AILayer
    AILayer --> AIModels
    
    FileUI --> FileAPI
    FileAPI --> FileHandler
    FileHandler --> BlobStorage
    
    ChatPage --> HistoryAPI
    HistoryAPI --> DBLayer
    DBLayer --> Postgres

    %% Click Events
    click AuthUI "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/components/auth-form.tsx"
    click ChatUI "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/components/chat.tsx"
    click Editor "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/tree/main/lib/editor"
    click AuthConfig "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(auth)/auth.config.ts"
    click AuthRoutes "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(auth)/api/auth/[...nextauth]/route.ts"
    click AuthActions "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(auth)/actions.ts"
    click ChatAPI "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(chat)/api/chat/route.ts"
    click ChatPage "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(chat)/chat/[id]/page.tsx"
    click HistoryAPI "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(chat)/api/history/route.ts"
    click FileAPI "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(chat)/api/files/upload/route.ts"
    click AILayer "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/tree/main/lib/ai"
    click DBLayer "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/tree/main/lib/db"
    click FileHandler "https://github.com/tomerzcod7/twitter-bookmarks-chatbot/blob/main/app/(chat)/api/document/route.ts"

    %% Styles
    classDef auth fill:#e6e6fa,stroke:#333
    classDef chat fill:#90ee90,stroke:#333
    classDef file fill:#ffa500,stroke:#333
    classDef ai fill:#add8e6,stroke:#333
    classDef db fill:#ffb6c1,stroke:#333
    classDef external fill:#f0e68c,stroke:#333
    classDef editor fill:#20b2aa,stroke:#333

    %% Legend
    subgraph Legend
        L1["Authentication"]:::auth
        L2["Chat System"]:::chat
        L3["File Management"]:::file
        L4["AI Integration"]:::ai
        L5["Database"]:::db
        L6["External Services"]:::external
        L7["Editor"]:::editor
    end
```
