# archiecodespiece/patrarekhaai architecture

> Architecture diagram of the GitHub repository archiecodespiece/patrarekhaai, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/archiecodespiece/patrarekhaai
- Repository: https://github.com/archiecodespiece/patrarekhaai

## Overview

PatraRekha’s documented primary workflow takes a PDF through preprocessing, semantic chunking, Gemini embeddings, and Pinecone upsert; Pinecone also supports search and deletion. The repository additionally contains a web interface and a Supabase-backed file/email backend, but the excerpts do not establish an end-to-end connection from those interfaces to vector search. Edges reflect shown calls, source-index references, or README-documented stages; unsampled wiring is omitted.

Main entry points: [`main.py`](https://github.com/archiecodespiece/patrarekhaai/blob/master/main.py) (Pipeline entrypoint), [`document preprocessing/pdf_processor.py`](https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/pdf_processor.py) (PDF processing), [`AI pipeline/Chunking/pipeline.py`](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/pipeline.py) (Chunk pipeline), [`AI pipeline/embedding/pipeline.py`](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/embedding/pipeline.py) (Embedding pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_preprocessing["Document preprocessing"]
  node_pdf_processing["PDF processing<br/>[pdf_processor.py]"]
  node_ocr["OCR engine<br/>[ocr_engine.py]"]
  node_table_extraction["Table extraction"]
  node_text_cleaning["Text cleaning<br/>[text_cleaner.py]"]
  node_metadata["Document metadata"]
end

subgraph group_pipeline["AI ingestion pipeline"]
  node_main["Pipeline entrypoint<br/>[main.py]"]
  node_chunk_pipeline["Chunk pipeline<br/>[pipeline.py]"]
  node_chunk_models["Document and chunk models<br/>[models.py]"]
  node_semantic_chunking["Semantic chunking<br/>[semantic.py]"]
  node_chunk_splitter["Token chunk splitter<br/>[splitter1.py]"]
  node_embedding_pipeline["Embedding pipeline<br/>[pipeline.py]"]
  node_embedding_models["Embedding results<br/>[models.py]"]
end

subgraph group_storage["File and vector storage"]
  node_vector_pipeline["Vector store pipeline<br/>[pipeline.py]"]
  node_pinecone_store["Pinecone connector<br/>[pinecone_store.py]"]
  node_backend_api["Backend API<br/>[main.py]"]
  node_email_ingestion["Email ingestion<br/>[ingest.py]"]
  node_file_storage["File operations<br/>[files.py]"]
end

subgraph group_application["Web application"]
  node_home_page["Home page<br/>[page.js]"]
  node_sidebar["Navigation sidebar<br/>[sidebar.jsx]"]
  node_chat_page["Chat page<br/>[page.js]"]
  node_chat_ui["PDF chat interface<br/>[chatpdf.jsx]"]
  node_calendar_page["Calendar page<br/>[page.js]"]
  node_calendar_ui["Calendar interface<br/>[calendar.jsx]"]
end

node_user(("PDF user"))
node_gemini{{"Gemini API"}}
node_pinecone[("Pinecone index")]
node_supabase[("Supabase")]
node_web_user(("Web user"))

node_user -->|"submits PDF"| node_main
node_main -->|"preprocesses PDF"| node_pdf_processing
node_pdf_processing -->|"runs OCR"| node_ocr
node_ocr -->|"reconstructs tables"| node_table_extraction
node_pdf_processing -->|"extracts tables"| node_table_extraction
node_pdf_processing -->|"cleans text"| node_text_cleaning
node_main -->|"chunks JSON"| node_chunk_pipeline
node_chunk_pipeline -->|"builds documents"| node_chunk_models
node_chunk_pipeline -->|"processes document"| node_semantic_chunking
node_semantic_chunking -->|"uses models"| node_chunk_models
node_chunk_splitter -->|"uses models"| node_chunk_models
node_main -->|"embeds chunks"| node_embedding_pipeline
node_embedding_pipeline -->|"builds results"| node_embedding_models
node_embedding_pipeline -->|"requests embeddings"| node_gemini
node_main -->|"uploads embeddings"| node_vector_pipeline
node_vector_pipeline -->|"delegates storage"| node_pinecone_store
node_pinecone_store -->|"upserts and queries"| node_pinecone
node_backend_api -->|"uses file operations"| node_file_storage
node_email_ingestion -->|"uses file operations"| node_file_storage
node_file_storage -->|"stores and lists files"| node_supabase
node_web_user -->|"uses web app"| node_home_page
node_home_page -->|"renders navigation"| node_sidebar
node_chat_page -->|"renders chat"| node_chat_ui
node_calendar_page -->|"renders calendar"| node_calendar_ui

click node_main "https://github.com/archiecodespiece/patrarekhaai/blob/master/main.py"
click node_pdf_processing "https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/pdf_processor.py"
click node_ocr "https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/ocr_engine.py"
click node_table_extraction "https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/table_extraction.py"
click node_text_cleaning "https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/text_cleaner.py"
click node_metadata "https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/document_metadata.py"
click node_chunk_pipeline "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/pipeline.py"
click node_chunk_models "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/models.py"
click node_semantic_chunking "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/semantic.py"
click node_chunk_splitter "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/splitter1.py"
click node_embedding_pipeline "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/embedding/pipeline.py"
click node_embedding_models "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/embedding/models.py"
click node_vector_pipeline "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/vectorstore/pipeline.py"
click node_pinecone_store "https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/vectorstore/pinecone_store.py"
click node_backend_api "https://github.com/archiecodespiece/patrarekhaai/blob/master/backend/api/main.py"
click node_email_ingestion "https://github.com/archiecodespiece/patrarekhaai/blob/master/backend/email-ingestion/ingest.py"
click node_file_storage "https://github.com/archiecodespiece/patrarekhaai/blob/master/backend/db/files.py"
click node_home_page "https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/app/page.js"
click node_sidebar "https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/components/sidebar.jsx"
click node_chat_page "https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/app/chat/page.js"
click node_chat_ui "https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/components/chatpdf.jsx"
click node_calendar_page "https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/app/calendar/page.js"
click node_calendar_ui "https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/components/calendar.jsx"

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_pdf_processing,node_ocr,node_table_extraction,node_text_cleaning,node_metadata,node_user,node_web_user toneBlue
class node_main,node_chunk_pipeline,node_chunk_models,node_semantic_chunking,node_chunk_splitter,node_embedding_pipeline,node_embedding_models,node_pinecone,node_supabase toneAmber
class node_vector_pipeline,node_pinecone_store,node_backend_api,node_email_ingestion,node_file_storage,node_gemini toneMint
class node_home_page,node_sidebar,node_chat_page,node_chat_ui,node_calendar_page,node_calendar_ui toneRose
```

## Components

### Document preprocessing

- [PDF processing](https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/pdf_processor.py): `document preprocessing/pdf_processor.py`
- [OCR engine](https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/ocr_engine.py): `document preprocessing/ocr_engine.py`
- [Table extraction](https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/table_extraction.py): `document preprocessing/table_extraction.py`
- [Text cleaning](https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/text_cleaner.py): `document preprocessing/text_cleaner.py`
- [Document metadata](https://github.com/archiecodespiece/patrarekhaai/blob/master/document%20preprocessing/document_metadata.py): `document preprocessing/document_metadata.py`

### AI ingestion pipeline

- [Pipeline entrypoint](https://github.com/archiecodespiece/patrarekhaai/blob/master/main.py): `main.py`
- [Chunk pipeline](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/pipeline.py): `AI pipeline/Chunking/pipeline.py`
- [Document and chunk models](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/models.py): `AI pipeline/Chunking/models.py`
- [Semantic chunking](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/semantic.py): `AI pipeline/Chunking/semantic.py`
- [Token chunk splitter](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/Chunking/splitter1.py): `AI pipeline/Chunking/splitter1.py`
- [Embedding pipeline](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/embedding/pipeline.py): `AI pipeline/embedding/pipeline.py`
- [Embedding results](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/embedding/models.py): `AI pipeline/embedding/models.py`

### File and vector storage

- [Vector store pipeline](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/vectorstore/pipeline.py): `AI pipeline/vectorstore/pipeline.py`
- [Pinecone connector](https://github.com/archiecodespiece/patrarekhaai/blob/master/AI%20pipeline/vectorstore/pinecone_store.py): `AI pipeline/vectorstore/pinecone_store.py`
- [Backend API](https://github.com/archiecodespiece/patrarekhaai/blob/master/backend/api/main.py): `backend/api/main.py`
- [Email ingestion](https://github.com/archiecodespiece/patrarekhaai/blob/master/backend/email-ingestion/ingest.py): `backend/email-ingestion/ingest.py`
- [File operations](https://github.com/archiecodespiece/patrarekhaai/blob/master/backend/db/files.py): `backend/db/files.py`

### Web application

- [Home page](https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/app/page.js): `frontend/src/app/page.js`
- [Navigation sidebar](https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/components/sidebar.jsx): `frontend/src/components/sidebar.jsx`
- [Chat page](https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/app/chat/page.js): `frontend/src/app/chat/page.js`
- [PDF chat interface](https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/components/chatpdf.jsx): `frontend/src/components/chatpdf.jsx`
- [Calendar page](https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/app/calendar/page.js): `frontend/src/app/calendar/page.js`
- [Calendar interface](https://github.com/archiecodespiece/patrarekhaai/blob/master/frontend/src/components/calendar.jsx): `frontend/src/components/calendar.jsx`

### Other components

- **PDF user**
- **Gemini API**
- **Pinecone index**
- **Supabase**
- **Web user**

## Connections

- PDF user → Pipeline entrypoint: submits PDF
- Pipeline entrypoint → PDF processing: preprocesses PDF (evidence: `main.py`)
- PDF processing → OCR engine: runs OCR (evidence: `document preprocessing/pdf_processor.py`)
- OCR engine → Table extraction: reconstructs tables (evidence: `document preprocessing/ocr_engine.py`)
- PDF processing → Table extraction: extracts tables (evidence: `document preprocessing/pdf_processor.py`)
- PDF processing → Text cleaning: cleans text (evidence: `document preprocessing/pdf_processor.py`)
- Pipeline entrypoint → Chunk pipeline: chunks JSON (evidence: `main.py`)
- Chunk pipeline → Document and chunk models: builds documents (evidence: `AI pipeline/Chunking/pipeline.py`)
- Chunk pipeline → Semantic chunking: processes document (evidence: `AI pipeline/Chunking/pipeline.py`)
- Semantic chunking → Document and chunk models: uses models (evidence: `AI pipeline/Chunking/semantic.py`)
- Token chunk splitter → Document and chunk models: uses models (evidence: `AI pipeline/Chunking/splitter1.py`)
- Pipeline entrypoint → Embedding pipeline: embeds chunks (evidence: `main.py`)
- Embedding pipeline → Embedding results: builds results (evidence: `AI pipeline/embedding/pipeline.py`)
- Embedding pipeline → Gemini API: requests embeddings
- Pipeline entrypoint → Vector store pipeline: uploads embeddings (evidence: `main.py`)
- Vector store pipeline → Pinecone connector: delegates storage (evidence: `AI pipeline/vectorstore/pipeline.py`)
- Pinecone connector → Pinecone index: upserts and queries (evidence: `AI pipeline/vectorstore/pinecone_store.py`)
- Backend API → File operations: uses file operations (evidence: `backend/api/main.py`)
- Email ingestion → File operations: uses file operations (evidence: `backend/email-ingestion/ingest.py`)
- File operations → Supabase: stores and lists files (evidence: `backend/db/files.py`)
- Web user → Home page: uses web app (evidence: `frontend/src/app/page.js`)
- Home page → Navigation sidebar: renders navigation
- Chat page → PDF chat interface: renders chat (evidence: `frontend/src/app/chat/page.js`)
- Calendar page → Calendar interface: renders calendar (evidence: `frontend/src/app/calendar/page.js`)
