# theonlyabdulhamid/ai-agent architecture

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

- Interactive diagram: https://gitdiagram.com/theonlyabdulhamid/ai-agent
- Repository: https://github.com/theonlyabdulhamid/ai-agent

## Overview

AI Research Assistant is a FastAPI backend for uploading PDFs and asking questions about their contents. The documented upload workflow extracts PDF text, chunks it, embeds the chunks, and stores them in ChromaDB; the documented question workflow retrieves relevant chunks and uses Groq to generate a context-aware answer. The upload path is wired in the excerpts, but the ask endpoint currently only returns the submitted question: its connection to RAG and answer generation is documented, not implemented in the shown code. The React frontend is described as future work. Unverified links are dashed.

Main entry points: [`backend/app/api/routes.py`](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/api/routes.py) (API routes), [`backend/app/services/document_processor.py`](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/document_processor.py) (Document processor), [`backend/app/services/rag.py`](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/rag.py) (RAG context builder), [`backend/app/services/retrieval.py`](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/retrieval.py) (Semantic retrieval)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and intake"]
  node_app["FastAPI application<br/>[main.py]"]
  node_routes["API routes<br/>[routes.py]"]
  node_schemas["Request and response schemas<br/>[document.py]"]
  node_pdf["PDF text extraction<br/>[routes.py]"]
end

subgraph group_processing["Document processing"]
  node_processor["Document processor"]
  node_chunking["Text chunking<br/>[chunking.py]"]
end

subgraph group_search["Retrieval and generation"]
  node_rag["RAG context builder<br/>[rag.py]"]
  node_retrieval["Semantic retrieval<br/>[retrieval.py]"]
  node_groq["Groq answer service<br/>[groq_service.py]"]
end

subgraph group_storage["Embedding and storage"]
  node_embeddings["Semantic embeddings<br/>[embeddings.py]"]
  node_chroma[("Chroma vector store<br/>[chroma.py]")]
end

node_user(("Research user"))
node_groq_api{{"Groq API"}}

node_user -->|"uploads PDF"| node_routes
node_user -->|"asks question"| node_routes
node_app -->|"registers"| node_routes
node_routes -->|"validates with"| node_schemas
node_routes -->|"extracts text"| node_pdf
node_routes -->|"processes text"| node_processor
node_processor -->|"chunks text"| node_chunking
node_processor -->|"embeds chunks"| node_embeddings
node_processor -->|"stores chunks"| node_chroma
node_routes -.->|"builds context"| node_rag
node_rag -->|"retrieves context"| node_retrieval
node_retrieval -->|"embeds query"| node_embeddings
node_retrieval -->|"queries vectors"| node_chroma
node_rag -.->|"generates answer"| node_groq
node_groq -->|"requests completion"| node_groq_api

click node_app "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/main.py"
click node_routes "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/api/routes.py"
click node_schemas "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/schemas/document.py"
click node_pdf "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/api/routes.py"
click node_processor "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/document_processor.py"
click node_chunking "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/chunking.py"
click node_embeddings "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/embeddings.py"
click node_chroma "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/database/chroma.py"
click node_rag "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/rag.py"
click node_retrieval "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/retrieval.py"
click node_groq "https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/groq_service.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_app,node_routes,node_schemas,node_pdf,node_user toneBlue
class node_processor,node_chunking toneAmber
class node_rag,node_retrieval,node_groq,node_groq_api toneMint
class node_embeddings,node_chroma toneRose
```

## Components

### API and intake

- [FastAPI application](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/main.py): `backend/main.py`
- [API routes](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`
- [Request and response schemas](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/schemas/document.py): `backend/app/schemas/document.py`
- [PDF text extraction](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/api/routes.py): `backend/app/api/routes.py`

### Document processing

- [Document processor](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/document_processor.py): `backend/app/services/document_processor.py`
- [Text chunking](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/chunking.py): `backend/app/services/chunking.py`

### Retrieval and generation

- [RAG context builder](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/rag.py): `backend/app/services/rag.py`
- [Semantic retrieval](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/retrieval.py): `backend/app/services/retrieval.py`
- [Groq answer service](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/groq_service.py): `backend/app/services/groq_service.py`

### Embedding and storage

- [Semantic embeddings](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/services/embeddings.py): `backend/app/services/embeddings.py`
- [Chroma vector store](https://github.com/theonlyabdulhamid/ai-agent/blob/main/backend/app/database/chroma.py): `backend/app/database/chroma.py`

### Other components

- **Research user**
- **Groq API**

## Connections

- Research user → API routes: uploads PDF (evidence: `README.md`)
- Research user → API routes: asks question (evidence: `README.md`)
- FastAPI application → API routes: registers (evidence: `backend/main.py`)
- API routes → Request and response schemas: validates with (evidence: `backend/app/api/routes.py`)
- API routes → PDF text extraction: extracts text (evidence: `backend/app/api/routes.py`)
- API routes → Document processor: processes text (evidence: `backend/app/api/routes.py`)
- Document processor → Text chunking: chunks text (evidence: `backend/app/services/document_processor.py`)
- Document processor → Semantic embeddings: embeds chunks (evidence: `backend/app/services/document_processor.py`)
- Document processor → Chroma vector store: stores chunks (evidence: `backend/app/services/document_processor.py`)
- API routes → RAG context builder: builds context
- RAG context builder → Semantic retrieval: retrieves context (evidence: `backend/app/services/rag.py`)
- Semantic retrieval → Semantic embeddings: embeds query (evidence: `backend/app/services/retrieval.py`)
- Semantic retrieval → Chroma vector store: queries vectors (evidence: `backend/app/services/retrieval.py`)
- RAG context builder → Groq answer service: generates answer
- Groq answer service → Groq API: requests completion (evidence: `backend/app/services/groq_service.py`)
