# anilkumara9/quill-ai-chat-with-pdf- architecture

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

- Interactive diagram: https://gitdiagram.com/anilkumara9/quill-ai-chat-with-pdf-
- Repository: https://github.com/anilkumara9/quill-ai-chat-with-pdf-

## Overview

##### Project type and purpose
- This is a full-stack, AI-driven document processing and collaboration system (“Quill”) built with Next.js 14 (frontend + API routes) and supplemented by a Python microservice (in the `demo.py/` folder) for AI/document logic.
- The README confirms features like document processing, AI integrations (GPT-3.5/Google AI), secure sharing, and real-time collaboration.

##### File structure
- Top-level:
- `src/app/…` – Next.js App Router (pages, API routes)
- `src/components/…`, `src/lib/…`, `src/hooks/…` – React UI and utility layers
- `prisma/` – database schema and migrations
- `demo.py/` – standalone Python service with modules for AI, auth, config, DB, document logic
- Root config files: `next.config.js`, `tsconfig.json`, `tailwind.config.*`, `package.json`
- API organization: under `src/app/api` you see domain-driven routes (documents, chat, categories, sync-user, webhooks).
- The Python service (`demo.py/`) uses its own `database.py`, `ai_service.py`, and a `main.py` entrypoint—indicating a microservice style alongside the Next.js monolith.

##### README insights
- Tech stack: Next.js, TypeScript, Prisma ORM, Clerk auth, React Query, Tailwind, Radix UI, Google AI.

- Browser / Client (React UI)
- Next.js Frontend (SSR/SSG pages, client-side components)
- Next.js API (App Router endpoints under `src/app/api`)
- Python microservice (`demo.py`)
- Database (PostgreSQL/MySQL via Prisma)
- Authentication service (Clerk)
- External AI provider (Google AI / OpenAI GPT-3.5)
- Optional: File storage or object store if used (S3, etc.)
- Browser → Next.js Frontend (HTTP/HTTPS)
- Frontend ↔ Next.js API (fetch/React Query calls)
- Next.js API → Prisma → Database (SQL queries)
- Next.js API → Clerk (for auth via middleware or API calls)
- Next.js API → Python microservice (HTTP/gRPC) for heavy AI/document workflows
- Next.js API & Python microservice → External AI (Google/OpenAI)
- Python microservice → Database (for document versioning, user mapping)
c. Architectural patterns/design principles:
- Monorepo with polyglot services (Node + Python)
- Domain-driven API routing (documents, chat, categories)
- Microservice for AI-heavy processing (separation of concerns)
- Prisma ORM for DB abstraction
- Middleware for auth (Clerk) and rate-limiting
d. Key technologies:
- Next.js 14 (App Router, API routes)
- TypeScript, React Query, Tailwind, Radix UI
- Prisma (schema.prisma, migrations)
- Clerk (auth middleware)
- Python service (FastAPI/Flask implied) modules: ai_service.py, document_service.py, database.py
- Google AI / OpenAI GPT endpoints

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser / React UI"]:::frontend
    end

    %% Frontend Layer
    subgraph "Next.js Frontend"
        Pages["App Router Pages"]:::frontend
        Layout["Layout & Globals"]:::frontend
        Styles["Global Styles"]:::frontend
    end

    Browser -->|"HTTP/HTTPS"| Pages
    Pages --> Layout
    Pages --> Styles

    %% Server Layer
    subgraph "Server Layer"
        subgraph "Next.js API"  
            AI_API["/api/ai"]:::api
            Docs_API["/api/documents/*"]:::api
            Chat_API["/api/chat/*"]:::api
            Cat_API["/api/categories/*"]:::api
            Sync_API["/api/sync-user"]:::api
            Webhook_API["/api/webhooks/clerk"]:::api
            Middleware["Auth & Rate-limit Middleware"]:::middleware
        end

        subgraph "Python Microservice"
            Py_Main["main.py"]:::ms
            AI_Svc["ai_service.py"]:::ms
            Doc_Svc["document_service.py"]:::ms
            Auth_Py["auth_services.py"]:::ms
            DB_Py["database.py"]:::ms
        end
    end

    %% Client to Server
    Pages -->|"fetch|React Query"| AI_API
    Pages -->|"fetch|React Query"| Docs_API
    Pages -->|"fetch|React Query"| Chat_API
    Pages -->|"fetch|React Query"| Cat_API

    %% Middleware
    AI_API -->|verify via| Middleware
    Docs_API -->|verify via| Middleware
    Chat_API -->|verify via| Middleware
    Cat_API -->|verify via| Middleware
    Sync_API -->|verify via| Middleware
    Webhook_API -->|verify via| Middleware

    %% API to Microservice
    AI_API -->|gRPC/HTTP| Py_Main
    Docs_API -->|gRPC/HTTP| Py_Main

    %% Microservice internal
    Py_Main --> AI_Svc
    Py_Main --> Doc_Svc
    Py_Main --> Auth_Py
    Py_Main --> DB_Py

    %% Database
    subgraph "Database"
        PrismaDB["Prisma DB (PostgreSQL)"]:::db
    end

    Docs_API -->|Prisma| PrismaDB
    AI_API -->|Prisma| PrismaDB
    Chat_API -->|Prisma| PrismaDB
    Cat_API -->|Prisma| PrismaDB
    Sync_API -->|Prisma| PrismaDB
    Py_Main -->|Prisma| PrismaDB

    %% External Services
    subgraph "External Services"
        Clerk["Clerk Auth"]:::ext
        AI_Provider["OpenAI/Google AI"]:::ext
    end

    Middleware --> Clerk
    AI_API -->|HTTP| AI_Provider
    Py_Main -->|HTTP| AI_Provider

    %% Click Events
    click Browser "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/tree/main/src/app"
    click Browser "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/tree/main/src/components"
    click Pages "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/layout.tsx"
    click Styles "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/globals.css"
    click AI_API "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/api/ai/route.ts"
    click Docs_API "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/tree/main/src/app/api/documents"
    click Chat_API "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/api/chat/route.ts"
    click Cat_API "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/api/categories/route.ts"
    click Sync_API "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/api/sync-user/route.ts"
    click Webhook_API "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/src/app/api/webhooks/clerk/route.ts"
    click Middleware "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/middleware.ts"
    click Py_Main "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/demo.py/main.py"
    click AI_Svc "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/demo.py/ai_service.py"
    click Doc_Svc "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/demo.py/document_service.py"
    click Auth_Py "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/demo.py/auth_servies.py"
    click DB_Py "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/demo.py/database.py"
    click PrismaDB "https://github.com/anilkumara9/quill-ai-chat-with-pdf-/blob/main/prisma/schema.prisma"

    %% Styles
    classDef frontend fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef backend fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20
    classDef api fill:#c8e6c9,stroke:#388e3c,color:#1b5e20
    classDef middleware fill:#a5d6a7,stroke:#2e7d32,color:#1b5e20
    classDef ms fill:#fff9c4,stroke:#f9a825,color:#f57f17
    classDef db fill:#eceff1,stroke:#607d8b,color:#37474f
    classDef ext fill:#ffe0b2,stroke:#ef6c00,color:#e65100
```
