# aimara8/local_rag architecture

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

- Interactive diagram: https://gitdiagram.com/aimara8/local_rag
- Repository: https://github.com/aimara8/local_rag

## Overview

#### Purpose and Entry Points
`local_rag` is a compact local retrieval-augmented generation application. It separates a backend RAG service from a frontend user interface.

- Backend entry point: `backend/main.py`
- Frontend entry point: `frontend/app.py`
- Core RAG implementation: `backend/rag_core.py`

#### Frontend Interaction Layer
The frontend accepts user interaction and presents generated/retrieved results. It is isolated from retrieval and model logic, communicating with the backend-facing application flow rather than owning RAG state.

- `frontend/app.py`

#### Backend Application Layer
The backend application coordinates request handling, invokes the RAG core, and returns responses to the frontend. This is the primary process boundary between UI concerns and retrieval/generation concerns.

- `backend/main.py`
- `backend/rag_core.py`

#### RAG Core
`rag_core.py` is the architecture-defining domain module. It should encapsulate document ingestion/index access, query retrieval, prompt/context assembly, and generation orchestration. Keeping this logic outside `main.py` allows the backend transport layer to remain thin.

- `backend/rag_core.py`

#### Primary Control Flow
The expected request path is:

1. A user submits a query through `frontend/app.py`.
2. Backend request orchestration in `backend/main.py` receives or coordinates the query.
3. `backend/rag_core.py` retrieves relevant context and produces a RAG response.
4. The response returns through the backend to the frontend for display.

The key boundary is between frontend presentation (`frontend/`) and backend/RAG execution (`backend/`).

#### Runtime and Dependency Boundary
The repository is Python-based, with dependencies defined centrally in `requirements.txt`. No deployment infrastructure, database, vector store, model provider, or external service configuration is visible in the supplied tree; those runtime details must be confirmed from the implementation and dependency list.

- `requirements.txt`
- `backend/main.py`
- `frontend/app.py`

Main entry points: [`backend/main.py`](https://github.com/aimara8/local_rag/blob/main/backend/main.py) (Backend app), [`backend/rag_core.py`](https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py) (RAG core), [`frontend/app.py`](https://github.com/aimara8/local_rag/blob/main/frontend/app.py) (Frontend app), [`requirements.txt`](https://github.com/aimara8/local_rag/blob/main/requirements.txt) (Python dependencies)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["Frontend app<br/>Python UI<br/>[app.py]"]
end

subgraph group_backend["Backend"]
  node_backend_main["Backend app<br/>Python service<br/>[main.py]"]
  node_rag_core["RAG core<br/>RAG domain module<br/>[rag_core.py]"]
  node_ingestion_index[("Document ingestion &amp; index<br/>RAG stage<br/>[rag_core.py]")]
  node_retrieval["Context retrieval<br/>RAG stage<br/>[rag_core.py]"]
  node_prompt_generation["Prompt &amp; generation<br/>RAG stage<br/>[rag_core.py]"]
end

node_dependencies["Python dependencies<br/>Dependency manifest<br/>[requirements.txt]"]

node_frontend_app -->|"submits query"| node_backend_main
node_backend_main -->|"invokes"| node_rag_core
node_rag_core -->|"uses"| node_ingestion_index
node_rag_core -->|"retrieves context"| node_retrieval
node_ingestion_index -->|"supplies documents"| node_retrieval
node_retrieval -->|"relevant context"| node_prompt_generation
node_prompt_generation -->|"RAG response"| node_backend_main
node_backend_main -->|"returns response"| node_frontend_app
node_dependencies -.->|"provides packages"| node_frontend_app
node_dependencies -.->|"provides packages"| node_backend_main

click node_frontend_app "https://github.com/aimara8/local_rag/blob/main/frontend/app.py"
click node_backend_main "https://github.com/aimara8/local_rag/blob/main/backend/main.py"
click node_rag_core "https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py"
click node_ingestion_index "https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py"
click node_retrieval "https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py"
click node_prompt_generation "https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py"
click node_dependencies "https://github.com/aimara8/local_rag/blob/main/requirements.txt"

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_frontend_app toneBlue
class node_backend_main,node_rag_core,node_ingestion_index,node_retrieval,node_prompt_generation toneAmber
class node_dependencies toneNeutral
```

## Components

### Frontend

User interaction and result presentation.

- [Frontend app](https://github.com/aimara8/local_rag/blob/main/frontend/app.py): Python UI · Accepts queries and displays responses. · `frontend/app.py`

### Backend

Request transport and RAG execution.

- [Backend app](https://github.com/aimara8/local_rag/blob/main/backend/main.py): Python service · Coordinates backend query handling. · `backend/main.py`
- [RAG core](https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py): RAG domain module · Owns ingestion/index access, retrieval, context assembly, and generation. · `backend/rag_core.py`
- [Document ingestion & index](https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py): RAG stage · Ingests documents and accesses retrieval index. · `backend/rag_core.py`
- [Context retrieval](https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py): RAG stage · Finds relevant document context for a query. · `backend/rag_core.py`
- [Prompt & generation](https://github.com/aimara8/local_rag/blob/main/backend/rag_core.py): RAG stage · Assembles context and produces the response. · `backend/rag_core.py`

### Other components

- [Python dependencies](https://github.com/aimara8/local_rag/blob/main/requirements.txt): Dependency manifest · Central dependency definition. · `requirements.txt`

## Connections

- Frontend app → Backend app: submits query
- Backend app → RAG core: invokes
- RAG core → Document ingestion & index: uses
- RAG core → Context retrieval: retrieves context
- Document ingestion & index → Context retrieval: supplies documents
- Context retrieval → Prompt & generation: relevant context
- Prompt & generation → Backend app: RAG response
- Backend app → Frontend app: returns response
- Python dependencies → Frontend app: provides packages
- Python dependencies → Backend app: provides packages
