# githyan/building_rag architecture

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

- Interactive diagram: https://gitdiagram.com/githyan/building_rag
- Repository: https://github.com/githyan/building_rag

## Overview

This is an educational RAG ingestion prototype: the demonstrated workflow reads Markdown files, splits them into chunks, requests Gemini embeddings, and writes chunk metadata and vectors to PostgreSQL. Markdown section parsing exists as a separate document-processing capability, but the shown entry point does not call it. The repository also documents PostgreSQL-backed knowledge storage, but no retrieval or answer-generation path is shown. The graph reflects the sampled call sites; the abstract repository interface has no demonstrated implementation connection.

Main entry points: [`main.py`](https://github.com/githyan/building_rag/blob/main/main.py) (Ingestion entry point), [`src/repository/parse_document.py`](https://github.com/githyan/building_rag/blob/main/src/repository/parse_document.py) (Chunk and embed), [`src/document_processing/files.py`](https://github.com/githyan/building_rag/blob/main/src/document_processing/files.py) (File loader), [`src/repository/SQLInjection.py`](https://github.com/githyan/building_rag/blob/main/src/repository/SQLInjection.py) (PostgreSQL writer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document ingestion"]
  node_main["Ingestion entry point<br/>[main.py]"]
  node_file_loader["File loader<br/>[files.py]"]
end

subgraph group_processing["Text processing"]
  node_markdown_parser["Markdown section parser<br/>[parse.py]"]
  node_chunk_embed["Chunk and embed<br/>[parse_document.py]"]
end

subgraph group_storage["Embedding and storage"]
  node_repository_interface["Repository interface<br/>[interface.py]"]
  node_sql_writer["PostgreSQL writer<br/>[SQLInjection.py]"]
end

node_developer(("Developer"))
node_documents["Markdown corpus"]
node_gemini{{"Gemini embeddings"}}
node_postgres[("PostgreSQL")]

node_developer -->|"runs"| node_main
node_documents -->|"reads files"| node_file_loader
node_main -->|"loads documents"| node_file_loader
node_file_loader -->|"returns documents"| node_main
node_main -->|"generates chunks"| node_chunk_embed
node_chunk_embed -->|"requests embeddings"| node_gemini
node_chunk_embed -->|"initializes and writes"| node_sql_writer
node_sql_writer -->|"executes SQL"| node_postgres

click node_main "https://github.com/githyan/building_rag/blob/main/main.py"
click node_file_loader "https://github.com/githyan/building_rag/blob/main/src/document_processing/files.py"
click node_markdown_parser "https://github.com/githyan/building_rag/blob/main/src/document_processing/parse.py"
click node_chunk_embed "https://github.com/githyan/building_rag/blob/main/src/repository/parse_document.py"
click node_repository_interface "https://github.com/githyan/building_rag/blob/main/src/repository/interface.py"
click node_sql_writer "https://github.com/githyan/building_rag/blob/main/src/repository/SQLInjection.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_file_loader toneBlue
class node_markdown_parser,node_chunk_embed,node_postgres toneAmber
class node_repository_interface,node_sql_writer toneMint
class node_developer,node_documents,node_gemini toneIndigo
```

## Components

### Document ingestion

- [Ingestion entry point](https://github.com/githyan/building_rag/blob/main/main.py): `main.py`
- [File loader](https://github.com/githyan/building_rag/blob/main/src/document_processing/files.py): `src/document_processing/files.py`

### Text processing

- [Markdown section parser](https://github.com/githyan/building_rag/blob/main/src/document_processing/parse.py): `src/document_processing/parse.py`
- [Chunk and embed](https://github.com/githyan/building_rag/blob/main/src/repository/parse_document.py): `src/repository/parse_document.py`

### Embedding and storage

- [Repository interface](https://github.com/githyan/building_rag/blob/main/src/repository/interface.py): `src/repository/interface.py`
- [PostgreSQL writer](https://github.com/githyan/building_rag/blob/main/src/repository/SQLInjection.py): `src/repository/SQLInjection.py`

### Other components

- **Developer**
- **Markdown corpus**
- **Gemini embeddings**
- **PostgreSQL**

## Connections

- Developer → Ingestion entry point: runs (evidence: `README.md`)
- Markdown corpus → File loader: reads files
- Ingestion entry point → File loader: loads documents (evidence: `main.py`)
- File loader → Ingestion entry point: returns documents (evidence: `main.py`)
- Ingestion entry point → Chunk and embed: generates chunks (evidence: `main.py`)
- Chunk and embed → Gemini embeddings: requests embeddings (evidence: `src/repository/parse_document.py`)
- Chunk and embed → PostgreSQL writer: initializes and writes (evidence: `src/repository/parse_document.py`)
- PostgreSQL writer → PostgreSQL: executes SQL (evidence: `src/repository/SQLInjection.py`)
