# sreeja99sunkara/policypal architecture

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

- Interactive diagram: https://gitdiagram.com/sreeja99sunkara/policypal
- Repository: https://github.com/sreeja99sunkara/policypal

## Overview

PolicyPal is a FastAPI service for indexing insurance-policy PDFs and answering questions with cited, document-grounded responses. Its two user workflows are synchronous PDF ingestion—save, extract and chunk, then index—and querying—check that documents exist, retrieve relevant chunks, generate an answer, and return source text. The graph reflects the sampled routes and service calls; README-documented capabilities supplement them where implementation was not sampled. The configured Chroma persistence directory is not present in the supplied tree, so its node has no repository path.

Main entry points: [`app/services/vectorstore.py`](https://github.com/sreeja99sunkara/policypal/blob/main/app/services/vectorstore.py) (Vector Store Service), [`app/services/rag_chain.py`](https://github.com/sreeja99sunkara/policypal/blob/main/app/services/rag_chain.py) (RAG Chain), [`app/routers/ingestion.py`](https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/ingestion.py) (Upload Route), [`app/routers/query.py`](https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/query.py) (Query Route)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_main["FastAPI App<br/>[main.py]"]
  node_upload["Upload Route<br/>[ingestion.py]"]
  node_query["Query Route<br/>[query.py]"]
  node_schema["Query Schemas<br/>[query.py]"]
end

subgraph group_ingestion["Document Ingestion"]
  node_rawfiles["Uploaded PDFs"]
  node_loader["PDF Loader And Chunker<br/>[document_loader.py]"]
end

subgraph group_answering["Retrieval And Answering"]
  node_rag["RAG Chain<br/>[rag_chain.py]"]
  node_prompt["QA Prompt<br/>[qa_prompt.py]"]
  node_answer["Answer And Sources<br/>[query.py]"]
end

subgraph group_integrations["Models And Storage"]
  node_vectorstore["Vector Store Service<br/>[vectorstore.py]"]
  node_embeddings["Embedding Model<br/>[embedder.py]"]
  node_chromadb[("Chroma Store")]
  node_groq["Groq LLM"]
end

node_user(("User"))

node_user -->|"sends requests"| node_main
node_main -->|"registers route"| node_upload
node_main -->|"registers route"| node_query
node_user -->|"uploads PDF"| node_upload
node_upload -->|"writes PDF"| node_rawfiles
node_upload -->|"loads and chunks"| node_loader
node_upload -->|"ingests chunks"| node_vectorstore
node_loader -->|"reads PDF"| node_rawfiles
node_vectorstore -->|"gets embeddings"| node_embeddings
node_vectorstore -->|"replaces index"| node_chromadb
node_user -->|"asks question"| node_query
node_query -->|"validates request"| node_schema
node_query -->|"checks documents"| node_vectorstore
node_query -->|"invokes chain"| node_rag
node_rag -->|"retrieves chunks"| node_vectorstore
node_vectorstore -->|"reads vectors"| node_chromadb
node_rag -->|"formats context"| node_prompt
node_rag -->|"requests completion"| node_groq
node_rag -->|"returns results"| node_answer
node_answer -->|"returns citations"| node_user

click node_main "https://github.com/sreeja99sunkara/policypal/blob/main/app/main.py"
click node_upload "https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/ingestion.py"
click node_query "https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/query.py"
click node_schema "https://github.com/sreeja99sunkara/policypal/blob/main/app/schemas/query.py"
click node_rawfiles "https://github.com/sreeja99sunkara/policypal/tree/main/data/raw"
click node_loader "https://github.com/sreeja99sunkara/policypal/blob/main/app/services/document_loader.py"
click node_vectorstore "https://github.com/sreeja99sunkara/policypal/blob/main/app/services/vectorstore.py"
click node_embeddings "https://github.com/sreeja99sunkara/policypal/blob/main/app/services/embedder.py"
click node_rag "https://github.com/sreeja99sunkara/policypal/blob/main/app/services/rag_chain.py"
click node_prompt "https://github.com/sreeja99sunkara/policypal/blob/main/app/prompts/qa_prompt.py"
click node_answer "https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/query.py"

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_main,node_upload,node_query,node_schema,node_user toneBlue
class node_rawfiles,node_loader toneAmber
class node_rag,node_prompt,node_answer toneMint
class node_vectorstore,node_embeddings,node_chromadb,node_groq toneRose
```

## Components

### API

- [FastAPI App](https://github.com/sreeja99sunkara/policypal/blob/main/app/main.py): `app/main.py`
- [Upload Route](https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/ingestion.py): `app/routers/ingestion.py`
- [Query Route](https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/query.py): `app/routers/query.py`
- [Query Schemas](https://github.com/sreeja99sunkara/policypal/blob/main/app/schemas/query.py): `app/schemas/query.py`

### Document Ingestion

- [Uploaded PDFs](https://github.com/sreeja99sunkara/policypal/tree/main/data/raw): `data/raw`
- [PDF Loader And Chunker](https://github.com/sreeja99sunkara/policypal/blob/main/app/services/document_loader.py): `app/services/document_loader.py`

### Retrieval And Answering

- [RAG Chain](https://github.com/sreeja99sunkara/policypal/blob/main/app/services/rag_chain.py): `app/services/rag_chain.py`
- [QA Prompt](https://github.com/sreeja99sunkara/policypal/blob/main/app/prompts/qa_prompt.py): `app/prompts/qa_prompt.py`
- [Answer And Sources](https://github.com/sreeja99sunkara/policypal/blob/main/app/routers/query.py): `app/routers/query.py`

### Models And Storage

- [Vector Store Service](https://github.com/sreeja99sunkara/policypal/blob/main/app/services/vectorstore.py): `app/services/vectorstore.py`
- [Embedding Model](https://github.com/sreeja99sunkara/policypal/blob/main/app/services/embedder.py): `app/services/embedder.py`
- **Chroma Store**
- **Groq LLM**

### Other components

- **User**

## Connections

- User → FastAPI App: sends requests
- FastAPI App → Upload Route: registers route
- FastAPI App → Query Route: registers route
- User → Upload Route: uploads PDF
- Upload Route → Uploaded PDFs: writes PDF
- Upload Route → PDF Loader And Chunker: loads and chunks
- Upload Route → Vector Store Service: ingests chunks
- PDF Loader And Chunker → Uploaded PDFs: reads PDF
- Vector Store Service → Embedding Model: gets embeddings
- Vector Store Service → Chroma Store: replaces index
- User → Query Route: asks question
- Query Route → Query Schemas: validates request
- Query Route → Vector Store Service: checks documents
- Query Route → RAG Chain: invokes chain
- RAG Chain → Vector Store Service: retrieves chunks
- Vector Store Service → Chroma Store: reads vectors
- RAG Chain → QA Prompt: formats context
- RAG Chain → Groq LLM: requests completion
- RAG Chain → Answer And Sources: returns results
- Answer And Sources → User: returns citations
