# vercel-labs/gemini-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/vercel-labs/gemini-chatbot
- Repository: https://github.com/vercel-labs/gemini-chatbot

## Overview

##### Project Type and Purpose
- This is a full-stack AI chatbot template built with Next.js 14 (App Router) that uses Vercel’s AI SDK for LLM integration.
- It provides authentication (NextAuth), chat interfaces, file uploads, history storage, and reservation functionality.
- Key use case: users log in, interact via chat UI backed by a large language model, upload files, and view/save chat history.

##### File Structure Analysis
- Top-level “app” directory: Next.js App Router routes split into two route groups:
- `(auth)`: endpoints/pages for login, registration, NextAuth handlers, and auth middleware.
- `(chat)`: chat pages, dynamic routes for conversations, and multiple API routes (`chat`, `files/upload`, `history`, `reservation`).
- “ai” folder: server-side AI integration layer with custom middleware, action functions, and an index entrypoint for making SDK calls.
- “components”: React UI primitives split into `custom` (chat UI, forms, navigation) and `flights` (booking flows), plus generic `ui` components from shadcn + Radix.
- “db” + “drizzle.config.ts”: database schema, migrations, and queries powered by Drizzle ORM, targeting Vercel Postgres/Neon.
- “public”: static assets (images, fonts).
- Configuration: `.env.example` for secrets, `next.config.mjs`, `tailwind.config.ts`, `postcss.config.mjs`.

##### README Insights
- Confirms stack: Next.js App Router with React Server Components & Server Actions, AI SDK hooking into multiple LLM providers, Postgres + Blob storage for persistence, NextAuth for auth.

##### Final Advice
- Logical layer; don’t omit the AI middleware or the Drizzle ORM layer.
- Dynamic routes under chat as part of the UI, but highlight the single API endpoint handler.
- Be detailed: label server actions separately from REST endpoints if both are used.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Frontend (UI)"
        Layout["Layout & Global Styles"]:::frontend
        Login["Login Page"]:::frontend
        Register["Registration Page"]:::frontend
        ChatHome["Chat List / Home"]:::frontend
        ChatDetail["Conversation Detail"]:::frontend
        customUI["Custom Primitives"]:::frontend
        flightsUI["Flight Reservation Flow"]:::frontend
        genericUI["Generic UI Library"]:::frontend
        Utils["Utility Functions"]:::frontend
        Configs["Tailwind, PostCSS & Next.js Config"]:::frontend
    end

    subgraph "Backend (App Server)"
        AuthAPI["NextAuth Endpoints"]:::backend
        AuthCfg["NextAuth Config & Actions"]:::backend
        ChatAPI["Chat API (/api/chat)"]:::backend
        FileAPI["File Upload API (/api/files/upload)"]:::backend
        HistoryAPI["History API (/api/history)"]:::backend
        ReservationAPI["Reservation API (/api/reservation)"]:::backend
        AIIndex["AI Layer Entry Point"]:::backend
        AIActions["AI Actions & Middleware"]:::backend
        DrizzleConfig["Drizzle Configuration"]:::backend
        DBSchema["DB Schema & Migrations"]:::database
        DBQueries["DB Queries"]:::database
        BlobStorage["Blob Storage"]:::storage
    end

    subgraph "External Services"
        LLM["LLM Providers"]:::external
        AuthProvider["Auth Providers"]:::external
    end

    %% Frontend to Backend
    Login -->|uses| AuthAPI
    Register -->|uses| AuthAPI
    ChatHome -->|calls| ChatAPI
    ChatDetail -->|calls| ChatAPI
    ChatDetail -->|uploads files| FileAPI
    ChatHome -->|fetches history| HistoryAPI
    ChatHome -->|manages reservation| ReservationAPI

    %% Auth flow
    AuthAPI -->|reads/writes| DBQueries
    AuthAPI -->|auth via| AuthProvider
    AuthCfg -->|configures| AuthAPI

    %% Chat and AI flow
    ChatAPI -->|orchestrates| AIActions
    AIActions -->|invokes| AIIndex
    AIIndex -->|requests| LLM
    LLM -->|responds| AIIndex
    AIIndex -->|returns| AIActions
    AIActions -->|responds| ChatAPI

    %% File and storage
    FileAPI -->|streams files to| BlobStorage
    FileAPI -->|stores metadata| DBQueries

    %% History & reservation
    HistoryAPI -->|queries| DBQueries
    ReservationAPI -->|queries| DBQueries

    %% Database config
    DBQueries -->|uses| DrizzleConfig
    DBSchema -->|migrates| DBQueries

    %% Click Events
    click Layout "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/layout.tsx"
    click Login "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(auth)/login/page.tsx"
    click Register "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(auth)/register/page.tsx"
    click ChatHome "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(chat)/page.tsx"
    click ChatDetail "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(chat)/chat/[id]/page.tsx"
    click AuthAPI "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(auth)/api/auth/[...nextauth]/route.ts"
    click AuthCfg "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(auth)/auth.config.ts"
    click AuthCfg "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(auth)/actions.ts"
    click ChatAPI "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(chat)/api/chat/route.ts"
    click FileAPI "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(chat)/api/files/upload/route.ts"
    click HistoryAPI "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(chat)/api/history/route.ts"
    click ReservationAPI "https://github.com/vercel-labs/gemini-chatbot/blob/main/app/(chat)/api/reservation/route.ts"
    click AIIndex "https://github.com/vercel-labs/gemini-chatbot/blob/main/ai/index.ts"
    click AIActions "https://github.com/vercel-labs/gemini-chatbot/blob/main/ai/actions.ts"
    click AIActions "https://github.com/vercel-labs/gemini-chatbot/blob/main/ai/custom-middleware.ts"
    click DBSchema "https://github.com/vercel-labs/gemini-chatbot/blob/main/db/schema.ts"
    click DBSchema "https://github.com/vercel-labs/gemini-chatbot/blob/main/db/migrate.ts"
    click DBQueries "https://github.com/vercel-labs/gemini-chatbot/blob/main/db/queries.ts"
    click DrizzleConfig "https://github.com/vercel-labs/gemini-chatbot/blob/main/drizzle.config.ts"
    click customUI "https://github.com/vercel-labs/gemini-chatbot/tree/main/components/custom/"
    click flightsUI "https://github.com/vercel-labs/gemini-chatbot/tree/main/components/flights/"
    click genericUI "https://github.com/vercel-labs/gemini-chatbot/tree/main/components/ui/"
    click Utils "https://github.com/vercel-labs/gemini-chatbot/blob/main/lib/utils.ts"
    click Configs "https://github.com/vercel-labs/gemini-chatbot/blob/main/tailwind.config.ts"
    click Configs "https://github.com/vercel-labs/gemini-chatbot/blob/main/postcss.config.mjs"
    click Configs "https://github.com/vercel-labs/gemini-chatbot/blob/main/next.config.mjs"

    %% Styles
    classDef frontend fill:#e8f5e9,stroke:#1b5e20
    classDef backend fill:#e3f2fd,stroke:#0d47a1
    classDef database fill:#fff3e0,stroke:#e65100
    classDef storage fill:#fff3e0,stroke:#e65100
    classDef external fill:#f3e5f5,stroke:#4a148c
```
