# ddmpriza/ai-document-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/ddmpriza/ai-document-assistant
- Repository: https://github.com/ddmpriza/ai-document-assistant

## Overview

AI Document Assistant accepts PDF uploads and document questions through a Streamlit interface backed by a FastAPI service. The API extracts page text, chunks it, embeds the chunks, persists document content in SQLite, and builds an in-memory FAISS index. For questions, it embeds the query, searches the index, and passes retrieved context to a configured LLM provider; answers include source references, or a fallback when no relevant chunks are found. The README documents persistence and provider options; links among components are limited to shown calls or documented behavior.

Main entry points: [`app/main.py`](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/main.py) (REST API), [`app/providers/factory.py`](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/factory.py) (LLM selection), [`app/providers/ollama_provider.py`](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/ollama_provider.py) (Ollama answers), [`app/providers/openai_provider.py`](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/openai_provider.py) (OpenAI answers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["User interface"]
  node_ui["Streamlit UI<br/>[streamlit_app.py]"]
end

subgraph group_api["API orchestration"]
  node_api_main["REST API<br/>[main.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
  node_models["Domain models<br/>[models.py]"]
end

subgraph group_documents["Document and retrieval"]
  node_pdf["PDF extraction<br/>[pdf_parser.py]"]
  node_chunker["Text chunking<br/>[text_chunker.py]"]
  node_document_store[("Document persistence<br/>[document_store.py]")]
  node_faiss[("FAISS index")]
  node_memory_vector[("In-memory vector store")]
  node_retrieval["Cosine retrieval<br/>[retrieval.py]"]
end

subgraph group_providers["Model providers"]
  node_embedding_factory["Embedding selection<br/>[factory.py]"]
  node_embedding_interface["Embedding interface<br/>[base.py]"]
  node_ollama_embedding["Ollama embeddings<br/>[ollama_provider.py]"]
  node_llm_factory["LLM selection<br/>[factory.py]"]
  node_llm_interface["LLM interface<br/>[base.py]"]
  node_ollama_llm["Ollama answers<br/>[ollama_provider.py]"]
  node_openai_llm["OpenAI answers<br/>[openai_provider.py]"]
  node_mock_llm["Mock answers<br/>[mock_provider.py]"]
end

node_user(("Document user"))
node_ollama_service["Ollama service"]
node_openai_service["OpenAI service"]

node_user -->|"uses"| node_ui
node_ui -->|"sends requests"| node_api_main
node_api_main -->|"validates and responds"| node_schemas
node_api_main -->|"extracts pages"| node_pdf
node_api_main -->|"creates chunks"| node_chunker
node_api_main -->|"selects embeddings"| node_embedding_factory
node_embedding_factory -->|"creates"| node_ollama_embedding
node_ollama_embedding -->|"implements"| node_embedding_interface
node_api_main -->|"stores and loads"| node_document_store
node_document_store -->|"builds records"| node_models
node_api_main -->|"indexes and searches"| node_faiss
node_api_main -->|"selects provider"| node_llm_factory
node_llm_factory -->|"creates"| node_ollama_llm
node_llm_factory -->|"creates"| node_openai_llm
node_llm_factory -->|"creates"| node_mock_llm
node_ollama_llm -->|"implements"| node_llm_interface
node_openai_llm -->|"implements"| node_llm_interface
node_mock_llm -->|"implements"| node_llm_interface
node_ollama_llm -->|"calls"| node_ollama_service
node_openai_llm -->|"calls"| node_openai_service
node_api_main -->|"builds context"| node_models

click node_ui "https://github.com/ddmpriza/ai-document-assistant/blob/main/ui/streamlit_app.py"
click node_api_main "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/main.py"
click node_schemas "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/schemas.py"
click node_models "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/models.py"
click node_pdf "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/pdf_parser.py"
click node_chunker "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/text_chunker.py"
click node_embedding_factory "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/embeddings/factory.py"
click node_embedding_interface "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/embeddings/base.py"
click node_ollama_embedding "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/embeddings/ollama_provider.py"
click node_document_store "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/document_store.py"
click node_faiss "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/faiss_vector_store.py"
click node_memory_vector "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/in_memory_vector_store.py"
click node_retrieval "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/retrieval.py"
click node_llm_factory "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/factory.py"
click node_llm_interface "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/base.py"
click node_ollama_llm "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/ollama_provider.py"
click node_openai_llm "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/openai_provider.py"
click node_mock_llm "https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/mock_provider.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_ui,node_user toneBlue
class node_api_main,node_schemas,node_models toneAmber
class node_pdf,node_chunker,node_document_store,node_faiss,node_memory_vector,node_retrieval toneMint
class node_embedding_factory,node_embedding_interface,node_ollama_embedding,node_llm_factory,node_llm_interface,node_ollama_llm,node_openai_llm,node_mock_llm toneRose
class node_ollama_service,node_openai_service toneIndigo
```

## Components

### User interface

- [Streamlit UI](https://github.com/ddmpriza/ai-document-assistant/blob/main/ui/streamlit_app.py): `ui/streamlit_app.py`

### API orchestration

- [REST API](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/main.py): `app/main.py`
- [API schemas](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/schemas.py): `app/schemas.py`
- [Domain models](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/models.py): `app/models.py`

### Document and retrieval

- [PDF extraction](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/pdf_parser.py): `app/services/pdf_parser.py`
- [Text chunking](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/text_chunker.py): `app/services/text_chunker.py`
- [Document persistence](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/document_store.py): `app/services/document_store.py`
- [FAISS index](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/faiss_vector_store.py): `app/services/faiss_vector_store.py`
- [In-memory vector store](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/in_memory_vector_store.py): `app/services/in_memory_vector_store.py`
- [Cosine retrieval](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/services/retrieval.py): `app/services/retrieval.py`

### Model providers

- [Embedding selection](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/embeddings/factory.py): `app/providers/embeddings/factory.py`
- [Embedding interface](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/embeddings/base.py): `app/providers/embeddings/base.py`
- [Ollama embeddings](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/embeddings/ollama_provider.py): `app/providers/embeddings/ollama_provider.py`
- [LLM selection](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/factory.py): `app/providers/factory.py`
- [LLM interface](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/base.py): `app/providers/base.py`
- [Ollama answers](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/ollama_provider.py): `app/providers/ollama_provider.py`
- [OpenAI answers](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/openai_provider.py): `app/providers/openai_provider.py`
- [Mock answers](https://github.com/ddmpriza/ai-document-assistant/blob/main/app/providers/mock_provider.py): `app/providers/mock_provider.py`

### Other components

- **Document user**
- **Ollama service**
- **OpenAI service**

## Connections

- Document user → Streamlit UI: uses (evidence: `README.md`)
- Streamlit UI → REST API: sends requests (evidence: `README.md`)
- REST API → API schemas: validates and responds (evidence: `app/main.py`)
- REST API → PDF extraction: extracts pages (evidence: `app/main.py`)
- REST API → Text chunking: creates chunks (evidence: `app/main.py`)
- REST API → Embedding selection: selects embeddings (evidence: `app/main.py`)
- Embedding selection → Ollama embeddings: creates (evidence: `app/providers/embeddings/factory.py`)
- Ollama embeddings → Embedding interface: implements (evidence: `app/providers/embeddings/ollama_provider.py`)
- REST API → Document persistence: stores and loads (evidence: `app/main.py`)
- Document persistence → Domain models: builds records (evidence: `app/services/document_store.py`)
- REST API → FAISS index: indexes and searches (evidence: `app/main.py`)
- REST API → LLM selection: selects provider (evidence: `app/main.py`)
- LLM selection → Ollama answers: creates (evidence: `app/providers/factory.py`)
- LLM selection → OpenAI answers: creates (evidence: `app/providers/factory.py`)
- LLM selection → Mock answers: creates (evidence: `app/providers/factory.py`)
- Ollama answers → LLM interface: implements (evidence: `app/providers/ollama_provider.py`)
- OpenAI answers → LLM interface: implements (evidence: `app/providers/openai_provider.py`)
- Mock answers → LLM interface: implements (evidence: `app/providers/mock_provider.py`)
- Ollama answers → Ollama service: calls (evidence: `app/providers/ollama_provider.py`)
- OpenAI answers → OpenAI service: calls (evidence: `app/providers/openai_provider.py`)
- REST API → Domain models: builds context (evidence: `app/main.py`)
