# ragieai/basechat architecture

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

- Interactive diagram: https://gitdiagram.com/ragieai/basechat
- Repository: https://github.com/ragieai/basechat

## Overview

##### Main System Components

a) Client Layer:
- Next.js Frontend (app directory structure)
- Authentication UI components
- Chat interface components
- Settings and configuration UI

b) API Layer:
- Next.js API routes (/app/api/*)
- Authentication endpoints
- Conversation management
- Document management
- Tenant management

c) Integration Layer:
- Ragie.ai connection
- Google Authentication

d) Data Layer:
- PostgreSQL database
- Drizzle ORM integration

##### Component Relationships

a) Frontend to Backend:
- API routes connections from frontend components to their corresponding endpoints
- Authentication flow
- Demonstrate conversation data flow

b) External Services:
- Connection to Ragie.ai for RAG (Retrieval Augmented Generation) functionality
- Google Auth integration for user authentication

##### Specific Implementation Details

Architectural patterns:

a) Multi-tenant Architecture:
- Tenant isolation
- User management per tenant
- Connection management

b) Next.js App Router Structure:
- (auth) route group
- (main) route group
- API routes organization

##### Key Components to Highlight

Frontend:
**/app/(main)/conversations/* - Chat interface**
**/app/(main)/data/* - Data management**
**/app/(main)/settings/* - System settings**
**/components/chatbot/* - Chat components**

Backend:
**/app/api/conversations/* - Conversation management**
**/app/api/ragie/* - Ragie.ai integration**
**/app/api/tenants/* - Tenant management**
**/lib/data-access/* - Data access layer**

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        FE_Auth["Authentication UI"]
        FE_Chat["Chat Interface"]
        FE_Settings["Settings UI"]
        FE_Data["Data Management UI"]
        FE_Users["User Management"]
        FE_Invites["Invite Management"]
    end

    subgraph API
        API_Auth["Auth Endpoints"]
        API_Chat["Conversation API"]
        API_Data["Document API"]
        API_Tenant["Tenant API"]
        API_Users["User API"]
        API_Ragie["Ragie.ai API"]
        API_Conn["Connection API"]
        API_Invites["Invite API"]
    end

    subgraph External
        Ragie["Ragie.ai Service"]
        GoogleAuth["Google Auth"]
    end

    subgraph Data
        DB[(PostgreSQL)]
        ORM["Drizzle ORM"]
    end

    %% Client to API Connections
    FE_Auth --> API_Auth
    FE_Chat --> API_Chat
    FE_Settings --> API_Tenant
    FE_Data --> API_Data
    FE_Users --> API_Users
    FE_Invites --> API_Invites

    %% API to External Connections
    API_Auth --> GoogleAuth
    API_Ragie --> Ragie
    API_Chat --> API_Ragie

    %% Data Layer Connections
    API_Chat --> ORM
    API_Data --> ORM
    API_Tenant --> ORM
    API_Users --> ORM
    API_Invites --> ORM
    ORM --> DB

    %% Click Events
    click FE_Auth "https://github.com/ragieai/basechat/tree/main/app/(auth)"
    click API_Auth "https://github.com/ragieai/basechat/tree/main/app/api/auth"
    click FE_Chat "https://github.com/ragieai/basechat/tree/main/app/(main)/conversations"
    click API_Chat "https://github.com/ragieai/basechat/tree/main/app/api/conversations"
    click FE_Settings "https://github.com/ragieai/basechat/tree/main/app/(main)/settings"
    click API_Tenant "https://github.com/ragieai/basechat/tree/main/app/api/tenants"
    click FE_Data "https://github.com/ragieai/basechat/tree/main/app/(main)/data"
    click API_Data "https://github.com/ragieai/basechat/tree/main/app/api/documents"
    click FE_Users "https://github.com/ragieai/basechat/tree/main/app/(main)/settings/users"
    click API_Users "https://github.com/ragieai/basechat/tree/main/app/api/profiles"
    click FE_Invites "https://github.com/ragieai/basechat/tree/main/app/(main)/invites"
    click API_Invites "https://github.com/ragieai/basechat/tree/main/app/api/invites"
    click API_Ragie "https://github.com/ragieai/basechat/tree/main/app/api/ragie"
    click API_Conn "https://github.com/ragieai/basechat/tree/main/app/api/connections"
    click ORM "https://github.com/ragieai/basechat/tree/main/lib/db"

    classDef frontend fill:#2196F3,stroke:#1565C0,color:white
    classDef api fill:#4CAF50,stroke:#2E7D32,color:white
    classDef external fill:#FFC107,stroke:#FFA000,color:black
    classDef database fill:#9E9E9E,stroke:#616161,color:white

    class FE_Auth,FE_Chat,FE_Settings,FE_Data,FE_Users,FE_Invites frontend
    class API_Auth,API_Chat,API_Data,API_Tenant,API_Users,API_Ragie,API_Conn,API_Invites api
    class Ragie,GoogleAuth external
    class DB,ORM database
```
