# xinyi-estate-ntu/ai-agent architecture

> Architecture diagram of the GitHub repository xinyi-estate-ntu/ai-agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/xinyi-estate-ntu/ai-agent
- Repository: https://github.com/xinyi-estate-ntu/ai-agent

## Overview

##### Project Type and Purpose
- This is a data‑driven AI assistant application built with Streamlit. It exposes a chat interface for real‑estate queries, backed by an AI “agent” layer that loads, analyzes, and queries cached housing‐price data.
- The user interacts via a Streamlit frontend (`app.py`), which delegates requests to an internal API module and then through a query‑processing pipeline that in turn calls data‑loading and analysis components.

##### Main Components
a. Frontend Layer
- `app.py`: Streamlit UI and user interaction
b. API Layer
- `AI_agent/api.py`: single entry point for chat and real‑estate queries
c. Processing Pipeline
- `AI_agent/query_processor.py`: orchestrates NL query → structured request
- `AI_agent/data_loader.py`: loads raw data from `data/`, with caching
- `AI_agent/data_analysis.py`: computes statistics and generates charts
d. Supporting Modules
- `AI_agent/config.py`: holds model settings, cache settings, API keys
- `AI_agent/utils.py`: helper functions for logging, formatting, etc.
e. Data Store
- `data/`: CSV or other files with Taipei/New Taipei housing trades
f. External Services
- Groq API (via LangChain–Groq) for model inference
- LangSmith for experiment tracking

##### Relationships & Data Flow
- User → Streamlit (`app.py`)
└─calls→ API (`api.py`)
└─routes to→ Query Processor (`query_processor.py`)
├─fetches→ Raw data via Data Loader (`data_loader.py`)
├─computes→ Insights via Data Analysis (`data_analysis.py`)
└─reads configs→ (`config.py`)
- External: Query Processor and/or API call out to Groq and LangSmith using credentials from `config.py`.

##### Architectural Patterns & Principles
- Clear separation of concerns (UI vs. API vs. processing vs. data).
- Pipeline pattern in Query Processor for modular data operations.
- Caching layer in Data Loader to optimize repeated queries.
- Config centralization for keys and hyperparameters.

## Diagram (Mermaid)

```mermaid
flowchart LR
    User((User))
    app((app.py)):::frontend
    api((api.py)):::backend
    query((query_processor.py)):::backend
    loader((data_loader.py)):::data
    analysis((data_analysis.py)):::data
    datastore((data/)):::data
    groq((Groq API)):::external_service
    langsmith((LangSmith)):::external_service
    config((config.py)):::aux
    utils((utils.py)):::aux
    env((.env.example)):::aux

    User -->|"submit query"| app
    app -->|"call API"| api
    api -->|"route to processor"| query
    query -->|"load cache"| loader
    query -->|"run analysis"| analysis
    loader -->|"read data"| datastore
    query -->|"fetch model inference"| groq
    query -->|"log experiments"| langsmith

    api --- config
    api --- utils
    query --- config
    query --- utils

    click app "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/app.py"
    click api "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/AI_agent/api.py"
    click query "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/AI_agent/query_processor.py"
    click loader "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/AI_agent/data_loader.py"
    click analysis "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/AI_agent/data_analysis.py"
    click config "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/AI_agent/config.py"
    click utils "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/src/AI_agent/utils.py"
    click env "https://github.com/xinyi-estate-ntu/ai-agent/blob/master/.env.example"

    classDef frontend fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef backend fill:#90EE90,stroke:#333,stroke-width:1px
    classDef data fill:#FFA500,stroke:#333,stroke-width:1px
    classDef external_service fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef aux fill:#D3D3D3,stroke:#333,stroke-width:1px
```
