# phatphudo/cs547-final-project architecture

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

- Interactive diagram: https://gitdiagram.com/phatphudo/cs547-final-project
- Repository: https://github.com/phatphudo/cs547-final-project
- Video tour (about a minute): https://gitdiagram.com/phatphudo/cs547-final-project/video

## Overview

BayRent Chat is a prototype rental-listing search app. In the main workflow, a renter submits a query in the Streamlit UI; the assistant extracts recognized constraints, searches listings, and formats cited results, with optional OpenAI phrasing. A separate MCP server exposes search and listing-detail tools. The store initializes SQLite from the JSON corpus and builds a local TF-IDF index. Source excerpts support these core calls; the README documents MCP capabilities and optional integrations, whose runtime details are not fully shown.

Main entry points: [`bayrent/store.py`](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py) (Listing Search), [`bayrent/assistant.py`](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py) (Query Assistant), [`bayrent/mcp_server.py`](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/mcp_server.py) (MCP Server), [`app.py`](https://github.com/phatphudo/cs547-final-project/blob/main/app.py) (Chat UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User Interfaces"]
  node_streamlit["Chat UI<br/>[app.py]"]
  node_mcp["MCP Server<br/>[mcp_server.py]"]
end

subgraph group_search["Search Workflow"]
  node_assistant["Query Assistant<br/>[assistant.py]"]
  node_constraints["Constraint Parsing<br/>[assistant.py]"]
  node_retrieval["Listing Search<br/>[store.py]"]
  node_keyword["Keyword Ranking<br/>[store.py]"]
  node_vector["TF-IDF Ranking<br/>[store.py]"]
end

subgraph group_storage["Corpus and Storage"]
  node_corpus["Listing Corpus<br/>[listings.json]"]
  node_loader["Corpus Loader<br/>[data.py]"]
  node_database[("SQLite Listings<br/>[store.py]")]
  node_index[("Local Vector Index<br/>[store.py]")]
end

subgraph group_answer["Answer Generation"]
  node_formatter["Cited Answer<br/>[assistant.py]"]
end

subgraph group_integration["External Integrations"]
  node_openai["OpenAI Responses API"]
end

node_renter(("Renter"))
node_mcp_client(("MCP Client"))

node_renter -->|"submits query"| node_streamlit
node_streamlit -->|"requests answer"| node_assistant
node_assistant -->|"parses query"| node_constraints
node_assistant -->|"searches listings"| node_retrieval
node_retrieval -->|"filters candidates"| node_database
node_retrieval -->|"ranks keywords"| node_keyword
node_retrieval -->|"ranks vectors"| node_vector
node_retrieval -->|"reads index"| node_index
node_loader -->|"loads records"| node_corpus
node_database -->|"seeds from"| node_loader
node_database -->|"builds index"| node_index
node_assistant -->|"formats results"| node_formatter
node_assistant -.->|"phrases optionally"| node_openai
node_mcp_client -->|"invokes tools"| node_mcp
node_mcp -->|"searches listings"| node_retrieval
node_mcp -->|"fetches detail"| node_database

click node_streamlit "https://github.com/phatphudo/cs547-final-project/blob/main/app.py"
click node_assistant "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py"
click node_constraints "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py"
click node_retrieval "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py"
click node_keyword "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py"
click node_vector "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py"
click node_corpus "https://github.com/phatphudo/cs547-final-project/blob/main/data/listings.json"
click node_loader "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/data.py"
click node_database "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py"
click node_index "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py"
click node_formatter "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py"
click node_mcp "https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/mcp_server.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_streamlit,node_mcp,node_mcp_client toneBlue
class node_assistant,node_constraints,node_retrieval,node_keyword,node_vector toneAmber
class node_corpus,node_loader,node_database,node_index toneMint
class node_formatter toneRose
class node_openai,node_renter toneIndigo
```

## Components

### User Interfaces

- [Chat UI](https://github.com/phatphudo/cs547-final-project/blob/main/app.py): `app.py`
- [MCP Server](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/mcp_server.py): `bayrent/mcp_server.py`

### Search Workflow

- [Query Assistant](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py): `bayrent/assistant.py`
- [Constraint Parsing](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py): `bayrent/assistant.py`
- [Listing Search](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py): `bayrent/store.py`
- [Keyword Ranking](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py): `bayrent/store.py`
- [TF-IDF Ranking](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py): `bayrent/store.py`

### Corpus and Storage

- [Listing Corpus](https://github.com/phatphudo/cs547-final-project/blob/main/data/listings.json): `data/listings.json`
- [Corpus Loader](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/data.py): `bayrent/data.py`
- [SQLite Listings](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py): `bayrent/store.py`
- [Local Vector Index](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/store.py): `bayrent/store.py`

### Answer Generation

- [Cited Answer](https://github.com/phatphudo/cs547-final-project/blob/main/bayrent/assistant.py): `bayrent/assistant.py`

### External Integrations

- **OpenAI Responses API**

### Other components

- **Renter**
- **MCP Client**

## Connections

- Renter → Chat UI: submits query (evidence: `app.py`)
- Chat UI → Query Assistant: requests answer (evidence: `app.py`)
- Query Assistant → Constraint Parsing: parses query (evidence: `bayrent/assistant.py`)
- Query Assistant → Listing Search: searches listings (evidence: `bayrent/assistant.py`)
- Listing Search → SQLite Listings: filters candidates (evidence: `bayrent/store.py`)
- Listing Search → Keyword Ranking: ranks keywords (evidence: `bayrent/store.py`)
- Listing Search → TF-IDF Ranking: ranks vectors (evidence: `bayrent/store.py`)
- Listing Search → Local Vector Index: reads index (evidence: `bayrent/store.py`)
- Corpus Loader → Listing Corpus: loads records (evidence: `bayrent/data.py`)
- SQLite Listings → Corpus Loader: seeds from (evidence: `bayrent/store.py`)
- SQLite Listings → Local Vector Index: builds index (evidence: `bayrent/store.py`)
- Query Assistant → Cited Answer: formats results (evidence: `bayrent/assistant.py`)
- Query Assistant → OpenAI Responses API: phrases optionally (evidence: `bayrent/assistant.py`)
- MCP Client → MCP Server: invokes tools (evidence: `README.md`)
- MCP Server → Listing Search: searches listings (evidence: `bayrent/mcp_server.py`)
- MCP Server → SQLite Listings: fetches detail (evidence: `bayrent/mcp_server.py`)
