# thaieaut-engineer/tri-tue-nhan-tao-ai- architecture

> Architecture diagram of the GitHub repository thaieaut-engineer/tri-tue-nhan-tao-ai-, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/thaieaut-engineer/tri-tue-nhan-tao-ai-
- Repository: https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-

## Overview

TourAI is a Flask tour-booking and management site with an AI travel-advice chatbot. Visitors browse tours or submit questions; the chat route manages conversation sessions and invokes the chatbot, which preprocesses questions, matches its knowledge and tour data, and can consult weather or web-search services. Users can book, review, and favorite tours; admins manage catalog, accounts, bookings, reviews, and AI knowledge. README documents continual learning and question harvesting, but excerpts do not show every runtime handoff, so some documented or unverified links are marked accordingly.

Main entry points: [`ai/chatbot.py`](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/chatbot.py) (Chatbot engine), [`database/db.py`](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/database/db.py) (MySQL database), [`app.py`](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/app.py) (Flask app), [`routes/chat_routes.py`](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/chat_routes.py) (Chat routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web entry and routes"]
  node_app["Flask app<br/>[app.py]"]
  node_chat_routes["Chat routes<br/>[chat_routes.py]"]
  node_tour_routes["Tour routes<br/>[tour_routes.py]"]
  node_auth_routes["Auth routes<br/>[auth_routes.py]"]
  node_admin_routes["Admin routes<br/>[admin_routes.py]"]
end

subgraph group_ai["Chatbot and AI"]
  node_chatbot["Chatbot engine<br/>[chatbot.py]"]
  node_preprocess["Text preprocessing<br/>[preprocess.py]"]
  node_training["Intent training<br/>[train_model.py]"]
  node_self_learning["Continual learning<br/>[self_learning.py]"]
  node_qa_generator["QA harvesting<br/>[qa_generator.py]"]
end

subgraph group_travel["Travel services"]
  node_weather["Weather lookup<br/>[weather_service.py]"]
  node_web_search["Directed web search<br/>[web_search.py]"]
  node_weather_apis["Weather APIs"]
  node_web_sources["Web sources"]
end

subgraph group_accounts["Accounts and engagement"]
  node_user_model["User accounts<br/>[user.py]"]
  node_favorite_model["Favorites<br/>[favorite.py]"]
end

subgraph group_persistence["Persistence"]
  node_tour_model["Tour catalog<br/>[tour.py]"]
  node_booking_model["Bookings<br/>[booking.py]"]
  node_review_model["Reviews<br/>[review.py]"]
  node_chat_history["Chat history<br/>[chat_history.py]"]
  node_chat_session["Chat sessions<br/>[chat_session.py]"]
  node_qa_model["QA knowledge<br/>[qa_data.py]"]
  node_mysql[("MySQL database<br/>[db.py]")]
end

node_visitor(("Visitor"))

node_visitor -->|"opens site"| node_app
node_app -->|"registers"| node_chat_routes
node_app -->|"registers"| node_tour_routes
node_app -->|"registers"| node_auth_routes
node_app -->|"registers"| node_admin_routes
node_chat_routes -->|"asks"| node_chatbot
node_chat_routes -->|"manages sessions"| node_chat_session
node_chat_routes -->|"reads and updates"| node_chat_history
node_chat_routes -->|"triggers learning"| node_self_learning
node_chatbot -->|"normalizes text"| node_preprocess
node_chatbot -->|"loads model"| node_training
node_chatbot -->|"loads tour data"| node_tour_model
node_chatbot -.->|"loads QA data"| node_qa_model
node_chatbot -->|"requests weather"| node_weather
node_chatbot -->|"searches web"| node_web_search
node_weather -->|"queries"| node_weather_apis
node_web_search -->|"searches"| node_web_sources
node_tour_routes -->|"retrieves tours"| node_tour_model
node_tour_routes -->|"creates bookings"| node_booking_model
node_tour_routes -->|"creates and reads reviews"| node_review_model
node_tour_routes -->|"toggles favorites"| node_favorite_model
node_auth_routes -->|"authenticates users"| node_user_model
node_auth_routes -->|"retrieves bookings"| node_booking_model
node_auth_routes -->|"retrieves favorites"| node_favorite_model
node_admin_routes -->|"manages learning"| node_self_learning
node_admin_routes -->|"reloads knowledge"| node_chatbot
node_admin_routes -->|"manages tours"| node_tour_model
node_admin_routes -->|"manages QA"| node_qa_model
node_self_learning -->|"scans history"| node_chat_history
node_self_learning -->|"adds learned QA"| node_qa_model
node_qa_generator -->|"harvests answers"| node_chatbot
node_qa_generator -->|"stores harvested QA"| node_qa_model
node_qa_generator -->|"triggers retraining"| node_training
node_tour_model -.->|"reads and writes"| node_mysql
node_booking_model -.->|"reads and writes"| node_mysql
node_review_model -->|"reads and writes"| node_mysql
node_user_model -.->|"reads and writes"| node_mysql
node_favorite_model -.->|"reads and writes"| node_mysql
node_chat_history -.->|"reads and writes"| node_mysql
node_chat_session -->|"reads and writes"| node_mysql
node_qa_model -.->|"reads and writes"| node_mysql

click node_app "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/app.py"
click node_chat_routes "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/chat_routes.py"
click node_tour_routes "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/tour_routes.py"
click node_auth_routes "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/auth_routes.py"
click node_admin_routes "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/admin_routes.py"
click node_chatbot "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/chatbot.py"
click node_preprocess "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/preprocess.py"
click node_training "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/train_model.py"
click node_self_learning "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/self_learning.py"
click node_qa_generator "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/qa_generator.py"
click node_weather "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/weather_service.py"
click node_web_search "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/web_search.py"
click node_tour_model "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/tour.py"
click node_booking_model "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/booking.py"
click node_review_model "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/review.py"
click node_user_model "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/user.py"
click node_favorite_model "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/favorite.py"
click node_chat_history "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/chat_history.py"
click node_chat_session "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/chat_session.py"
click node_qa_model "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/qa_data.py"
click node_mysql "https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/database/db.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_app,node_chat_routes,node_tour_routes,node_auth_routes,node_admin_routes toneBlue
class node_chatbot,node_preprocess,node_training,node_self_learning,node_qa_generator toneAmber
class node_weather,node_web_search,node_weather_apis,node_web_sources toneMint
class node_user_model,node_favorite_model toneRose
class node_tour_model,node_booking_model,node_review_model,node_chat_history,node_chat_session,node_qa_model,node_mysql,node_visitor toneIndigo
```

## Components

### Web entry and routes

- [Flask app](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/app.py): `app.py`
- [Chat routes](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/chat_routes.py): `routes/chat_routes.py`
- [Tour routes](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/tour_routes.py): `routes/tour_routes.py`
- [Auth routes](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/auth_routes.py): `routes/auth_routes.py`
- [Admin routes](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/routes/admin_routes.py): `routes/admin_routes.py`

### Chatbot and AI

- [Chatbot engine](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/chatbot.py): `ai/chatbot.py`
- [Text preprocessing](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/preprocess.py): `ai/preprocess.py`
- [Intent training](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/train_model.py): `ai/train_model.py`
- [Continual learning](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/self_learning.py): `ai/self_learning.py`
- [QA harvesting](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/qa_generator.py): `ai/qa_generator.py`

### Travel services

- [Weather lookup](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/weather_service.py): `ai/weather_service.py`
- [Directed web search](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/ai/web_search.py): `ai/web_search.py`
- **Weather APIs**
- **Web sources**

### Accounts and engagement

- [User accounts](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/user.py): `models/user.py`
- [Favorites](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/favorite.py): `models/favorite.py`

### Persistence

- [Tour catalog](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/tour.py): `models/tour.py`
- [Bookings](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/booking.py): `models/booking.py`
- [Reviews](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/review.py): `models/review.py`
- [Chat history](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/chat_history.py): `models/chat_history.py`
- [Chat sessions](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/chat_session.py): `models/chat_session.py`
- [QA knowledge](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/models/qa_data.py): `models/qa_data.py`
- [MySQL database](https://github.com/thaieaut-engineer/tri-tue-nhan-tao-ai-/blob/main/database/db.py): `database/db.py`

### Other components

- **Visitor**

## Connections

- Visitor → Flask app: opens site (evidence: `README.md`)
- Flask app → Chat routes: registers (evidence: `app.py`)
- Flask app → Tour routes: registers (evidence: `app.py`)
- Flask app → Auth routes: registers (evidence: `app.py`)
- Flask app → Admin routes: registers (evidence: `app.py`)
- Chat routes → Chatbot engine: asks (evidence: `routes/chat_routes.py`)
- Chat routes → Chat sessions: manages sessions (evidence: `routes/chat_routes.py`)
- Chat routes → Chat history: reads and updates (evidence: `routes/chat_routes.py`)
- Chat routes → Continual learning: triggers learning (evidence: `routes/chat_routes.py`)
- Chatbot engine → Text preprocessing: normalizes text (evidence: `ai/chatbot.py`)
- Chatbot engine → Intent training: loads model (evidence: `ai/chatbot.py`)
- Chatbot engine → Tour catalog: loads tour data (evidence: `ai/chatbot.py`)
- Chatbot engine → QA knowledge: loads QA data
- Chatbot engine → Weather lookup: requests weather (evidence: `ai/chatbot.py`)
- Chatbot engine → Directed web search: searches web (evidence: `ai/chatbot.py`)
- Weather lookup → Weather APIs: queries (evidence: `README.md`)
- Directed web search → Web sources: searches (evidence: `README.md`)
- Tour routes → Tour catalog: retrieves tours (evidence: `routes/tour_routes.py`)
- Tour routes → Bookings: creates bookings (evidence: `routes/tour_routes.py`)
- Tour routes → Reviews: creates and reads reviews (evidence: `routes/tour_routes.py`)
- Tour routes → Favorites: toggles favorites (evidence: `routes/tour_routes.py`)
- Auth routes → User accounts: authenticates users (evidence: `routes/auth_routes.py`)
- Auth routes → Bookings: retrieves bookings (evidence: `routes/auth_routes.py`)
- Auth routes → Favorites: retrieves favorites (evidence: `routes/auth_routes.py`)
- Admin routes → Continual learning: manages learning (evidence: `routes/admin_routes.py`)
- Admin routes → Chatbot engine: reloads knowledge (evidence: `routes/admin_routes.py`)
- Admin routes → Tour catalog: manages tours (evidence: `routes/admin_routes.py`)
- Admin routes → QA knowledge: manages QA (evidence: `routes/admin_routes.py`)
- Continual learning → Chat history: scans history (evidence: `ai/self_learning.py`)
- Continual learning → QA knowledge: adds learned QA (evidence: `ai/self_learning.py`)
- QA harvesting → Chatbot engine: harvests answers (evidence: `README.md`)
- QA harvesting → QA knowledge: stores harvested QA (evidence: `ai/qa_generator.py`)
- QA harvesting → Intent training: triggers retraining (evidence: `README.md`)
- Tour catalog → MySQL database: reads and writes (evidence: `models/tour.py`)
- Bookings → MySQL database: reads and writes (evidence: `models/booking.py`)
- Reviews → MySQL database: reads and writes (evidence: `models/review.py`)
- User accounts → MySQL database: reads and writes (evidence: `models/user.py`)
- Favorites → MySQL database: reads and writes (evidence: `models/favorite.py`)
- Chat history → MySQL database: reads and writes (evidence: `models/chat_history.py`)
- Chat sessions → MySQL database: reads and writes (evidence: `models/chat_session.py`)
- QA knowledge → MySQL database: reads and writes (evidence: `models/qa_data.py`)
