# zahidpichen/wander-chat architecture

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

- Interactive diagram: https://gitdiagram.com/zahidpichen/wander-chat
- Repository: https://github.com/zahidpichen/wander-chat

## Overview

1. **Repository shape**
   This repo is currently a **Python-first backend service** for an AI travel assistant. The tree shows a single runtime entrypoint, `app.py`, plus a local document corpus in `dataset/` and prebuilt retrieval artifacts in `knowledge_base/`. The README mentions a Next.js frontend, but that frontend is not present in the tree you provided.

2. **Primary application boundary**
   `app.py` is the main orchestration layer. It likely exposes the API surface, handles chat requests, coordinates retrieval, calls the LLM, and returns the final response. In architecture terms, this is the central control plane for the assistant.

3. **Local knowledge sources**
   The `dataset/` folder contains Kerala tourism PDFs such as:
   - `ernakulam.pdf`
   - `alappuzhahrj28.pdf`
   - `munnar-e-brochure.pdf`
   - `Thiruvananthapuram-E-Brochure.pdf`
   
   These are the authoritative local content sources for the assistant’s domain knowledge.

4. **Precomputed retrieval layer**
   The `knowledge_base/` directory contains:
   - `chunk_store.pkl`
   - `vectorstore.index`
   
   These indicate an offline-built RAG index. The PDFs are split into chunks, embedded, and stored in a FAISS-style vector index, with the chunk metadata serialized separately. This is the main data boundary between raw documents and runtime answering.

5. **Runtime retrieval flow**
   At request time, the backend should:
   1. Receive a user travel question.
   2. Search the vector index for relevant chunks from the local Kerala corpus.
   3. Attach the retrieved context to the prompt.
   4. Generate a response with the LLM.
   
   This is the core “local knowledge -> semantic retrieval -> answer synthesis” pipeline.

6. **Live information augmentation**
   The README states the assistant also uses **Tavily API** for live web search. That means the architecture has two knowledge paths:
   - **Static/local RAG** for brochure and tourism content
   - **Dynamic web search** for live events, festivals, shops, and current updates
   
   The backend likely decides when to rely on each path based on query intent.

7. **LLM generation boundary**
   The model layer uses **Google Gemini 2.0 Flash via OpenRouter**. So the repository is not hosting its own model; it is an orchestration client that sends prompts plus retrieved context to an external LLM API and consumes the generated text.

8. **Conversation memory**
   The README says the assistant maintains **short-term conversation history**. That implies the backend keeps recent messages in memory within the request/session flow so follow-up questions can be resolved without reintroducing full context every time.

9. **Domain behavior split**
   The assistant is described as operating in two phases:
   - **Discovery**: recommend destinations based on interests
   - **Planning**: generate itineraries, budgets, and local recommendations
   
   This is an application-level state distinction, probably implemented through prompt logic or request classification rather than separate services.

10. **Configuration and secrets**
   `.env` is the configuration boundary for API keys and runtime settings. Based on the README, it likely holds OpenRouter and Tavily credentials, and possibly other service settings used by `app.py`.

11. **Offline build vs online serving**
   The presence of prebuilt indices in `knowledge_base/` suggests a two-stage architecture:
   - **Build/ingestion stage**: parse PDFs, chunk content, embed text, write index files
   - **Serving stage**: load the index and answer queries through the API
   
   The checked-in artifacts mean the service can start without rebuilding the corpus every time.

12. **Tooling and implementation style**
   The project is intentionally lightweight: pure Python, FastAPI, and direct integrations rather than a larger agent framework. The README explicitly says it avoids LangChain-style abstractions, which means the main logic is likely concentrated in `app.py` with a small number of focused dependencies from `requirements.txt`.

13. **What to draw in an architecture diagram**
   A clear diagram should show:
   - User/client on one side
   - `app.py` / FastAPI backend in the center
   - Local PDF corpus and FAISS-style vector store as the retrieval subsystem
   - OpenRouter/Gemini as the generation subsystem
   - Tavily as the live search subsystem
   - `.env` as configuration input
   
   The key architectural idea is that **Wanderchat is a retrieval-augmented travel assistant that blends local brochure knowledge with live web search, then synthesizes answers through an external LLM**.

Main entry points: [`app.py`](https://github.com/zahidpichen/wander-chat/blob/main/app.py) (App), [`knowledge_base/vectorstore.index`](https://github.com/zahidpichen/wander-chat/blob/main/knowledge_base/vectorstore.index) (Vector Index), [`dataset`](https://github.com/zahidpichen/wander-chat/tree/main/dataset) (PDF Corpus), [`knowledge_base/chunk_store.pkl`](https://github.com/zahidpichen/wander-chat/blob/main/knowledge_base/chunk_store.pkl) (Chunk Store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_client(("User<br/>client"))
  node_app["App<br/>FastAPI backend<br/>[app.py]"]
  node_session["History<br/>conversation state"]
  node_router{{"Query Router<br/>intent logic"}}
  node_rag["RAG Synthesizer<br/>prompt assembly"]
end

subgraph group_knowledge["Knowledge"]
  node_dataset[("PDF Corpus<br/>tourism docs")]
  node_ernakulam["Ernakulam<br/>brochure PDF<br/>[ernakulam.pdf]"]
  node_alappuzha["Alappuzha<br/>brochure PDF<br/>[alappuzhahrj28.pdf]"]
  node_munnar["Munnar<br/>brochure PDF"]
  node_trivandrum["Thiruvananthapuram<br/>brochure PDF"]
  node_index[("Vector Index<br/>FAISS index<br/>[vectorstore.index]")]
  node_chunks[("Chunk Store<br/>pickle metadata<br/>[chunk_store.pkl]")]
end

subgraph group_external["External APIs"]
  node_tavily["Tavily Search<br/>web search API"]
  node_openrouter["OpenRouter<br/>LLM gateway"]
end

subgraph group_config["Config"]
  node_env["Env Vars<br/>config<br/>[.env]"]
end

node_client -->|"chat request"| node_app
node_env -->|"configure"| node_app
node_app -->|"retain"| node_session
node_app -->|"classify"| node_router
node_router -->|"semantic search"| node_index
node_index -->|"lookup metadata"| node_chunks
node_router -->|"live search"| node_tavily
node_router -->|"assemble context"| node_rag
node_dataset -.->|"build index"| node_index
node_dataset -.->|"chunk text"| node_chunks
node_rag -->|"generate"| node_openrouter
node_openrouter -->|"response"| node_app
node_tavily -->|"search results"| node_rag
node_app -->|"answer"| node_client

click node_app "https://github.com/zahidpichen/wander-chat/blob/main/app.py"
click node_dataset "https://github.com/zahidpichen/wander-chat/tree/main/dataset"
click node_ernakulam "https://github.com/zahidpichen/wander-chat/blob/main/dataset/ernakulam.pdf"
click node_alappuzha "https://github.com/zahidpichen/wander-chat/blob/main/dataset/alappuzhahrj28.pdf"
click node_munnar "https://github.com/zahidpichen/wander-chat/blob/main/dataset/munnar-e-brochure.pdf"
click node_trivandrum "https://github.com/zahidpichen/wander-chat/blob/main/dataset/Thiruvananthapuram-E-Brochure.pdf"
click node_index "https://github.com/zahidpichen/wander-chat/blob/main/knowledge_base/vectorstore.index"
click node_chunks "https://github.com/zahidpichen/wander-chat/blob/main/knowledge_base/chunk_store.pkl"
click node_env "https://github.com/zahidpichen/wander-chat/blob/main/.env"

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_client,node_app,node_session,node_router,node_rag toneBlue
class node_dataset,node_ernakulam,node_alappuzha,node_munnar,node_trivandrum,node_index,node_chunks toneAmber
class node_tavily,node_openrouter toneMint
class node_env toneRose
```

## Components

### Runtime

Serving path for chat requests and response synthesis

- **User**: client · Traveler asking questions or planning trips
- [App](https://github.com/zahidpichen/wander-chat/blob/main/app.py): FastAPI backend · Main orchestration layer for chat, retrieval, and answer generation · `app.py`
- **History**: conversation state · Short-term chat context used for follow-up questions
- **Query Router**: intent logic · Selects between discovery, planning, local retrieval, and live search paths
- **RAG Synthesizer**: prompt assembly · Combines retrieved context with the user question for final response generation

### Knowledge

Local tourism corpus and prebuilt retrieval artifacts

- [PDF Corpus](https://github.com/zahidpichen/wander-chat/tree/main/dataset): tourism docs · Authoritative Kerala brochure sources used for offline knowledge · `dataset`
- [Ernakulam](https://github.com/zahidpichen/wander-chat/blob/main/dataset/ernakulam.pdf): brochure PDF · Regional tourism brochure content · `dataset/ernakulam.pdf`
- [Alappuzha](https://github.com/zahidpichen/wander-chat/blob/main/dataset/alappuzhahrj28.pdf): brochure PDF · Regional tourism brochure content · `dataset/alappuzhahrj28.pdf`
- [Munnar](https://github.com/zahidpichen/wander-chat/blob/main/dataset/munnar-e-brochure.pdf): brochure PDF · Regional tourism brochure content · `dataset/munnar-e-brochure.pdf`
- [Thiruvananthapuram](https://github.com/zahidpichen/wander-chat/blob/main/dataset/Thiruvananthapuram-E-Brochure.pdf): brochure PDF · Regional tourism brochure content · `dataset/Thiruvananthapuram-E-Brochure.pdf`
- [Vector Index](https://github.com/zahidpichen/wander-chat/blob/main/knowledge_base/vectorstore.index): FAISS index · Semantic search index over chunked brochure text · `knowledge_base/vectorstore.index`
- [Chunk Store](https://github.com/zahidpichen/wander-chat/blob/main/knowledge_base/chunk_store.pkl): pickle metadata · Serialized chunk text and metadata backing retrieval results · `knowledge_base/chunk_store.pkl`

### External APIs

Third-party services used at query time

- **Tavily Search**: web search API · Live web search for current events, updates, and local services
- **OpenRouter**: LLM gateway · Hosts Gemini 2.0 Flash access used for answer generation

### Config

Repository-level runtime settings

- [Env Vars](https://github.com/zahidpichen/wander-chat/blob/main/.env): config · Secrets and runtime configuration for external services · `.env`

## Connections

- User → App: chat request · User submits a travel question
- Env Vars → App: configure · App reads API keys and runtime settings
- App → History: retain · Keeps short-term conversation history
- App → Query Router: classify · Chooses the appropriate knowledge and generation path
- Query Router → Vector Index: semantic search · Retrieves relevant brochure chunks from the vector index
- Vector Index → Chunk Store: lookup metadata · Maps nearest neighbors back to chunk text and source info
- Query Router → Tavily Search: live search · Fetches current information when the query needs freshness
- Query Router → RAG Synthesizer: assemble context · Prepares the answer prompt from history, retrieval, and search results
- PDF Corpus → Vector Index: build index · Offline PDFs are split and embedded into the retrieval store
- PDF Corpus → Chunk Store: chunk text · Document text and source metadata are serialized for runtime lookup
- RAG Synthesizer → OpenRouter: generate · Sends prompt plus context to the external LLM
- OpenRouter → App: response · Returns synthesized answer text
- Tavily Search → RAG Synthesizer: search results · Adds fresh web snippets into the final prompt
- App → User: answer · Returns the travel recommendation or itinerary
