# hoangoanh100720-bot/vietnamfootball architecture

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

- Interactive diagram: https://gitdiagram.com/hoangoanh100720-bot/vietnamfootball
- Repository: https://github.com/hoangoanh100720-bot/vietnamfootball

## Overview

Đây là ứng dụng người hâm mộ đội tuyển Việt Nam, với app Expo tiêu thụ API Express. Luồng chính đi từ các màn hình trận đấu, đội hình, cầu thủ và AI qua API đến các nghiệp vụ backend; dữ liệu trận đấu trực tiếp còn được cập nhật qua socket hoặc polling dự phòng. Các nhánh đáng kể khác gồm đăng nhập, thống kê/điểm cầu thủ, tìm kiếm tri thức lai và thu thập nội dung. Các đường nối dùng bằng chứng README và controller được cung cấp; wiring của những module chưa được trích dẫn được lược bỏ.

Main entry points: [`backend/src/routes/index.ts`](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/routes/index.ts) (API routes), [`backend/src/config/database.ts`](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/config/database.ts) (Cơ sở dữ liệu), [`mobile/app`](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/mobile/app) (Màn hình app), [`backend/src/modules/search/search.service.ts`](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/modules/search/search.service.ts) (Tìm kiếm lai)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Ứng dụng di động"]
  node_mobile_screens["Màn hình app"]
  node_mobile_api["API client<br/>[client.ts]"]
  node_mobile_live["Live score hook<br/>[useLiveScore.ts]"]
  node_mobile_socket["Socket client<br/>[socket.ts]"]
  node_mobile_notify["Thông báo app<br/>[notifications.ts]"]
end

subgraph group_api["API và nghiệp vụ"]
  node_server["API server<br/>[server.ts]"]
  node_routes["API routes<br/>[index.ts]"]
  node_auth["Xác thực"]
  node_matches["Trận đấu"]
  node_squad_players["Đội hình &amp; cầu thủ"]
  node_team_competitions["Đội tuyển &amp; giải đấu"]
  node_stats["Thống kê"]
  node_ratings["Điểm cầu thủ<br/>[rating.service.ts]"]
end

subgraph group_knowledge["AI và tri thức"]
  node_search["Tìm kiếm lai<br/>[search.service.ts]"]
  node_chat["Trợ lý chat<br/>[chat.service.ts]"]
  node_ai["AI dự đoán"]
  node_crawler["Thu thập nội dung"]
  node_embed["Embedding"]
end

subgraph group_platform["Dữ liệu và realtime"]
  node_db[("Cơ sở dữ liệu<br/>[database.ts]")]
  node_socket_service["Socket service<br/>[socket.service.ts]"]
  node_live_job["Live poll job<br/>[livePoll.job.ts]"]
end

node_fan(("Người hâm mộ"))
node_gemini{{"Google Gemini"}}
node_push{{"Dịch vụ push"}}

node_fan -->|"dùng"| node_mobile_screens
node_mobile_screens -->|"gọi API"| node_mobile_api
node_mobile_api -->|"gửi request"| node_server
node_server -->|"chuyển tiếp"| node_routes
node_routes -->|"định tuyến"| node_auth
node_routes -->|"định tuyến"| node_matches
node_routes -->|"định tuyến"| node_squad_players
node_routes -->|"định tuyến"| node_team_competitions
node_routes -->|"định tuyến"| node_stats
node_routes -->|"định tuyến"| node_ratings
node_routes -->|"định tuyến"| node_search
node_routes -->|"định tuyến"| node_chat
node_routes -->|"định tuyến"| node_ai
node_auth -->|"đọc/ghi"| node_db
node_stats -->|"đọc"| node_db
node_ratings -->|"đọc/ghi"| node_db
node_chat -->|"tìm tri thức"| node_search
node_search -->|"nhúng truy vấn"| node_embed
node_embed -.->|"tạo vector"| node_gemini
node_search -->|"truy vấn chỉ mục"| node_db
node_crawler -->|"tạo embedding"| node_embed
node_crawler -->|"lưu tài liệu"| node_db
node_ai -.->|"yêu cầu dự đoán"| node_gemini
node_chat -.->|"tạo câu trả lời"| node_gemini
node_mobile_screens -->|"hiển thị tỷ số"| node_mobile_live
node_mobile_live -->|"nhận cập nhật"| node_mobile_socket
node_mobile_live -->|"poll dự phòng"| node_mobile_api
node_mobile_socket -->|"kết nối"| node_socket_service
node_live_job -->|"phát tỷ số"| node_socket_service
node_socket_service -->|"đẩy cập nhật"| node_mobile_socket
node_mobile_screens -->|"thiết lập thông báo"| node_mobile_notify
node_mobile_notify -->|"đăng ký thiết bị"| node_server
node_push -.->|"gửi thông báo"| node_mobile_notify

click node_mobile_screens "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/mobile/app"
click node_mobile_api "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/api/client.ts"
click node_mobile_live "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/hooks/useLiveScore.ts"
click node_mobile_socket "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/services/socket.ts"
click node_mobile_notify "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/services/notifications.ts"
click node_server "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/server.ts"
click node_routes "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/routes/index.ts"
click node_auth "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/auth"
click node_matches "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/matches"
click node_squad_players "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/squad"
click node_team_competitions "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/team"
click node_stats "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/stats"
click node_ratings "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/rating/rating.service.ts"
click node_search "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/modules/search/search.service.ts"
click node_chat "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/chat/chat.service.ts"
click node_ai "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/ai"
click node_crawler "https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/services/crawl"
click node_embed "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/embedding.service.ts"
click node_db "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/config/database.ts"
click node_socket_service "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/socket.service.ts"
click node_live_job "https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/jobs/livePoll.job.ts"

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_mobile_screens,node_mobile_api,node_mobile_live,node_mobile_socket,node_mobile_notify toneBlue
class node_server,node_routes,node_auth,node_matches,node_squad_players,node_team_competitions,node_stats,node_ratings toneAmber
class node_search,node_chat,node_ai,node_crawler,node_embed toneMint
class node_db,node_socket_service,node_live_job toneRose
class node_fan,node_gemini,node_push toneIndigo
```

## Components

### Ứng dụng di động

- [Màn hình app](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/mobile/app): `mobile/app`
- [API client](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/api/client.ts): `mobile/src/api/client.ts`
- [Live score hook](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/hooks/useLiveScore.ts): `mobile/src/hooks/useLiveScore.ts`
- [Socket client](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/services/socket.ts): `mobile/src/services/socket.ts`
- [Thông báo app](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/mobile/src/services/notifications.ts): `mobile/src/services/notifications.ts`

### API và nghiệp vụ

- [API server](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/server.ts): `backend/src/server.ts`
- [API routes](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/routes/index.ts): `backend/src/routes/index.ts`
- [Xác thực](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/auth): `backend/src/modules/auth`
- [Trận đấu](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/matches): `backend/src/modules/matches`
- [Đội hình & cầu thủ](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/squad): `backend/src/modules/squad`
- [Đội tuyển & giải đấu](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/team): `backend/src/modules/team`
- [Thống kê](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/stats): `backend/src/modules/stats`
- [Điểm cầu thủ](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/rating/rating.service.ts): `backend/src/services/rating/rating.service.ts`

### AI và tri thức

- [Tìm kiếm lai](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/modules/search/search.service.ts): `backend/src/modules/search/search.service.ts`
- [Trợ lý chat](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/chat/chat.service.ts): `backend/src/services/chat/chat.service.ts`
- [AI dự đoán](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/modules/ai): `backend/src/modules/ai`
- [Thu thập nội dung](https://github.com/hoangoanh100720-bot/vietnamfootball/tree/main/backend/src/services/crawl): `backend/src/services/crawl`
- [Embedding](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/embedding.service.ts): `backend/src/services/embedding.service.ts`

### Dữ liệu và realtime

- [Cơ sở dữ liệu](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/config/database.ts): `backend/src/config/database.ts`
- [Socket service](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/services/socket.service.ts): `backend/src/services/socket.service.ts`
- [Live poll job](https://github.com/hoangoanh100720-bot/vietnamfootball/blob/main/backend/src/jobs/livePoll.job.ts): `backend/src/jobs/livePoll.job.ts`

### Other components

- **Người hâm mộ**
- **Google Gemini**
- **Dịch vụ push**

## Connections

- Người hâm mộ → Màn hình app: dùng
- Màn hình app → API client: gọi API
- API client → API server: gửi request
- API server → API routes: chuyển tiếp
- API routes → Xác thực: định tuyến
- API routes → Trận đấu: định tuyến
- API routes → Đội hình & cầu thủ: định tuyến
- API routes → Đội tuyển & giải đấu: định tuyến
- API routes → Thống kê: định tuyến
- API routes → Điểm cầu thủ: định tuyến
- API routes → Tìm kiếm lai: định tuyến
- API routes → Trợ lý chat: định tuyến
- API routes → AI dự đoán: định tuyến
- Xác thực → Cơ sở dữ liệu: đọc/ghi
- Thống kê → Cơ sở dữ liệu: đọc
- Điểm cầu thủ → Cơ sở dữ liệu: đọc/ghi
- Trợ lý chat → Tìm kiếm lai: tìm tri thức
- Tìm kiếm lai → Embedding: nhúng truy vấn
- Embedding → Google Gemini: tạo vector
- Tìm kiếm lai → Cơ sở dữ liệu: truy vấn chỉ mục
- Thu thập nội dung → Embedding: tạo embedding
- Thu thập nội dung → Cơ sở dữ liệu: lưu tài liệu
- AI dự đoán → Google Gemini: yêu cầu dự đoán
- Trợ lý chat → Google Gemini: tạo câu trả lời
- Màn hình app → Live score hook: hiển thị tỷ số
- Live score hook → Socket client: nhận cập nhật
- Live score hook → API client: poll dự phòng
- Socket client → Socket service: kết nối
- Live poll job → Socket service: phát tỷ số
- Socket service → Socket client: đẩy cập nhật
- Màn hình app → Thông báo app: thiết lập thông báo
- Thông báo app → API server: đăng ký thiết bị
- Dịch vụ push → Thông báo app: gửi thông báo
