# ahmedayman4/nawy architecture

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

- Interactive diagram: https://gitdiagram.com/ahmedayman4/nawy
- Repository: https://github.com/ahmedayman4/nawy

## Overview

This is a full-stack Egyptian real-estate discovery and AI-consultant platform. Users browse and filter listings, search in natural language, chat for location or compound insights, compare properties, and request price estimates; chat also supports history and evolving preferences. The README documents the main client-to-API relationship and the broader capabilities. Backend startup and several feature implementations are excerpted; frontend-to-API calls and some documented subsystems are not, so those links are omitted where no relationship is evidenced.

Main entry points: [`backend/core/lifespan.py`](https://github.com/ahmedayman4/nawy/blob/main/backend/core/lifespan.py) (Runtime initialization), [`backend/routers/chat.py`](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/chat.py) (Location RAG chat), [`backend/routers/properties.py`](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/properties.py) (Semantic recommendations), [`backend/main.py`](https://github.com/ahmedayman4/nawy/blob/main/backend/main.py) (FastAPI gateway)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web experience"]
  node_browse["Browse listings<br/>[page.tsx]"]
  node_chatui["Consultant chat<br/>[page.tsx]"]
  node_compareui["Compare properties<br/>[page.tsx]"]
  node_predictui["Price predictor<br/>[page.tsx]"]
  node_favorites["Saved favorites<br/>[page.tsx]"]
  node_historyui["Chat history<br/>[page.tsx]"]
end

subgraph group_api["API features"]
  node_api["FastAPI gateway<br/>[main.py]"]
  node_listing["Browse and filter<br/>[properties.py]"]
  node_recommend["Semantic recommendations<br/>[properties.py]"]
  node_chat["Location RAG chat<br/>[chat.py]"]
  node_comparison["AI comparison<br/>[compare.py]"]
  node_price["Price prediction<br/>[predict.py]"]
  node_schemas["Request and response models<br/>[models.py]"]
end

subgraph group_ai["AI and data services"]
  node_startup["Runtime initialization<br/>[lifespan.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_propertydata[("Property dataset")]
  node_propertyvectors[("Property vector store")]
  node_locationvectors[("Location vector store")]
  node_llm{{"Groq language models"}}
  node_price_model["Price model and encoder"]
end

subgraph group_state["Session state"]
  node_helpers["Preference and history helpers<br/>[helpers.py]"]
  node_mongo[("MongoDB")]
  node_localstate[("In-memory fallback")]
end

subgraph group_collection["Data collection"]
  node_scrape_locations["Location collection"]
  node_scrape_properties["Property collection<br/>[nawy_scrapping.py]"]
  node_scrape_finder["Property-finder collection"]
  node_process_locations["Location processing"]
end

node_user(("Property seeker"))

node_user -->|"searches listings"| node_browse
node_user -->|"asks questions"| node_chatui
node_user -->|"compares listings"| node_compareui
node_user -->|"estimates price"| node_predictui
node_user -.->|"saves listings"| node_favorites
node_user -.->|"reviews chats"| node_historyui
node_api -->|"routes requests"| node_listing
node_api -->|"routes requests"| node_recommend
node_api -->|"routes requests"| node_chat
node_api -->|"routes requests"| node_comparison
node_api -->|"routes requests"| node_price
node_startup -->|"loads dataset"| node_propertydata
node_startup -->|"initializes store"| node_propertyvectors
node_startup -->|"initializes store"| node_locationvectors
node_startup -->|"initializes models"| node_llm
node_startup -->|"loads artifacts"| node_price_model
node_startup -->|"connects client"| node_mongo
node_startup -->|"reads URI"| node_config
node_startup -->|"initializes fallback"| node_localstate
node_listing -->|"filters rows"| node_propertydata
node_recommend -->|"searches similar"| node_propertyvectors
node_recommend -->|"filters results"| node_propertydata
node_recommend -->|"generates filters"| node_llm
node_recommend -->|"cleans generated code"| node_helpers
node_chat -->|"loads history"| node_helpers
node_chat -->|"updates preferences"| node_helpers
node_chat -->|"retrieves context"| node_locationvectors
node_chat -->|"rewrites and answers"| node_llm
node_chat -->|"delegates property search"| node_recommend
node_comparison -->|"reads specifications"| node_propertydata
node_comparison -->|"retrieves locations"| node_locationvectors
node_comparison -->|"synthesizes comparison"| node_llm
node_price -->|"predicts price"| node_price_model
node_price -->|"reads price statistics"| node_propertydata
node_helpers -->|"reads and writes"| node_mongo
node_helpers -->|"falls back to"| node_localstate
node_listing -->|"validates payloads"| node_schemas
node_chat -->|"validates payloads"| node_schemas
node_comparison -->|"validates payloads"| node_schemas
node_price -->|"validates payloads"| node_schemas

click node_browse "https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/page.tsx"
click node_chatui "https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/chat/page.tsx"
click node_compareui "https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/compare/page.tsx"
click node_predictui "https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/predictor/page.tsx"
click node_favorites "https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/favorites/page.tsx"
click node_historyui "https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/history/page.tsx"
click node_api "https://github.com/ahmedayman4/nawy/blob/main/backend/main.py"
click node_listing "https://github.com/ahmedayman4/nawy/blob/main/backend/routers/properties.py"
click node_recommend "https://github.com/ahmedayman4/nawy/blob/main/backend/routers/properties.py"
click node_chat "https://github.com/ahmedayman4/nawy/blob/main/backend/routers/chat.py"
click node_comparison "https://github.com/ahmedayman4/nawy/blob/main/backend/routers/compare.py"
click node_price "https://github.com/ahmedayman4/nawy/blob/main/backend/routers/predict.py"
click node_schemas "https://github.com/ahmedayman4/nawy/blob/main/backend/schemas/models.py"
click node_startup "https://github.com/ahmedayman4/nawy/blob/main/backend/core/lifespan.py"
click node_config "https://github.com/ahmedayman4/nawy/blob/main/backend/core/config.py"
click node_helpers "https://github.com/ahmedayman4/nawy/blob/main/backend/utils/helpers.py"
click node_scrape_locations "https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/location_data_collection/location_scrapper.py"
click node_scrape_properties "https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/property_data_collection/nawy_scrapping.py"
click node_scrape_finder "https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/property_finder_collection/property_finder_scraping.py"
click node_process_locations "https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/scratch/process_locations.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_browse,node_chatui,node_compareui,node_predictui,node_favorites,node_historyui toneBlue
class node_api,node_listing,node_recommend,node_chat,node_comparison,node_price,node_schemas toneAmber
class node_startup,node_config,node_propertydata,node_propertyvectors,node_locationvectors,node_llm,node_price_model toneMint
class node_helpers,node_mongo,node_localstate toneRose
class node_scrape_locations,node_scrape_properties,node_scrape_finder,node_process_locations,node_user toneIndigo
```

## Components

### Web experience

- [Browse listings](https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/page.tsx): `frontend/src/app/page.tsx`
- [Consultant chat](https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/chat/page.tsx): `frontend/src/app/chat/page.tsx`
- [Compare properties](https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/compare/page.tsx): `frontend/src/app/compare/page.tsx`
- [Price predictor](https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/predictor/page.tsx): `frontend/src/app/predictor/page.tsx`
- [Saved favorites](https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/favorites/page.tsx): `frontend/src/app/favorites/page.tsx`
- [Chat history](https://github.com/ahmedayman4/nawy/blob/main/frontend/src/app/history/page.tsx): `frontend/src/app/history/page.tsx`

### API features

- [FastAPI gateway](https://github.com/ahmedayman4/nawy/blob/main/backend/main.py): `backend/main.py`
- [Browse and filter](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/properties.py): `backend/routers/properties.py`
- [Semantic recommendations](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/properties.py): `backend/routers/properties.py`
- [Location RAG chat](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/chat.py): `backend/routers/chat.py`
- [AI comparison](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/compare.py): `backend/routers/compare.py`
- [Price prediction](https://github.com/ahmedayman4/nawy/blob/main/backend/routers/predict.py): `backend/routers/predict.py`
- [Request and response models](https://github.com/ahmedayman4/nawy/blob/main/backend/schemas/models.py): `backend/schemas/models.py`

### AI and data services

- [Runtime initialization](https://github.com/ahmedayman4/nawy/blob/main/backend/core/lifespan.py): `backend/core/lifespan.py`
- [Runtime configuration](https://github.com/ahmedayman4/nawy/blob/main/backend/core/config.py): `backend/core/config.py`
- **Property dataset**
- **Property vector store**
- **Location vector store**
- **Groq language models**
- **Price model and encoder**

### Session state

- [Preference and history helpers](https://github.com/ahmedayman4/nawy/blob/main/backend/utils/helpers.py): `backend/utils/helpers.py`
- **MongoDB**
- **In-memory fallback**

### Data collection

- [Location collection](https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/location_data_collection/location_scrapper.py): `01-nawy-scraping/location_data_collection/location_scrapper.py`
- [Property collection](https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/property_data_collection/nawy_scrapping.py): `01-nawy-scraping/property_data_collection/nawy_scrapping.py`
- [Property-finder collection](https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/property_finder_collection/property_finder_scraping.py): `01-nawy-scraping/property_finder_collection/property_finder_scraping.py`
- [Location processing](https://github.com/ahmedayman4/nawy/blob/main/01-nawy-scraping/scratch/process_locations.py): `01-nawy-scraping/scratch/process_locations.py`

### Other components

- **Property seeker**

## Connections

- Property seeker → Browse listings: searches listings (evidence: `README.md`)
- Property seeker → Consultant chat: asks questions (evidence: `README.md`)
- Property seeker → Compare properties: compares listings (evidence: `README.md`)
- Property seeker → Price predictor: estimates price (evidence: `README.md`)
- Property seeker → Saved favorites: saves listings
- Property seeker → Chat history: reviews chats
- FastAPI gateway → Browse and filter: routes requests (evidence: `backend/main.py`)
- FastAPI gateway → Semantic recommendations: routes requests (evidence: `backend/main.py`)
- FastAPI gateway → Location RAG chat: routes requests (evidence: `backend/main.py`)
- FastAPI gateway → AI comparison: routes requests (evidence: `backend/main.py`)
- FastAPI gateway → Price prediction: routes requests (evidence: `backend/main.py`)
- Runtime initialization → Property dataset: loads dataset (evidence: `backend/core/lifespan.py`)
- Runtime initialization → Property vector store: initializes store (evidence: `backend/core/lifespan.py`)
- Runtime initialization → Location vector store: initializes store (evidence: `backend/core/lifespan.py`)
- Runtime initialization → Groq language models: initializes models (evidence: `backend/core/lifespan.py`)
- Runtime initialization → Price model and encoder: loads artifacts (evidence: `backend/core/lifespan.py`)
- Runtime initialization → MongoDB: connects client (evidence: `backend/core/lifespan.py`)
- Runtime initialization → Runtime configuration: reads URI (evidence: `backend/core/lifespan.py`)
- Runtime initialization → In-memory fallback: initializes fallback (evidence: `backend/core/lifespan.py`)
- Browse and filter → Property dataset: filters rows (evidence: `backend/routers/properties.py`)
- Semantic recommendations → Property vector store: searches similar (evidence: `backend/routers/properties.py`)
- Semantic recommendations → Property dataset: filters results (evidence: `backend/routers/properties.py`)
- Semantic recommendations → Groq language models: generates filters (evidence: `README.md`)
- Semantic recommendations → Preference and history helpers: cleans generated code (evidence: `backend/routers/properties.py`)
- Location RAG chat → Preference and history helpers: loads history (evidence: `backend/routers/chat.py`)
- Location RAG chat → Preference and history helpers: updates preferences (evidence: `backend/routers/chat.py`)
- Location RAG chat → Location vector store: retrieves context (evidence: `backend/routers/chat.py`)
- Location RAG chat → Groq language models: rewrites and answers (evidence: `backend/routers/chat.py`)
- Location RAG chat → Semantic recommendations: delegates property search (evidence: `backend/routers/chat.py`)
- AI comparison → Property dataset: reads specifications (evidence: `backend/routers/compare.py`)
- AI comparison → Location vector store: retrieves locations (evidence: `backend/routers/compare.py`)
- AI comparison → Groq language models: synthesizes comparison (evidence: `backend/routers/compare.py`)
- Price prediction → Price model and encoder: predicts price (evidence: `backend/routers/predict.py`)
- Price prediction → Property dataset: reads price statistics (evidence: `backend/routers/predict.py`)
- Preference and history helpers → MongoDB: reads and writes (evidence: `backend/utils/helpers.py`)
- Preference and history helpers → In-memory fallback: falls back to (evidence: `backend/utils/helpers.py`)
- Browse and filter → Request and response models: validates payloads (evidence: `backend/routers/properties.py`)
- Location RAG chat → Request and response models: validates payloads (evidence: `backend/routers/chat.py`)
- AI comparison → Request and response models: validates payloads (evidence: `backend/routers/compare.py`)
- Price prediction → Request and response models: validates payloads (evidence: `backend/routers/predict.py`)
