# ennaguiyoussef/simple_rag architecture

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

- Interactive diagram: https://gitdiagram.com/ennaguiyoussef/simple_rag
- Repository: https://github.com/ennaguiyoussef/simple_rag

## Overview

This is a learning-focused cat-facts RAG chatbot. A user submits a question in the React chat UI; the Flask endpoint validates it, retrieves relevant facts from an in-memory vector database, asks Ollama to generate a grounded answer, and returns it to the UI. The README also describes embedding, similarity search, and a health endpoint. The sampled Flask source implements RAG directly; although `rag_core.py` is documented as core logic, the sampled `app.py` does not import it, so no connection between them is shown.

Main entry points: [`app.py`](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py) (Flask API), [`frontend/src/chatbot.jsx`](https://github.com/ennaguiyoussef/simple_rag/blob/master/frontend/src/chatbot.jsx) (Chat UI), [`frontend/src/App.jsx`](https://github.com/ennaguiyoussef/simple_rag/blob/master/frontend/src/App.jsx) (React app), [`cat-facts`](https://github.com/ennaguiyoussef/simple_rag/blob/master/cat-facts) (Cat facts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Chat interface"]
  node_chat_ui["Chat UI<br/>[chatbot.jsx]"]
  node_app_shell["React app<br/>[App.jsx]"]
end

subgraph group_api["Flask API"]
  node_flask_api["Flask API<br/>[app.py]"]
  node_chat_endpoint["Chat endpoint<br/>[app.py]"]
  node_health_endpoint["Health endpoint<br/>[app.py]"]
end

subgraph group_rag["RAG pipeline"]
  node_rag_flow["RAG answer flow<br/>[app.py]"]
  node_facts["Cat facts"]
  node_vector_db[("In-memory vectors<br/>[app.py]")]
  node_retrieval["Similarity retrieval<br/>[app.py]"]
end

subgraph group_models["Ollama models"]
  node_embed_model["Embedding model"]
  node_language_model["Language model"]
end

node_user(("Chat user"))
node_health_client(("Health-check caller"))

node_user -->|"asks"| node_chat_ui
node_chat_ui -->|"POST /chat"| node_flask_api
node_flask_api -->|"dispatches"| node_chat_endpoint
node_chat_endpoint -->|"calls"| node_rag_flow
node_rag_flow -->|"calls"| node_retrieval
node_retrieval -->|"embeds query"| node_embed_model
node_retrieval -->|"reads vectors"| node_vector_db
node_rag_flow -->|"sends context"| node_language_model
node_facts -->|"embeds facts"| node_embed_model
node_flask_api -->|"loads at startup"| node_facts
node_flask_api -->|"stores embeddings"| node_vector_db
node_chat_endpoint -->|"returns answer"| node_chat_ui
node_user -->|"opens"| node_app_shell
node_app_shell -->|"renders"| node_chat_ui
node_health_client -->|"GET /health"| node_flask_api
node_flask_api -->|"dispatches"| node_health_endpoint

click node_chat_ui "https://github.com/ennaguiyoussef/simple_rag/blob/master/frontend/src/chatbot.jsx"
click node_app_shell "https://github.com/ennaguiyoussef/simple_rag/blob/master/frontend/src/App.jsx"
click node_flask_api "https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py"
click node_chat_endpoint "https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py"
click node_health_endpoint "https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py"
click node_rag_flow "https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py"
click node_facts "https://github.com/ennaguiyoussef/simple_rag/blob/master/cat-facts"
click node_vector_db "https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py"
click node_retrieval "https://github.com/ennaguiyoussef/simple_rag/blob/master/app.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_chat_ui,node_app_shell,node_user toneBlue
class node_flask_api,node_chat_endpoint,node_health_endpoint toneAmber
class node_rag_flow,node_facts,node_vector_db,node_retrieval toneMint
class node_embed_model,node_language_model toneRose
class node_health_client toneIndigo
```

## Components

### Chat interface

- [Chat UI](https://github.com/ennaguiyoussef/simple_rag/blob/master/frontend/src/chatbot.jsx): `frontend/src/chatbot.jsx`
- [React app](https://github.com/ennaguiyoussef/simple_rag/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`

### Flask API

- [Flask API](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py): `app.py`
- [Chat endpoint](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py): `app.py`
- [Health endpoint](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py): `app.py`

### RAG pipeline

- [RAG answer flow](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py): `app.py`
- [Cat facts](https://github.com/ennaguiyoussef/simple_rag/blob/master/cat-facts): `cat-facts`
- [In-memory vectors](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py): `app.py`
- [Similarity retrieval](https://github.com/ennaguiyoussef/simple_rag/blob/master/app.py): `app.py`

### Ollama models

- **Embedding model**
- **Language model**

### Other components

- **Chat user**
- **Health-check caller**

## Connections

- Chat user → Chat UI: asks
- Chat UI → Flask API: POST /chat
- Flask API → Chat endpoint: dispatches
- Chat endpoint → RAG answer flow: calls
- RAG answer flow → Similarity retrieval: calls
- Similarity retrieval → Embedding model: embeds query
- Similarity retrieval → In-memory vectors: reads vectors
- RAG answer flow → Language model: sends context
- Cat facts → Embedding model: embeds facts
- Flask API → Cat facts: loads at startup
- Flask API → In-memory vectors: stores embeddings
- Chat endpoint → Chat UI: returns answer
- Chat user → React app: opens
- React app → Chat UI: renders
- Health-check caller → Flask API: GET /health
- Flask API → Health endpoint: dispatches
