# joodshatnawi/rawi architecture

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

- Interactive diagram: https://gitdiagram.com/joodshatnawi/rawi
- Repository: https://github.com/joodshatnawi/rawi

## Overview

Rawi AI is a Streamlit tourist guide whose main journey runs from image upload through landmark recognition and tour generation to a results page with story, audio, facts, and a map; visitors can then ask landmark-specific questions. Chat rewrites questions, retrieves local indexed knowledge, and generates grounded answers. The graph also preserves multilingual content, cached stories, and the documented visitor-information features. Some subsystems are documented but their implementation was not sampled, so their links are limited to README evidence.

Main entry points: [`model_rawi.py`](https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py) (Answer Generation), [`home_page.py`](https://github.com/joodshatnawi/rawi/blob/main/home_page.py) (Image Intake), [`result_page.py`](https://github.com/joodshatnawi/rawi/blob/main/result_page.py) (Tour Results), [`app.py`](https://github.com/joodshatnawi/rawi/blob/main/app.py) (App Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["Visitor Interface"]
  node_app["App Router<br/>[app.py]"]
  node_home["Image Intake<br/>[home_page.py]"]
  node_results["Tour Results<br/>[result_page.py]"]
  node_chat_ui["Chat Interface<br/>[chat_page.py]"]
end

subgraph group_tour["Landmark Tour"]
  node_recognition["Landmark Detection<br/>[model_rawi.py]"]
  node_story["Story Generation<br/>[model_rawi.py]"]
  node_audio["Audio Narration<br/>[model_rawi.py]"]
  node_visitor_info["Landmark Information<br/>[facts.json]"]
  node_map["Landmark Map<br/>[result_page.py]"]
end

subgraph group_chat["Rawi Chat"]
  node_query_rewrite["Query Rewriting<br/>[model_rawi.py]"]
  node_retrieval["Knowledge Retrieval<br/>[rag.py]"]
  node_answer["Answer Generation<br/>[model_rawi.py]"]
end

subgraph group_content["Tourism Content"]
  node_knowledge[("Indexed Knowledge<br/>[knowledge.json]")]
  node_story_cache[("Story Cache<br/>[stories_cache.json]")]
  node_story_prompts["Story Prompts"]
  node_answer_prompts["Answer Prompts"]
  node_rewrite_prompts["Rewrite Prompts<br/>[query_rewriting.md]"]
end

node_visitor(("Visitor"))
node_groq{{"Groq Model API"}}
node_tts_service{{"TTS Service"}}

node_visitor -->|"uploads image"| node_home
node_app -->|"routes home"| node_home
node_app -->|"routes results"| node_results
node_app -->|"routes chat"| node_chat_ui
node_home -->|"analyzes image"| node_recognition
node_recognition -->|"requests story"| node_story
node_recognition -.->|"loads facts"| node_visitor_info
node_story -->|"reads or writes"| node_story_cache
node_story -->|"uses prompts"| node_story_prompts
node_story -->|"generates story"| node_groq
node_recognition -->|"creates narration"| node_audio
node_audio -->|"synthesizes speech"| node_tts_service
node_home -->|"stores tour result"| node_results
node_results -->|"renders location"| node_map
node_visitor -->|"asks question"| node_chat_ui
node_chat_ui -->|"requests answer"| node_answer
node_answer -->|"rewrites question"| node_query_rewrite
node_query_rewrite -->|"uses prompts"| node_rewrite_prompts
node_query_rewrite -->|"rewrites query"| node_groq
node_answer -->|"requests context"| node_retrieval
node_retrieval -.->|"loads indexed chunks"| node_knowledge
node_answer -->|"uses prompts"| node_answer_prompts
node_answer -->|"generates answer"| node_groq
node_results -.->|"shows visitor facts"| node_visitor_info

click node_app "https://github.com/joodshatnawi/rawi/blob/main/app.py"
click node_home "https://github.com/joodshatnawi/rawi/blob/main/home_page.py"
click node_results "https://github.com/joodshatnawi/rawi/blob/main/result_page.py"
click node_chat_ui "https://github.com/joodshatnawi/rawi/blob/main/chat_page.py"
click node_recognition "https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py"
click node_story "https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py"
click node_audio "https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py"
click node_visitor_info "https://github.com/joodshatnawi/rawi/blob/main/data/facts.json"
click node_map "https://github.com/joodshatnawi/rawi/blob/main/result_page.py"
click node_query_rewrite "https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py"
click node_retrieval "https://github.com/joodshatnawi/rawi/blob/main/rag.py"
click node_answer "https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py"
click node_knowledge "https://github.com/joodshatnawi/rawi/blob/main/data/knowledge.json"
click node_story_cache "https://github.com/joodshatnawi/rawi/blob/main/stories_cache.json"
click node_story_prompts "https://github.com/joodshatnawi/rawi/blob/main/prompts/story_generation.md"
click node_answer_prompts "https://github.com/joodshatnawi/rawi/blob/main/prompts/answer_generation.md"
click node_rewrite_prompts "https://github.com/joodshatnawi/rawi/blob/main/prompts/query_rewriting.md"

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_home,node_results,node_chat_ui toneBlue
class node_recognition,node_story,node_audio,node_visitor_info,node_map toneAmber
class node_query_rewrite,node_retrieval,node_answer,node_groq toneMint
class node_knowledge,node_story_cache,node_story_prompts,node_answer_prompts,node_rewrite_prompts toneRose
class node_visitor,node_tts_service toneIndigo
```

## Components

### Visitor Interface

- [App Router](https://github.com/joodshatnawi/rawi/blob/main/app.py): `app.py`
- [Image Intake](https://github.com/joodshatnawi/rawi/blob/main/home_page.py): `home_page.py`
- [Tour Results](https://github.com/joodshatnawi/rawi/blob/main/result_page.py): `result_page.py`
- [Chat Interface](https://github.com/joodshatnawi/rawi/blob/main/chat_page.py): `chat_page.py`

### Landmark Tour

- [Landmark Detection](https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py): `model_rawi.py`
- [Story Generation](https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py): `model_rawi.py`
- [Audio Narration](https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py): `model_rawi.py`
- [Landmark Information](https://github.com/joodshatnawi/rawi/blob/main/data/facts.json): `data/facts.json`
- [Landmark Map](https://github.com/joodshatnawi/rawi/blob/main/result_page.py): `result_page.py`

### Rawi Chat

- [Query Rewriting](https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py): `model_rawi.py`
- [Knowledge Retrieval](https://github.com/joodshatnawi/rawi/blob/main/rag.py): `rag.py`
- [Answer Generation](https://github.com/joodshatnawi/rawi/blob/main/model_rawi.py): `model_rawi.py`

### Tourism Content

- [Indexed Knowledge](https://github.com/joodshatnawi/rawi/blob/main/data/knowledge.json): `data/knowledge.json`
- [Story Cache](https://github.com/joodshatnawi/rawi/blob/main/stories_cache.json): `stories_cache.json`
- [Story Prompts](https://github.com/joodshatnawi/rawi/blob/main/prompts/story_generation.md): `prompts/story_generation.md`
- [Answer Prompts](https://github.com/joodshatnawi/rawi/blob/main/prompts/answer_generation.md): `prompts/answer_generation.md`
- [Rewrite Prompts](https://github.com/joodshatnawi/rawi/blob/main/prompts/query_rewriting.md): `prompts/query_rewriting.md`

### Other components

- **Visitor**
- **Groq Model API**
- **TTS Service**

## Connections

- Visitor → Image Intake: uploads image (evidence: `README.md`)
- App Router → Image Intake: routes home (evidence: `app.py`)
- App Router → Tour Results: routes results (evidence: `app.py`)
- App Router → Chat Interface: routes chat (evidence: `app.py`)
- Image Intake → Landmark Detection: analyzes image (evidence: `home_page.py`)
- Landmark Detection → Story Generation: requests story (evidence: `model_rawi.py`)
- Landmark Detection → Landmark Information: loads facts
- Story Generation → Story Cache: reads or writes (evidence: `model_rawi.py`)
- Story Generation → Story Prompts: uses prompts (evidence: `README.md`)
- Story Generation → Groq Model API: generates story (evidence: `model_rawi.py`)
- Landmark Detection → Audio Narration: creates narration (evidence: `model_rawi.py`)
- Audio Narration → TTS Service: synthesizes speech (evidence: `README.md`)
- Image Intake → Tour Results: stores tour result (evidence: `home_page.py`)
- Tour Results → Landmark Map: renders location (evidence: `result_page.py`)
- Visitor → Chat Interface: asks question (evidence: `README.md`)
- Chat Interface → Answer Generation: requests answer (evidence: `chat_page.py`)
- Answer Generation → Query Rewriting: rewrites question (evidence: `README.md`)
- Query Rewriting → Rewrite Prompts: uses prompts (evidence: `README.md`)
- Query Rewriting → Groq Model API: rewrites query (evidence: `model_rawi.py`)
- Answer Generation → Knowledge Retrieval: requests context (evidence: `model_rawi.py`)
- Knowledge Retrieval → Indexed Knowledge: loads indexed chunks
- Answer Generation → Answer Prompts: uses prompts (evidence: `README.md`)
- Answer Generation → Groq Model API: generates answer (evidence: `model_rawi.py`)
- Tour Results → Landmark Information: shows visitor facts
