# kpolley/gitchat architecture

> Architecture diagram of the GitHub repository kpolley/gitchat, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kpolley/gitchat
- Repository: https://github.com/kpolley/gitchat

## Overview

##### Main Components

a. Client-Side (Frontend):
- Next.js Application Layer
- Authentication UI Components
- Chat Interface Components
- Theme Management
- Session Management

b. Server-Side (Backend):
- Next.js API Routes
- Authentication Service
- Vector Database
- Chat Processing Service

c. External Services:
- OpenAI API
- GitHub API
- Google OAuth
- Vector Storage

##### User Interface Layer (Top)
- Chat Interface (chat/, components/chat*)
- Authentication UI (sign-in/)
- Sidebar Navigation (components/sidebar*)
- Theme Controls (components/theme*)

##### Application Layer (Middle)
- Route Handlers (app/ directory)
- API Routes (app/api/)
- Middleware (middleware.ts)
- Actions (app/actions.ts)

##### Services Layer (Bottom)
- Authentication Service (auth.ts)
- Vector Database Service (generate.ts)
- Chat Processing Service (app/api/chat)

##### External Services (Right Side)
- OpenAI API
- GitHub Repository
- Google OAuth
- Vector Storage

##### Connection Flows

- User → Authentication Flow → Google OAuth
- Client → API Routes → OpenAI API
- Generate Script → GitHub Repo → Vector Database
- Chat Interface → Chat Processing → Vector Database + OpenAI

##### Technical Details to Note

Annotations for:
- Next.js 13+ App Router usage
- Server-side API routes
- Authentication flow with Auth.js
- Vector database implementation
- Real-time chat processing

##### The separation between client and server components

Remember to indicate the real-time nature of the chat system and the vector database's role in processing GitHub repository content. This will help other engineers understand both the static architecture and the dynamic data flows of the system.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        UI[Client Components]
        subgraph ClientComponents
            CI["Chat Interface"]:::client
            AU["Authentication UI"]:::client
            SN["Sidebar Navigation"]:::client
            TC["Theme Controls"]:::client
            CH["Chat History"]:::client
        end
    end

    subgraph AppLayer
        NA["Next.js Application"]
        subgraph Core
            RH["Route Handlers"]:::core
            AR["API Routes"]:::core
            MW["Middleware"]:::core
            AC["Actions"]:::core
        end
    end

    subgraph Services
        AS["Authentication Service"]:::service
        VD["Vector Database Service"]:::service
        CP["Chat Processing Service"]:::service
    end

    subgraph External
        OAI["OpenAI API"]:::external
        GH["GitHub Repository"]:::external
        GO["Google OAuth"]:::external
        VS["Vector Storage"]:::external
    end

    UI --> NA
    NA --> Services
    Services --> External

    CI --> CP
    AU --> AS
    AS --> GO
    CP --> OAI
    CP --> VD
    VD --> VS
    VD --> GH

    %% Component Mappings
    click CI "https://github.com/kpolley/GitChat/tree/main/app/(chat)/chat/"
    click AU "https://github.com/kpolley/GitChat/blob/main/app/sign-in/page.tsx"
    click SN "https://github.com/kpolley/GitChat/blob/main/components/sidebar.tsx"
    click TC "https://github.com/kpolley/GitChat/blob/main/components/theme-toggle.tsx"
    click AR "https://github.com/kpolley/GitChat/blob/main/app/api/chat/route.ts"
    click MW "https://github.com/kpolley/GitChat/blob/main/middleware.ts"
    click AC "https://github.com/kpolley/GitChat/blob/main/app/actions.ts"
    click AS "https://github.com/kpolley/GitChat/blob/main/auth.ts"
    click VD "https://github.com/kpolley/GitChat/blob/main/generate.ts"
    click CH "https://github.com/kpolley/GitChat/blob/main/components/chat-history.tsx"

    classDef client fill:#3498db,stroke:#2980b9,color:#fff
    classDef core fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef service fill:#9b59b6,stroke:#8e44ad,color:#fff
    classDef external fill:#f1c40f,stroke:#f39c12,color:#000
    
    %% Legend
    subgraph Legend
        L1[Client Component]:::client
        L2[Core Component]:::core
        L3[Service Component]:::service
        L4[External Service]:::external
    end
```
