# aaryan6/ai-mini-apps architecture

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

- Interactive diagram: https://gitdiagram.com/aaryan6/ai-mini-apps
- Repository: https://github.com/aaryan6/ai-mini-apps

## Overview

##### Main System Components

a) Frontend Layer:
- Pages (PDF Chat, Regular Chat, Auth pages)
- UI Components
- Theme Provider
- Client-side Utilities

b) Next.js Application Layer:
- API Routes
- Server Components
- Client Components
- Middleware

c) Backend Services:
- Distinct services:
- Authentication Service (NextAuth.js)
- PDF Processing Service
- Chat/AI Service
- Database Layer (Drizzle ORM)

##### Component Relationships

a) Client-Server Communication:
- API routes (/api/chat, /api/pdf-chat, /api/files/*)
- Authentication flow
- WebSocket or streaming connections for chat functionality

b) Data Flow:
- PDF processing pipeline
- Chat message flow
- Authentication flow
- Database interactions

##### Specific Implementation Details

Technical elements:

**Frontend:**
- Public Routes
- Home Page
- Protected Routes
- Chat Interface
- PDF Chat Interface
- Shared Components
- UI Components
- Theme System

**API Layer:**
- Auth Routes (/api/auth/*)
- Chat Routes (/api/chat)
- PDF Routes
- Upload
- Delete
- List
- PDF Chat Routes

**Backend Services:**
- Authentication (NextAuth.js)
- Database (Drizzle)
- PDF Processing
- AI/Chat Processing

##### Key Architectural Patterns to Highlight

- Next.js App Router architecture
- Authentication flow with NextAuth.js
- PDF processing pipeline
- Real-time chat functionality
- Database schema and relationships

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Client
        FE1["PDF Chat Interface"]:::frontend
        FE2["Regular Chat Interface"]:::frontend
        FE3["Authentication Pages"]:::frontend
        FE4["UI Components"]:::frontend
        FE5["Theme Provider"]:::frontend
        FE6["Client Utilities"]:::frontend
    end

    subgraph "Next.js App Router"
        AR1["API Routes"]:::router
        AR2["Server Components"]:::router
        AR3["Client Components"]:::router
        AR4["Middleware"]:::router
    end

    subgraph "Backend Services"
        BS1["Authentication Service"]:::backend
        BS2["PDF Processing Service"]:::backend
        BS3["Chat/AI Service"]:::backend
        BS4["RAG Middleware"]:::backend
    end

    subgraph "Data Layer"
        DB["Database"]:::database
        FS["File Storage"]:::storage
    end

    %% Connections
    FE1 --> AR1
    FE2 --> AR1
    FE3 --> BS1
    AR1 --> BS1
    AR1 --> BS2
    AR1 --> BS3
    BS2 --> FS
    BS3 --> BS4
    BS4 --> FS
    BS1 --> DB
    BS2 --> DB
    BS3 --> DB

    %% Click Events
    click FE1 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/app/(apps)/(pdf)/pdf-chat/page.tsx"
    click FE2 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/app/(apps)/chat/page.tsx"
    click FE3 "https://github.com/Aaryan6/ai-mini-apps/tree/main/src/app/(auth)"
    click FE4 "https://github.com/Aaryan6/ai-mini-apps/tree/main/src/components/ui"
    click FE5 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/components/theme-provider.tsx"
    click FE6 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/utils/fetcher.ts"
    click AR4 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/middleware.ts"
    click BS1 "https://github.com/Aaryan6/ai-mini-apps/tree/main/src/app/(auth)"
    click BS2 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/utils/pdf.ts"
    click BS3 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/app/(apps)/api/chat/route.ts"
    click BS4 "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/app/(apps)/(pdf)/ai/rag-middleware.ts"
    click DB "https://github.com/Aaryan6/ai-mini-apps/blob/main/src/db/schema.ts"

    %% Styles
    classDef frontend fill:#3498db,stroke:#2980b9,color:#fff
    classDef router fill:#2ecc71,stroke:#27ae60,color:#fff
    classDef backend fill:#f1c40f,stroke:#f39c12,color:#000
    classDef database fill:#e74c3c,stroke:#c0392b,color:#fff
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:#fff

    %% Legend
    subgraph Legend
        L1["Frontend Components"]:::frontend
        L2["Router Components"]:::router
        L3["Backend Services"]:::backend
        L4["Database"]:::database
        L5["Storage"]:::storage
    end
```
