# electriccodeguy/supabaseauthwithssr architecture

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

- Interactive diagram: https://gitdiagram.com/electriccodeguy/supabaseauthwithssr
- Repository: https://github.com/electriccodeguy/supabaseauthwithssr

## Overview

##### Main System Components

a) Client Layer:
- Frontend Components (app/components)
- Authentication UI (app/auth)
- Chat Interfaces (app/aichat, app/actionchat)
- Theme and UI Components

b) API Layer:
- Authentication Routes (app/api/auth)
- Chat Processing Routes (app/api/chat)
- Document Processing Routes (app/api/processdoc)
- Perplexity AI Integration (app/api/perplexity)

c) External Services Layer:
- Supabase (Authentication & Database)
- LlamaIndex Cloud
- Pinecone Vector Database
- Tavily AI Search
- OpenAI/Perplexity AI

##### Component Relationships

a) Authentication Flow:
**Client UI → API Routes → Supabase Auth → Database**
- ↳ Email Templates

b) Chat System Flow:
**Chat UI → API Routes → AI Services**
- ↳ Message Storage → Supabase Database

c) Document Processing Flow:
**Upload UI → Processing Pipeline → Vector Storage**
- ↳ LlamaIndex Processing → Pinecone Database
- ↳ Chat Interface ← Retrieved Context

##### Specific Implementation Details

a) Authentication Architecture:
- SSR implementation with middleware
- OAuth providers integration
- Password reset/update flow
- Email verification process

b) Chat System Architecture:
- Real-time streaming capabilities
- Message persistence
- Multiple AI model support
- Chat history management

c) Document Processing Pipeline:
- File upload and storage
- Text extraction and chunking
- Vector embedding generation
- Semantic search implementation

##### Key Technical Elements

Technical components:

**Frontend (Next.js 14)**
- Server Components
- Client Components
- Server Actions

**API Layer**
- Authentication Routes
- Chat Processing
- Document Handling

**External Services**
- Supabase
- Auth
- Database
- Storage
- AI Services
- OpenAI
- Perplexity
- Tavily
- Vector Storage
- LlamaIndex
- Pinecone

##### Important Notes

- Server-side rendering architecture
- Real-time capabilities
- Security boundaries
- Data flow directions
- Scalability points
- Error handling paths

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client["Client Layer"]
        direction TB
        FE["Frontend Components"]:::frontend
        Auth["Authentication UI"]:::frontend
        Chat["Chat Interfaces"]:::frontend
        Theme["Theme System"]:::frontend
        
        FE --> Auth
        FE --> Chat
        FE --> Theme
    end

    subgraph API["API Layer"]
        direction TB
        AuthAPI["Authentication Routes"]:::api
        ChatAPI["Chat Processing Routes"]:::api
        DocAPI["Document Processing Routes"]:::api
        PerAPI["Perplexity Integration"]:::api
    end

    subgraph External["External Services"]
        direction TB
        Supabase["Supabase"]:::external
        LlamaIndex["LlamaIndex Cloud"]:::external
        Pinecone["Pinecone Vector DB"]:::external
        Tavily["Tavily AI Search"]:::external
        AI["OpenAI/Perplexity"]:::external
    end

    subgraph Processing["Processing Pipeline"]
        direction TB
        Upload["Upload Handler"]:::process
        TextSplit["Text Splitting"]:::process
        AgentChains["Agent Chains"]:::process
        VectorStore["Vector Storage"]:::process
    end

    %% Connections
    Auth --> AuthAPI
    Chat --> ChatAPI
    FE --> DocAPI
    ChatAPI --> AI
    DocAPI --> Processing
    Processing --> Pinecone
    AuthAPI --> Supabase
    Upload --> TextSplit
    TextSplit --> AgentChains
    AgentChains --> VectorStore

    %% Click Events
    click Auth "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/auth"
    click Chat "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/aichat"
    click AuthAPI "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/api/auth"
    click ChatAPI "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/api/chat"
    click DocAPI "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/api/processdoc"
    click PerAPI "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/api/perplexity"
    click Upload "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/blob/main//app/api/uploaddoc/route.ts"
    click TextSplit "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/blob/main//app/api/processdoc/textspliter.ts"
    click AgentChains "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/blob/main//app/api/processdoc/agentchains.ts"
    click Theme "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/blob/main//theme/ThemeRegistry.tsx"
    click FE "https://github.com/ElectricCodeGuy/SupabaseAuthWithSSR/tree/main//app/components/ui"

    %% Styles
    classDef frontend fill:#2196F3,color:white
    classDef api fill:#4CAF50,color:white
    classDef external fill:#FFC107,color:black
    classDef process fill:#9C27B0,color:white
    
    %% Legend
    subgraph Legend
        Frontend["Frontend Component"]:::frontend
        APIRoute["API Route"]:::api
        ExtService["External Service"]:::external
        ProcessNode["Processing Node"]:::process
    end
```
