# kashifali-it/contexta architecture

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

- Interactive diagram: https://gitdiagram.com/kashifali-it/contexta
- Repository: https://github.com/kashifali-it/contexta

## Overview

Contexta Py is an asynchronous document Q&A platform. Its implemented path accepts a PDF through the document API, stores the file and record, queues ingestion, and has a worker parse and chunk it before updating document state. The README also describes a broader agentic RAG path—hybrid retrieval, grading, fallback web search, streaming answers, and TTS—but those implementations are not present in the sampled source or populated tree. Those documented capabilities are shown as such; edges without source evidence are omitted.

Main entry points: [`backend/app/services/ingestion.py`](https://github.com/kashifali-it/contexta/blob/main/backend/app/services/ingestion.py) (Ingestion service), [`backend/app/api/v1/documents.py`](https://github.com/kashifali-it/contexta/blob/main/backend/app/api/v1/documents.py) (Document API), [`frontend`](https://github.com/kashifali-it/contexta/tree/main/frontend) (Next.js client), [`backend/app/agents/nodes`](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes) (Agent engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and documents"]
  node_client["Next.js client"]
  node_document_api["Document API<br/>[documents.py]"]
  node_api_router["API router<br/>[router.py]"]
end

subgraph group_ingest["Ingestion pipeline"]
  node_worker["Ingestion worker<br/>[tasks.py]"]
  node_ingestion["Ingestion service<br/>[ingestion.py]"]
  node_pdf_parser["PDF parser<br/>[parser.py]"]
  node_chunker["Chunker<br/>[chunker.py]"]
  node_llm["LLM client<br/>[llm.py]"]
end

subgraph group_rag["Agentic Q&amp;A"]
  node_agent_engine["Agent engine"]
  node_hybrid_search["Hybrid retrieval"]
  node_grader["Relevance grader"]
  node_answer["Answer generator"]
  node_web_search["Web fallback"]
  node_tts["Text-to-speech"]
end

subgraph group_state["State and storage"]
  node_postgres[("PostgreSQL")]
  node_redis["Redis queue"]
  node_object_store[("Object storage<br/>[storage.py]")]
  node_vector_store[("Vector store")]
  node_tavily["Tavily search"]
  node_edge_tts["Edge TTS"]
end

node_user(("User"))

node_user -->|"uploads PDF"| node_client
node_client -->|"sends request"| node_document_api
node_api_router -->|"registers routes"| node_document_api
node_document_api -->|"stores file"| node_object_store
node_document_api -->|"creates record"| node_postgres
node_document_api -->|"enqueues job"| node_redis
node_worker -->|"runs ingestion"| node_ingestion
node_ingestion -->|"fetches file"| node_object_store
node_ingestion -->|"parses document"| node_pdf_parser
node_ingestion -->|"creates chunks"| node_chunker
node_ingestion -->|"summarizes tables"| node_llm
node_ingestion -->|"updates status"| node_postgres
node_user -.->|"asks question"| node_agent_engine
node_agent_engine -.->|"dispatches retrieval"| node_hybrid_search
node_hybrid_search -.->|"searches chunks"| node_vector_store
node_agent_engine -.->|"checks relevance"| node_grader
node_grader -.->|"passes relevant chunks"| node_answer
node_grader -.->|"falls back"| node_web_search
node_answer -.->|"streams answer"| node_client
node_client -.->|"requests speech"| node_tts
node_tts -.->|"generates audio"| node_edge_tts
node_web_search -.->|"searches web"| node_tavily

click node_client "https://github.com/kashifali-it/contexta/tree/main/frontend"
click node_document_api "https://github.com/kashifali-it/contexta/blob/main/backend/app/api/v1/documents.py"
click node_api_router "https://github.com/kashifali-it/contexta/blob/main/backend/app/api/v1/router.py"
click node_worker "https://github.com/kashifali-it/contexta/blob/main/backend/app/workers/tasks.py"
click node_ingestion "https://github.com/kashifali-it/contexta/blob/main/backend/app/services/ingestion.py"
click node_pdf_parser "https://github.com/kashifali-it/contexta/blob/main/backend/app/services/parser.py"
click node_chunker "https://github.com/kashifali-it/contexta/blob/main/backend/app/services/chunker.py"
click node_llm "https://github.com/kashifali-it/contexta/blob/main/backend/app/services/llm.py"
click node_agent_engine "https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes"
click node_hybrid_search "https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes"
click node_grader "https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes"
click node_answer "https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes"
click node_web_search "https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes"
click node_tts "https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes"
click node_object_store "https://github.com/kashifali-it/contexta/blob/main/backend/app/services/storage.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_client,node_document_api,node_api_router,node_user toneBlue
class node_worker,node_ingestion,node_pdf_parser,node_chunker,node_llm toneAmber
class node_agent_engine,node_hybrid_search,node_grader,node_answer,node_web_search,node_tts toneMint
class node_postgres,node_redis,node_object_store,node_vector_store,node_tavily,node_edge_tts toneRose
```

## Components

### API and documents

- [Next.js client](https://github.com/kashifali-it/contexta/tree/main/frontend): `frontend`
- [Document API](https://github.com/kashifali-it/contexta/blob/main/backend/app/api/v1/documents.py): `backend/app/api/v1/documents.py`
- [API router](https://github.com/kashifali-it/contexta/blob/main/backend/app/api/v1/router.py): `backend/app/api/v1/router.py`

### Ingestion pipeline

- [Ingestion worker](https://github.com/kashifali-it/contexta/blob/main/backend/app/workers/tasks.py): `backend/app/workers/tasks.py`
- [Ingestion service](https://github.com/kashifali-it/contexta/blob/main/backend/app/services/ingestion.py): `backend/app/services/ingestion.py`
- [PDF parser](https://github.com/kashifali-it/contexta/blob/main/backend/app/services/parser.py): `backend/app/services/parser.py`
- [Chunker](https://github.com/kashifali-it/contexta/blob/main/backend/app/services/chunker.py): `backend/app/services/chunker.py`
- [LLM client](https://github.com/kashifali-it/contexta/blob/main/backend/app/services/llm.py): `backend/app/services/llm.py`

### Agentic Q&A

- [Agent engine](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes): `backend/app/agents/nodes`
- [Hybrid retrieval](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes): `backend/app/agents/nodes`
- [Relevance grader](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes): `backend/app/agents/nodes`
- [Answer generator](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes): `backend/app/agents/nodes`
- [Web fallback](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes): `backend/app/agents/nodes`
- [Text-to-speech](https://github.com/kashifali-it/contexta/tree/main/backend/app/agents/nodes): `backend/app/agents/nodes`

### State and storage

- **PostgreSQL**
- **Redis queue**
- [Object storage](https://github.com/kashifali-it/contexta/blob/main/backend/app/services/storage.py): `backend/app/services/storage.py`
- **Vector store**
- **Tavily search**
- **Edge TTS**

### Other components

- **User**

## Connections

- User → Next.js client: uploads PDF (evidence: `README.md`)
- Next.js client → Document API: sends request (evidence: `README.md`)
- API router → Document API: registers routes (evidence: `backend/app/api/v1/router.py`)
- Document API → Object storage: stores file (evidence: `backend/app/api/v1/documents.py`)
- Document API → PostgreSQL: creates record (evidence: `README.md`)
- Document API → Redis queue: enqueues job
- Ingestion worker → Ingestion service: runs ingestion (evidence: `backend/app/workers/tasks.py`)
- Ingestion service → Object storage: fetches file (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → PDF parser: parses document (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → Chunker: creates chunks (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → LLM client: summarizes tables (evidence: `backend/app/services/ingestion.py`)
- Ingestion service → PostgreSQL: updates status (evidence: `backend/app/services/ingestion.py`)
- User → Agent engine: asks question (evidence: `README.md`)
- Agent engine → Hybrid retrieval: dispatches retrieval (evidence: `README.md`)
- Hybrid retrieval → Vector store: searches chunks (evidence: `README.md`)
- Agent engine → Relevance grader: checks relevance (evidence: `README.md`)
- Relevance grader → Answer generator: passes relevant chunks (evidence: `README.md`)
- Relevance grader → Web fallback: falls back (evidence: `README.md`)
- Answer generator → Next.js client: streams answer (evidence: `README.md`)
- Next.js client → Text-to-speech: requests speech (evidence: `README.md`)
- Text-to-speech → Edge TTS: generates audio (evidence: `README.md`)
- Web fallback → Tavily search: searches web (evidence: `README.md`)
