# vedbabar/chat-with-pdf architecture

> Architecture diagram of the GitHub repository vedbabar/chat-with-pdf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vedbabar/chat-with-pdf
- Repository: https://github.com/vedbabar/chat-with-pdf

## Overview

##### Project type and purpose
- This is a full-stack, multi-tenant web application (“Chat with PDF AI”) that lets authenticated users upload PDF documents, then chat with an AI agent (Google Gemini) about their content.
- It comprises a React/Next.js frontend, a Node/Express backend, a background worker, and three data stores (PostgreSQL via Prisma, Redis for queuing, Qdrant for vector search).

##### File structure
- Top-level:
– client/ (Next.js + TypeScript + Tailwind + Clerk for auth)
– server/ (Express API in index.js, Prisma schema & migrations, file upload directory, a worker.js)
– docker-compose.yml (orchestrates PostgreSQL, Redis, Qdrant)
- Patterns:
– client/app/components → UI and page components (chat view, file upload, sign-in/up)
– server/prisma → database schema and migrations (users, chats, file metadata, vector references)
– server/uploads → persistent PDF storage
– server/index.js → HTTP API endpoints (authentication middleware, file upload, chat management, question endpoints)
– server/worker.js → BullMQ + Redis job consumer, handles PDF parsing, embedding and vector insertion via Qdrant

##### README for additional insights
- Auth: Clerk (publishable + secret keys)
- Background Processing: BullMQ + Redis
- Vector Search: Qdrant
- AI: Google Gemini via LangChain.js
- Database: PostgreSQL via Prisma

##### Detail
- Environment variables or config points next to each component (e.g., .env for API, .env.local for Frontend).
- Port numbers (3000 for Next.js, 8000 for Express).
- Docker services for Redis, PostgreSQL, Qdrant from docker-compose.yml.

## Diagram (Mermaid)

```mermaid
graph TB
    User["User"]:::user
    Browser["Browser"]:::user

    User -->|"interacts via HTTP"| Browser

    subgraph "Frontend (Next.js)"
        direction TB
        FrontendUI["UI Components"]:::frontend
        LayoutPages["Layout & Pages"]:::frontend
        Middleware["Middleware (Clerk)"]:::frontend
    end

    Browser -->|"HTTP REST"| FrontendUI
    FrontendUI -->|"uses pages"| LayoutPages
    LayoutPages -->|"uses middleware"| Middleware
    FrontendUI -->|"OAuth/session"| Clerk

    Clerk["Clerk Auth Service"]:::external

    click FrontendUI "https://github.com/vedbabar/chat-with-pdf/tree/main/client/app/components/"
    click LayoutPages "https://github.com/vedbabar/chat-with-pdf/blob/main/client/app/layout.tsx"
    click LayoutPages "https://github.com/vedbabar/chat-with-pdf/blob/main/client/app/page.tsx"
    click Middleware "https://github.com/vedbabar/chat-with-pdf/blob/main/client/middleware.ts"

    subgraph "Backend Service (Express.js)"
        direction TB
        BackendAPI["API Endpoints"]:::backend
        FileStorage["File Storage"]:::backend
    end

    click BackendAPI "https://github.com/vedbabar/chat-with-pdf/blob/main/server/index.js"
    click FileStorage "https://github.com/vedbabar/chat-with-pdf/tree/main/server/uploads/"

    FrontendUI -->|"REST API calls"| BackendAPI

    subgraph "Background Worker"
        direction TB
        Queue["Redis Queue (BullMQ)"]:::async
        Worker["Worker"]:::async
    end

    click Worker "https://github.com/vedbabar/chat-with-pdf/blob/main/server/worker.js"
    click Queue "https://github.com/vedbabar/chat-with-pdf/blob/main/docker-compose.yml"

    BackendAPI -->|"enqueue PDF job"| Queue
    Worker -->|"consume job & parse PDF"| FileStorage
    Worker -->|"update file status"| PostgreSQL
    Worker -->|"insert embeddings"| Qdrant

    subgraph "Data Layer"
        direction TB
        PostgreSQL["PostgreSQL (Prisma)"]:::backend
        Qdrant["Qdrant Vector DB"]:::backend
    end

    click PostgreSQL "https://github.com/vedbabar/chat-with-pdf/blob/main/server/prisma/schema.prisma"
    click PostgreSQL "https://github.com/vedbabar/chat-with-pdf/tree/main/server/prisma/migrations/"
    click Qdrant "https://github.com/vedbabar/chat-with-pdf/blob/main/docker-compose.yml"

    BackendAPI -->|"CRUD metadata"| PostgreSQL
    BackendAPI -->|"semantic queries"| Qdrant
    BackendAPI -->|"send prompt"| GoogleAI

    GoogleAI["Google Gemini (LangChain.js)"]:::external

    click GoogleAI "https://github.com/vedbabar/chat-with-pdf/blob/main/server/index.js"

    GoogleAI -->|"AI response"| BackendAPI
    BackendAPI -->|"AI answer"| FrontendUI

    classDef user fill:#DDEEFF,stroke:#000
    classDef frontend fill:#CCE5FF,stroke:#0366d6
    classDef backend fill:#DFF5E1,stroke:#28a745
    classDef async fill:#FFE5CC,stroke:#FF8C00
    classDef external fill:#E5CCFF,stroke:#800080
```
