# bakrianoo/mini-rag architecture

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

- Interactive diagram: https://gitdiagram.com/bakrianoo/mini-rag
- Repository: https://github.com/bakrianoo/mini-rag
- Video tour (about a minute): https://gitdiagram.com/bakrianoo/mini-rag/video

## Overview

mini-rag is a FastAPI question-answering service that ingests project files, chunks and indexes their content, then answers queries with retrieval-augmented generation. The principal workflow runs from API routes through controllers and Celery tasks, storing project, asset, and chunk records alongside vectors. NLPController coordinates embeddings, vector search, prompt construction, and generation. The README documents PostgreSQL/PgVector, Qdrant, OpenAI/Cohere, and Celery capabilities; the sampled excerpts do not show every route or provider invocation, so those links are omitted where unsupported.

Main entry points: [`src/tasks/file_processing.py`](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/file_processing.py) (File processing task), [`src/routes/data.py`](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/routes/data.py) (Data routes), [`src/controllers/NLPController.py`](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/NLPController.py) (NLP controller), [`src/stores/vectordb/VectorDBProviderFactory.py`](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/VectorDBProviderFactory.py) (Vector DB factory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and control"]
  node_app["FastAPI app<br/>[main.py]"]
  node_data_routes["Data routes<br/>[data.py]"]
  node_nlp_routes["NLP routes<br/>[nlp.py]"]
  node_data_controller["Data controller<br/>[DataController.py]"]
end

subgraph group_ingestion["File ingestion"]
  node_project_controller["Project files"]
  node_process_controller["File parsing"]
end

subgraph group_persistence["Project persistence"]
  node_project_model["Project records<br/>[ProjectModel.py]"]
  node_asset_model["Asset records<br/>[AssetModel.py]"]
  node_chunk_model["Chunk records<br/>[ChunkModel.py]"]
  node_relational_db[("PostgreSQL")]
end

subgraph group_rag["Retrieval and generation"]
  node_nlp_controller["NLP controller<br/>[NLPController.py]"]
  node_vector_factory["Vector DB factory"]
  node_pgvector["PgVector provider"]
  node_qdrant["Qdrant provider"]
  node_llm_factory["LLM factory"]
  node_openai["OpenAI provider<br/>[OpenAIProvider.py]"]
  node_cohere["Cohere provider<br/>[CoHereProvider.py]"]
  node_templates["Prompt templates<br/>[template_parser.py]"]
end

subgraph group_workers["Background execution"]
  node_file_task["File processing task<br/>[file_processing.py]"]
  node_index_task["Data indexing task<br/>[data_indexing.py]"]
  node_workflow_task["Process workflow"]
  node_celery["Celery setup<br/>[celery_app.py]"]
end

node_user(("Client"))

node_user -->|"requests"| node_app
node_app -->|"registers"| node_data_routes
node_app -->|"registers"| node_nlp_routes
node_data_routes -->|"calls"| node_data_controller
node_data_routes -->|"calls"| node_project_controller
node_data_routes -->|"calls"| node_process_controller
node_data_routes -->|"dispatches"| node_file_task
node_nlp_routes -->|"calls"| node_nlp_controller
node_nlp_routes -->|"dispatches"| node_index_task
node_file_task -->|"registers task"| node_celery
node_index_task -->|"registers task"| node_celery
node_workflow_task -->|"invokes"| node_file_task
node_workflow_task -->|"invokes"| node_index_task
node_file_task -->|"loads project"| node_project_model
node_file_task -->|"loads assets"| node_asset_model
node_file_task -->|"parses files"| node_process_controller
node_file_task -->|"writes chunks"| node_chunk_model
node_index_task -->|"indexes chunks"| node_nlp_controller
node_nlp_controller -->|"reads prompts"| node_templates
node_celery -->|"configures"| node_vector_factory
node_celery -->|"configures"| node_llm_factory
node_vector_factory -->|"selects provider"| node_pgvector
node_vector_factory -->|"selects provider"| node_qdrant
node_llm_factory -->|"selects provider"| node_openai
node_llm_factory -->|"selects provider"| node_cohere
node_project_model -.->|"reads and writes"| node_relational_db
node_asset_model -.->|"reads and writes"| node_relational_db
node_chunk_model -.->|"reads and writes"| node_relational_db
node_nlp_controller -.->|"uses client"| node_vector_factory
node_nlp_controller -.->|"uses clients"| node_llm_factory

click node_app "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/main.py"
click node_data_routes "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/routes/data.py"
click node_nlp_routes "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/routes/nlp.py"
click node_data_controller "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/DataController.py"
click node_nlp_controller "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/NLPController.py"
click node_project_controller "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/ProjectController.py"
click node_process_controller "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/ProcessController.py"
click node_file_task "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/file_processing.py"
click node_index_task "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/data_indexing.py"
click node_workflow_task "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/process_workflow.py"
click node_celery "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/celery_app.py"
click node_project_model "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/models/ProjectModel.py"
click node_asset_model "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/models/AssetModel.py"
click node_chunk_model "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/models/ChunkModel.py"
click node_vector_factory "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/VectorDBProviderFactory.py"
click node_pgvector "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/providers/PGVectorProvider.py"
click node_qdrant "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/providers/QdrantDBProvider.py"
click node_llm_factory "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/LLMProviderFactory.py"
click node_openai "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/providers/OpenAIProvider.py"
click node_cohere "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/providers/CoHereProvider.py"
click node_templates "https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/templates/template_parser.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_data_routes,node_nlp_routes,node_data_controller,node_user toneBlue
class node_project_controller,node_process_controller toneAmber
class node_project_model,node_asset_model,node_chunk_model,node_relational_db toneMint
class node_nlp_controller,node_vector_factory,node_pgvector,node_qdrant,node_llm_factory,node_openai,node_cohere,node_templates toneRose
class node_file_task,node_index_task,node_workflow_task,node_celery toneIndigo
```

## Components

### API and control

- [FastAPI app](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/main.py): `src/main.py`
- [Data routes](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/routes/data.py): `src/routes/data.py`
- [NLP routes](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/routes/nlp.py): `src/routes/nlp.py`
- [Data controller](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/DataController.py): `src/controllers/DataController.py`

### File ingestion

- [Project files](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/ProjectController.py): `src/controllers/ProjectController.py`
- [File parsing](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/ProcessController.py): `src/controllers/ProcessController.py`

### Project persistence

- [Project records](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/models/ProjectModel.py): `src/models/ProjectModel.py`
- [Asset records](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/models/AssetModel.py): `src/models/AssetModel.py`
- [Chunk records](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/models/ChunkModel.py): `src/models/ChunkModel.py`
- **PostgreSQL**

### Retrieval and generation

- [NLP controller](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/controllers/NLPController.py): `src/controllers/NLPController.py`
- [Vector DB factory](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/VectorDBProviderFactory.py): `src/stores/vectordb/VectorDBProviderFactory.py`
- [PgVector provider](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/providers/PGVectorProvider.py): `src/stores/vectordb/providers/PGVectorProvider.py`
- [Qdrant provider](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/vectordb/providers/QdrantDBProvider.py): `src/stores/vectordb/providers/QdrantDBProvider.py`
- [LLM factory](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/LLMProviderFactory.py): `src/stores/llm/LLMProviderFactory.py`
- [OpenAI provider](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/providers/OpenAIProvider.py): `src/stores/llm/providers/OpenAIProvider.py`
- [Cohere provider](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/providers/CoHereProvider.py): `src/stores/llm/providers/CoHereProvider.py`
- [Prompt templates](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/stores/llm/templates/template_parser.py): `src/stores/llm/templates/template_parser.py`

### Background execution

- [File processing task](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/file_processing.py): `src/tasks/file_processing.py`
- [Data indexing task](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/data_indexing.py): `src/tasks/data_indexing.py`
- [Process workflow](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/tasks/process_workflow.py): `src/tasks/process_workflow.py`
- [Celery setup](https://github.com/bakrianoo/mini-rag/blob/tut-017/src/celery_app.py): `src/celery_app.py`

### Other components

- **Client**

## Connections

- Client → FastAPI app: requests
- FastAPI app → Data routes: registers (evidence: `src/main.py`)
- FastAPI app → NLP routes: registers (evidence: `src/main.py`)
- Data routes → Data controller: calls (evidence: `src/routes/data.py`)
- Data routes → Project files: calls (evidence: `src/routes/data.py`)
- Data routes → File parsing: calls (evidence: `src/routes/data.py`)
- Data routes → File processing task: dispatches (evidence: `src/routes/data.py`)
- NLP routes → NLP controller: calls (evidence: `src/routes/nlp.py`)
- NLP routes → Data indexing task: dispatches (evidence: `src/routes/nlp.py`)
- File processing task → Celery setup: registers task (evidence: `src/tasks/file_processing.py`)
- Data indexing task → Celery setup: registers task (evidence: `src/tasks/data_indexing.py`)
- Process workflow → File processing task: invokes (evidence: `src/tasks/process_workflow.py`)
- Process workflow → Data indexing task: invokes (evidence: `src/tasks/process_workflow.py`)
- File processing task → Project records: loads project (evidence: `src/tasks/file_processing.py`)
- File processing task → Asset records: loads assets (evidence: `src/tasks/file_processing.py`)
- File processing task → File parsing: parses files (evidence: `src/tasks/file_processing.py`)
- File processing task → Chunk records: writes chunks (evidence: `src/tasks/file_processing.py`)
- Data indexing task → NLP controller: indexes chunks (evidence: `src/tasks/data_indexing.py`)
- NLP controller → Prompt templates: reads prompts (evidence: `src/controllers/NLPController.py`)
- Celery setup → Vector DB factory: configures (evidence: `src/celery_app.py`)
- Celery setup → LLM factory: configures (evidence: `src/celery_app.py`)
- Vector DB factory → PgVector provider: selects provider (evidence: `src/stores/vectordb/VectorDBProviderFactory.py`)
- Vector DB factory → Qdrant provider: selects provider (evidence: `src/stores/vectordb/VectorDBProviderFactory.py`)
- LLM factory → OpenAI provider: selects provider (evidence: `src/stores/llm/LLMProviderFactory.py`)
- LLM factory → Cohere provider: selects provider (evidence: `src/stores/llm/LLMProviderFactory.py`)
- Project records → PostgreSQL: reads and writes
- Asset records → PostgreSQL: reads and writes
- Chunk records → PostgreSQL: reads and writes
- NLP controller → Vector DB factory: uses client
- NLP controller → LLM factory: uses clients
