# arun-232007/ai-multimodal-rag architecture

> Architecture diagram of the GitHub repository arun-232007/ai-multimodal-rag, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/arun-232007/ai-multimodal-rag
- Repository: https://github.com/arun-232007/ai-multimodal-rag

## Overview

This is a FastAPI backend for document-grounded PDF chat. The principal workflow is PDF upload, text extraction and chunking, embedding and storage, followed by query embedding, vector retrieval, answer generation, and returning source chunks. Session creation and chat-history retrieval are additional API capabilities. The sampled routes show orchestration and persistence calls; the README documents the Supabase schema and vector-search RPC. The SQL file and frontend were not sampled, so their internal behavior is not expanded.

Main entry points: [`routes/upload.py`](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/upload.py) (Upload Handler), [`routes/chat.py`](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py) (Chat Handler), [`app.py`](https://github.com/arun-232007/ai-multimodal-rag/blob/main/app.py) (FastAPI App), [`config.py`](https://github.com/arun-232007/ai-multimodal-rag/blob/main/config.py) (Client Configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_app["FastAPI App<br/>[app.py]"]
  node_contracts["API Models<br/>[schemas.py]"]
end

subgraph group_ingestion["PDF Ingestion"]
  node_upload["Upload Handler<br/>[upload.py]"]
  node_pdf["PDF Extraction<br/>[utils.py]"]
  node_chunking["Text Chunking<br/>[utils.py]"]
  node_upload_embedding["Document Embedding<br/>[upload.py]"]
end

subgraph group_chat["Retrieval and Chat"]
  node_chat["Chat Handler<br/>[chat.py]"]
  node_query_embedding["Query Embedding<br/>[chat.py]"]
  node_retrieval["Vector Retrieval<br/>[chat.py]"]
  node_answer["Answer Generation<br/>[chat.py]"]
end

subgraph group_platform["Data and Configuration"]
  node_config["Client Configuration<br/>[config.py]"]
  node_database[("Supabase Database")]
  node_storage[("Supabase Storage")]
  node_schema["Database Schema<br/>[supabase_setup.sql]"]
end

node_client(("API Client"))
node_cohere{{"Cohere API"}}

node_client -->|"sends requests"| node_app
node_app -->|"registers router"| node_upload
node_app -->|"registers router"| node_chat
node_upload -->|"returns model"| node_contracts
node_chat -->|"uses models"| node_contracts
node_upload -->|"extracts text"| node_pdf
node_upload -->|"chunks text"| node_chunking
node_upload -->|"embeds chunks"| node_upload_embedding
node_upload_embedding -->|"requests embeddings"| node_cohere
node_upload -->|"writes session and records"| node_database
node_upload -->|"uploads PDF"| node_storage
node_chat -->|"checks session and saves messages"| node_database
node_chat -->|"embeds question"| node_query_embedding
node_query_embedding -->|"requests embeddings"| node_cohere
node_chat -->|"retrieves matching chunks"| node_retrieval
node_retrieval -->|"calls vector search"| node_database
node_chat -->|"generates answer"| node_answer
node_answer -->|"requests chat completion"| node_cohere
node_config -->|"creates client"| node_database
node_config -->|"creates client"| node_cohere
node_schema -->|"defines tables and RPC"| node_database

click node_app "https://github.com/arun-232007/ai-multimodal-rag/blob/main/app.py"
click node_upload "https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/upload.py"
click node_pdf "https://github.com/arun-232007/ai-multimodal-rag/blob/main/utils.py"
click node_chunking "https://github.com/arun-232007/ai-multimodal-rag/blob/main/utils.py"
click node_upload_embedding "https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/upload.py"
click node_chat "https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py"
click node_query_embedding "https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py"
click node_retrieval "https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py"
click node_answer "https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py"
click node_contracts "https://github.com/arun-232007/ai-multimodal-rag/blob/main/schemas.py"
click node_config "https://github.com/arun-232007/ai-multimodal-rag/blob/main/config.py"
click node_schema "https://github.com/arun-232007/ai-multimodal-rag/blob/main/supabase_setup.sql"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_app,node_contracts,node_client toneBlue
class node_upload,node_pdf,node_chunking,node_upload_embedding toneAmber
class node_chat,node_query_embedding,node_retrieval,node_answer,node_cohere toneMint
class node_config,node_database,node_storage,node_schema toneRose
```

## Components

### API

- [FastAPI App](https://github.com/arun-232007/ai-multimodal-rag/blob/main/app.py): `app.py`
- [API Models](https://github.com/arun-232007/ai-multimodal-rag/blob/main/schemas.py): `schemas.py`

### PDF Ingestion

- [Upload Handler](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/upload.py): `routes/upload.py`
- [PDF Extraction](https://github.com/arun-232007/ai-multimodal-rag/blob/main/utils.py): `utils.py`
- [Text Chunking](https://github.com/arun-232007/ai-multimodal-rag/blob/main/utils.py): `utils.py`
- [Document Embedding](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/upload.py): `routes/upload.py`

### Retrieval and Chat

- [Chat Handler](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py): `routes/chat.py`
- [Query Embedding](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py): `routes/chat.py`
- [Vector Retrieval](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py): `routes/chat.py`
- [Answer Generation](https://github.com/arun-232007/ai-multimodal-rag/blob/main/routes/chat.py): `routes/chat.py`

### Data and Configuration

- [Client Configuration](https://github.com/arun-232007/ai-multimodal-rag/blob/main/config.py): `config.py`
- **Supabase Database**
- **Supabase Storage**
- [Database Schema](https://github.com/arun-232007/ai-multimodal-rag/blob/main/supabase_setup.sql): `supabase_setup.sql`

### Other components

- **API Client**
- **Cohere API**

## Connections

- API Client → FastAPI App: sends requests (evidence: `README.md`)
- FastAPI App → Upload Handler: registers router (evidence: `app.py`)
- FastAPI App → Chat Handler: registers router (evidence: `app.py`)
- Upload Handler → API Models: returns model (evidence: `routes/upload.py`)
- Chat Handler → API Models: uses models (evidence: `routes/chat.py`)
- Upload Handler → PDF Extraction: extracts text (evidence: `routes/upload.py`)
- Upload Handler → Text Chunking: chunks text (evidence: `routes/upload.py`)
- Upload Handler → Document Embedding: embeds chunks (evidence: `routes/upload.py`)
- Document Embedding → Cohere API: requests embeddings (evidence: `routes/upload.py`)
- Upload Handler → Supabase Database: writes session and records (evidence: `routes/upload.py`)
- Upload Handler → Supabase Storage: uploads PDF (evidence: `routes/upload.py`)
- Chat Handler → Supabase Database: checks session and saves messages (evidence: `routes/chat.py`)
- Chat Handler → Query Embedding: embeds question (evidence: `routes/chat.py`)
- Query Embedding → Cohere API: requests embeddings (evidence: `routes/chat.py`)
- Chat Handler → Vector Retrieval: retrieves matching chunks (evidence: `routes/chat.py`)
- Vector Retrieval → Supabase Database: calls vector search (evidence: `routes/chat.py`)
- Chat Handler → Answer Generation: generates answer (evidence: `routes/chat.py`)
- Answer Generation → Cohere API: requests chat completion (evidence: `routes/chat.py`)
- Client Configuration → Supabase Database: creates client (evidence: `config.py`)
- Client Configuration → Cohere API: creates client (evidence: `config.py`)
- Database Schema → Supabase Database: defines tables and RPC (evidence: `README.md`)
