# iofaraz/rag architecture

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

- Interactive diagram: https://gitdiagram.com/iofaraz/rag
- Repository: https://github.com/iofaraz/rag

## Overview

Nutrix is a nutrition question-answering application. A user submits a question in the chat; the frontend requests an answer, and the backend runs vector and knowledge-graph retrieval before returning an AI-generated response and nutrition sources for display. The graph also supports category and curated nutrient–goal knowledge. The README provides no capability details, and some frontend-to-backend wiring and storage setup were not excerpted; uncertain connections are omitted or marked unverified.

Main entry points: [`graph/graph_builder.py`](https://github.com/iofaraz/rag/blob/main/graph/graph_builder.py) (Graph builder), [`frontend/src/components/chat/ChatInterface.js`](https://github.com/iofaraz/rag/blob/main/frontend/src/components/chat/ChatInterface.js) (Chat interface), [`rag/rag_pipeline.py`](https://github.com/iofaraz/rag/blob/main/rag/rag_pipeline.py) (RAG pipeline), [`backend/app/main.py`](https://github.com/iofaraz/rag/blob/main/backend/app/main.py) (Query endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Question interface"]
  node_chat["Chat interface<br/>[ChatInterface.js]"]
  node_chat_views["Chat views"]
  node_sources_view["Retrieved sources"]
  node_source_card["Source card<br/>[SourceCard.js]"]
  node_api_client["API client<br/>[api.js]"]
end

subgraph group_api["Backend API"]
  node_api_route["Query endpoint<br/>[main.py]"]
  node_query_schema["Query schemas<br/>[query.py]"]
  node_response_adapter["Response adapter<br/>[rag.py]"]
end

subgraph group_rag["Answer retrieval"]
  node_pipeline["RAG pipeline<br/>[rag_pipeline.py]"]
  node_vector_retriever["Vector retrieval<br/>[retriever.py]"]
  node_vector_store[("Chroma store")]
  node_llm_client["LLM client<br/>[llm_client.py]"]
end

subgraph group_knowledge["Nutrition knowledge"]
  node_graph_retriever["Graph retrieval<br/>[graph_retriever.py]"]
  node_neo4j[("Neo4j graph")]
  node_graph_builder["Graph builder<br/>[graph_builder.py]"]
  node_category_resolver["Category resolver"]
  node_graph_schema["Graph schema<br/>[schema.py]"]
  node_seed_knowledge["Curated knowledge<br/>[seed_knowledge.py]"]
end

node_user(("User"))
node_groq["Groq service"]

node_user -->|"asks"| node_chat
node_chat -->|"renders"| node_chat_views
node_chat -->|"requests answer"| node_api_client
node_api_client -.->|"sends query"| node_api_route
node_api_route -->|"validates and shapes"| node_query_schema
node_api_route -->|"calls"| node_response_adapter
node_response_adapter -->|"calls"| node_pipeline
node_pipeline -->|"retrieves foods"| node_vector_retriever
node_pipeline -->|"retrieves graph data"| node_graph_retriever
node_pipeline -->|"generates answer"| node_llm_client
node_vector_retriever -->|"queries"| node_vector_store
node_llm_client -->|"sends prompt"| node_groq
node_graph_retriever -->|"queries"| node_neo4j
node_graph_builder -->|"uses schema"| node_graph_schema
node_graph_builder -->|"resolves categories"| node_category_resolver
node_graph_builder -->|"seeds curated data"| node_seed_knowledge
node_graph_builder -->|"writes graph"| node_neo4j
node_seed_knowledge -->|"writes curated links"| node_neo4j
node_chat -->|"displays records"| node_sources_view
node_sources_view -->|"renders cards"| node_source_card

click node_chat "https://github.com/iofaraz/rag/blob/main/frontend/src/components/chat/ChatInterface.js"
click node_chat_views "https://github.com/iofaraz/rag/tree/main/frontend/src/components/chat"
click node_sources_view "https://github.com/iofaraz/rag/blob/main/frontend/src/components/results/RetrievedSources.js"
click node_source_card "https://github.com/iofaraz/rag/blob/main/frontend/src/components/results/SourceCard.js"
click node_api_client "https://github.com/iofaraz/rag/blob/main/frontend/src/services/api.js"
click node_api_route "https://github.com/iofaraz/rag/blob/main/backend/app/main.py"
click node_query_schema "https://github.com/iofaraz/rag/blob/main/backend/schemas/query.py"
click node_response_adapter "https://github.com/iofaraz/rag/blob/main/backend/services/rag.py"
click node_pipeline "https://github.com/iofaraz/rag/blob/main/rag/rag_pipeline.py"
click node_vector_retriever "https://github.com/iofaraz/rag/blob/main/rag/retriever.py"
click node_vector_store "https://github.com/iofaraz/rag/blob/main/rag/create_vector_db.py"
click node_llm_client "https://github.com/iofaraz/rag/blob/main/rag/llm_client.py"
click node_graph_retriever "https://github.com/iofaraz/rag/blob/main/graph/graph_retriever.py"
click node_graph_builder "https://github.com/iofaraz/rag/blob/main/graph/graph_builder.py"
click node_category_resolver "https://github.com/iofaraz/rag/blob/main/graph/category_resolver.py"
click node_graph_schema "https://github.com/iofaraz/rag/blob/main/graph/schema.py"
click node_seed_knowledge "https://github.com/iofaraz/rag/blob/main/graph/seed_knowledge.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,node_chat_views,node_sources_view,node_source_card,node_api_client,node_user toneBlue
class node_api_route,node_query_schema,node_response_adapter toneAmber
class node_pipeline,node_vector_retriever,node_vector_store,node_llm_client toneMint
class node_graph_retriever,node_neo4j,node_graph_builder,node_category_resolver,node_graph_schema,node_seed_knowledge toneRose
class node_groq toneIndigo
```

## Components

### Question interface

- [Chat interface](https://github.com/iofaraz/rag/blob/main/frontend/src/components/chat/ChatInterface.js): `frontend/src/components/chat/ChatInterface.js`
- [Chat views](https://github.com/iofaraz/rag/tree/main/frontend/src/components/chat): `frontend/src/components/chat`
- [Retrieved sources](https://github.com/iofaraz/rag/blob/main/frontend/src/components/results/RetrievedSources.js): `frontend/src/components/results/RetrievedSources.js`
- [Source card](https://github.com/iofaraz/rag/blob/main/frontend/src/components/results/SourceCard.js): `frontend/src/components/results/SourceCard.js`
- [API client](https://github.com/iofaraz/rag/blob/main/frontend/src/services/api.js): `frontend/src/services/api.js`

### Backend API

- [Query endpoint](https://github.com/iofaraz/rag/blob/main/backend/app/main.py): `backend/app/main.py`
- [Query schemas](https://github.com/iofaraz/rag/blob/main/backend/schemas/query.py): `backend/schemas/query.py`
- [Response adapter](https://github.com/iofaraz/rag/blob/main/backend/services/rag.py): `backend/services/rag.py`

### Answer retrieval

- [RAG pipeline](https://github.com/iofaraz/rag/blob/main/rag/rag_pipeline.py): `rag/rag_pipeline.py`
- [Vector retrieval](https://github.com/iofaraz/rag/blob/main/rag/retriever.py): `rag/retriever.py`
- [Chroma store](https://github.com/iofaraz/rag/blob/main/rag/create_vector_db.py): `rag/create_vector_db.py`
- [LLM client](https://github.com/iofaraz/rag/blob/main/rag/llm_client.py): `rag/llm_client.py`

### Nutrition knowledge

- [Graph retrieval](https://github.com/iofaraz/rag/blob/main/graph/graph_retriever.py): `graph/graph_retriever.py`
- **Neo4j graph**
- [Graph builder](https://github.com/iofaraz/rag/blob/main/graph/graph_builder.py): `graph/graph_builder.py`
- [Category resolver](https://github.com/iofaraz/rag/blob/main/graph/category_resolver.py): `graph/category_resolver.py`
- [Graph schema](https://github.com/iofaraz/rag/blob/main/graph/schema.py): `graph/schema.py`
- [Curated knowledge](https://github.com/iofaraz/rag/blob/main/graph/seed_knowledge.py): `graph/seed_knowledge.py`

### Other components

- **User**
- **Groq service**

## Connections

- User → Chat interface: asks (evidence: `frontend/src/components/chat/ChatInterface.js`)
- Chat interface → Chat views: renders (evidence: `frontend/src/components/chat/ChatInterface.js`)
- Chat interface → API client: requests answer (evidence: `frontend/src/components/chat/ChatInterface.js`)
- API client → Query endpoint: sends query
- Query endpoint → Query schemas: validates and shapes (evidence: `backend/app/main.py`)
- Query endpoint → Response adapter: calls (evidence: `backend/app/main.py`)
- Response adapter → RAG pipeline: calls (evidence: `backend/services/rag.py`)
- RAG pipeline → Vector retrieval: retrieves foods (evidence: `rag/rag_pipeline.py`)
- RAG pipeline → Graph retrieval: retrieves graph data (evidence: `rag/rag_pipeline.py`)
- RAG pipeline → LLM client: generates answer (evidence: `rag/rag_pipeline.py`)
- Vector retrieval → Chroma store: queries (evidence: `rag/retriever.py`)
- LLM client → Groq service: sends prompt (evidence: `rag/llm_client.py`)
- Graph retrieval → Neo4j graph: queries (evidence: `graph/graph_retriever.py`)
- Graph builder → Graph schema: uses schema (evidence: `graph/graph_builder.py`)
- Graph builder → Category resolver: resolves categories (evidence: `graph/graph_builder.py`)
- Graph builder → Curated knowledge: seeds curated data (evidence: `graph/graph_builder.py`)
- Graph builder → Neo4j graph: writes graph (evidence: `graph/graph_builder.py`)
- Curated knowledge → Neo4j graph: writes curated links (evidence: `graph/seed_knowledge.py`)
- Chat interface → Retrieved sources: displays records (evidence: `frontend/src/components/chat/ChatInterface.js`)
- Retrieved sources → Source card: renders cards (evidence: `frontend/src/components/results/RetrievedSources.js`)
