# cyx-dzy/chinese-traditional-culture architecture

> Architecture diagram of the GitHub repository cyx-dzy/chinese-traditional-culture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cyx-dzy/chinese-traditional-culture
- Repository: https://github.com/cyx-dzy/chinese-traditional-culture

## Overview

1. **Repository shape**
   - This is a two-tier web application with a Python backend and a Vue 3 frontend.
   - The main architectural boundary is between the presentation layer in `frontend/` and the API/data layer in `backend/`.

2. **User-facing application flow**
   - Users enter through the Vue SPA, which provides a home page, category browsing, building detail pages, an about page, and an AI assistant page.
   - Frontend pages pull their content from backend APIs rather than hardcoding the exhibition data.

3. **Frontend subsystem**
   - Built with Vue 3, TypeScript, Vite, and Vue Router.
   - `src/pages/` contains the main screens, `src/components/` holds reusable UI pieces like the main layout and timeline, and `src/services/` centralizes API calls.
   - `public/image/` contains static image assets used in the exhibition experience.

4. **Backend API subsystem**
   - Built with FastAPI and served via Uvicorn.
   - `backend/main.py` is the application entrypoint, while `backend/routers/` splits the API into domain routes: home, buildings, faq, and ai.
   - This routing layout maps directly to the main product surfaces described in the README.

5. **Core data model**
   - The backend is organized around four main tables: `buildings`, `building_details`, `images`, and `faq`.
   - `models.py` and `schemas.py` define the persistence and response shapes used by the API, keeping the frontend-facing contract distinct from raw database storage.

6. **Data access and persistence**
   - `database.py` and `config.py` handle MySQL connection setup and runtime configuration.
   - The database is the system of record for the exhibition content; the frontend never reads the CSVs directly.

7. **Content initialization pipeline**
   - The `backend/sql/` directory contains the CSV source data plus SQL generation/loading scripts.
   - `write_sql.py` is used to seed the database from CSV files, supporting repeatable initialization for the demo dataset.
   - The repository also includes validation/check scripts such as `check_all_tables.py` and `check_faq.py`, suggesting the dataset is verified after import.

8. **AI question-answering path**
   - The AI assistant is exposed through `POST /ai/chat`.
   - The backend is configured to call ModelScope chat-completions services, so the AI experience is an external service integration layered on top of the curated exhibition content.
   - The frontend’s AI page combines FAQ shortcuts with a chat UI, making FAQ content and LLM responses part of one user flow.

9. **Content presentation strategy**
   - The home page aggregates high-level exhibition entry points: featured buildings, timeline, counts/statistics, and FAQ preview.
   - Category pages act as a browse/filter layer, while building detail pages present structured deep content such as history, construction, materials, cultural value, image galleries, and related buildings.
   - This means the frontend is not a generic CRUD app; it is a curated digital exhibit with multiple content depth levels.

10. **Startup and deployment orchestration**
   - `star_server.py` is a convenience orchestrator that checks configuration, ensures the database is populated if needed, and then starts both backend and frontend services.
   - This makes the repo usable as a single demo system while still keeping the runtime boundaries separate.

11. **External dependencies and runtime boundaries**
   - Backend runtime: Python 3 with FastAPI, SQLAlchemy, Uvicorn, and PyMySQL-style MySQL connectivity implied by the config and seeding scripts.
   - Frontend runtime: Node.js toolchain with Vite-based development server.
   - External service: ModelScope is the only clearly identified remote AI dependency.

12. **Diagramming summary**
   - A good architecture diagram should show: browser/UI on the left, Vue SPA in the middle, FastAPI routers as the backend API layer, MySQL as the content store, CSV/SQL scripts as the offline initialization path, and ModelScope as a separate AI service connected only through the AI router.

Main entry points: [`frontend/src/services`](https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/services) (API client), [`backend/main.py`](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/main.py) (API entry), [`frontend/src/App.vue`](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/frontend/src/App.vue) (Vue SPA), [`backend/models.py`](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/models.py) (Data model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_presentation["Presentation"]
  node_browser(("Browser<br/>client"))
  node_spa["Vue SPA<br/>frontend app<br/>[App.vue]"]
  node_router["Route map<br/>vue router<br/>[index.ts]"]
  node_pages["Pages<br/>screens"]
  node_layout["Layout<br/>ui components"]
  node_services["API client<br/>service layer"]
  node_assets["Images<br/>static assets"]
end

subgraph group_backend["Backend API"]
  node_entry["API entry<br/>fastapi app<br/>[main.py]"]
  node_homeapi["Home API<br/>router<br/>[home.py]"]
  node_bldapi["Buildings API<br/>router<br/>[buildings.py]"]
  node_faqapi["FAQ API<br/>router<br/>[faq.py]"]
  node_aiapi["AI API<br/>router<br/>[ai.py]"]
  node_domain["Data model<br/>orm+schemas<br/>[models.py]"]
  node_infra["DB config<br/>config+db<br/>[database.py]"]
  node_mysql[("MySQL<br/>database")]
end

subgraph group_data["Content & Init"]
  node_seed["Seed SQL<br/>init scripts<br/>[write_sql.py]"]
  node_csvs["CSV content<br/>source data"]
end

subgraph group_runtime["Runtime"]
  node_orchestrator["Starter<br/>launcher<br/>[star_server.py]"]
  node_llm(("ModelScope<br/>external ai service"))
end

node_browser -->|"uses"| node_spa
node_spa -->|"navigates"| node_router
node_router -->|"loads"| node_pages
node_spa -->|"composes"| node_layout
node_pages -->|"fetches data"| node_services
node_services -->|"GET home"| node_homeapi
node_services -->|"GET browse/detail"| node_bldapi
node_services -->|"GET faq"| node_faqapi
node_services -->|"POST chat"| node_aiapi
node_entry -->|"mounts"| node_homeapi
node_entry -->|"mounts"| node_bldapi
node_entry -->|"mounts"| node_faqapi
node_entry -->|"mounts"| node_aiapi
node_homeapi -->|"reads shapes"| node_domain
node_bldapi -->|"reads shapes"| node_domain
node_faqapi -->|"reads shapes"| node_domain
node_aiapi -->|"calls"| node_llm
node_domain -->|"persists via"| node_infra
node_infra -->|"connects"| node_mysql
node_seed -->|"reads"| node_csvs
node_seed -->|"loads"| node_mysql
node_orchestrator -->|"ensures data"| node_seed
node_orchestrator -->|"starts backend"| node_entry
node_orchestrator -->|"starts frontend"| node_spa
node_assets -->|"serves images"| node_pages

click node_spa "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/frontend/src/App.vue"
click node_router "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/frontend/src/router/index.ts"
click node_pages "https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/pages"
click node_layout "https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/components"
click node_services "https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/services"
click node_assets "https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/public/image"
click node_entry "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/main.py"
click node_homeapi "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/home.py"
click node_bldapi "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/buildings.py"
click node_faqapi "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/faq.py"
click node_aiapi "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/ai.py"
click node_domain "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/models.py"
click node_infra "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/database.py"
click node_seed "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/sql/write_sql.py"
click node_csvs "https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/backend/sql"
click node_orchestrator "https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/star_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_browser,node_spa,node_router,node_pages,node_layout,node_services,node_assets toneBlue
class node_entry,node_homeapi,node_bldapi,node_faqapi,node_aiapi,node_domain,node_infra,node_mysql toneAmber
class node_seed,node_csvs toneMint
class node_orchestrator,node_llm toneRose
```

## Components

### Presentation

Vue 3 SPA and user-facing content

- **Browser**: client · User entry point
- [Vue SPA](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/frontend/src/App.vue): frontend app · App shell and routed exhibit experience · `frontend/src/App.vue`
- [Route map](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/frontend/src/router/index.ts): vue router · Client-side page navigation · `frontend/src/router/index.ts`
- [Pages](https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/pages): screens · Home, category, detail, about, and AI views · `frontend/src/pages`
- [Layout](https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/components): ui components · Shared shell and timeline UI · `frontend/src/components`
- [API client](https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/src/services): service layer · Centralized backend calls and AI chat client · `frontend/src/services`
- [Images](https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/frontend/public/image): static assets · Exhibition image assets served by the frontend · `frontend/public/image`

### Backend API

FastAPI entrypoint, routers, and data layer

- [API entry](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/main.py): fastapi app · Application startup and router assembly · `backend/main.py`
- [Home API](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/home.py): router · Homepage aggregates and highlights · `backend/routers/home.py`
- [Buildings API](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/buildings.py): router · Category and building detail endpoints · `backend/routers/buildings.py`
- [FAQ API](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/faq.py): router · FAQ content endpoints · `backend/routers/faq.py`
- [AI API](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/routers/ai.py): router · Chat endpoint for assistant flow · `backend/routers/ai.py`
- [Data model](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/models.py): orm+schemas · Persistence models and response schemas · `backend/models.py`
- [DB config](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/database.py): config+db · MySQL connection and runtime configuration · `backend/database.py`
- **MySQL**: database · System of record for exhibition content

### Content & Init

CSV sources and database seeding scripts

- [Seed SQL](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/backend/sql/write_sql.py): init scripts · CSV-to-database loading and validation support · `backend/sql/write_sql.py`
- [CSV content](https://github.com/cyx-dzy/chinese-traditional-culture/tree/main/backend/sql): source data · Buildings, details, images, and FAQ datasets · `backend/sql`

### Runtime

Convenience startup orchestration and external services

- [Starter](https://github.com/cyx-dzy/chinese-traditional-culture/blob/main/star_server.py): launcher · Checks config, seeds data if needed, and starts services · `star_server.py`
- **ModelScope**: external ai service · Remote chat-completions provider

## Connections

- Browser → Vue SPA: uses · Users interact with the Vue application
- Vue SPA → Route map: navigates · Client-side route transitions
- Route map → Pages: loads · Routes resolve to exhibit screens
- Vue SPA → Layout: composes · Shared shell and timeline are reused across pages
- Pages → API client: fetches data · Pages call the API layer for exhibit content
- API client → Home API: GET home · Homepage content and preview data
- API client → Buildings API: GET browse/detail · Category browsing and building detail data
- API client → FAQ API: GET faq · FAQ content for preview and page sections
- API client → AI API: POST chat · Assistant conversation requests
- API entry → Home API: mounts · FastAPI registers the home router
- API entry → Buildings API: mounts · FastAPI registers the buildings router
- API entry → FAQ API: mounts · FastAPI registers the FAQ router
- API entry → AI API: mounts · FastAPI registers the AI router
- Home API → Data model: reads shapes · Uses response and persistence definitions
- Buildings API → Data model: reads shapes · Uses response and persistence definitions
- FAQ API → Data model: reads shapes · Uses response and persistence definitions
- AI API → ModelScope: calls · Delegates chat completion to ModelScope
- Data model → DB config: persists via · ORM and DB access depend on connection setup
- DB config → MySQL: connects · Runtime database connection
- Seed SQL → CSV content: reads · Seeder consumes curated CSV content
- Seed SQL → MySQL: loads · Initializes the database tables
- Starter → Seed SQL: ensures data · Populates the database if needed
- Starter → API entry: starts backend · Launches the FastAPI service
- Starter → Vue SPA: starts frontend · Launches the Vue/Vite service
- Images → Pages: serves images · Frontend pages reference static exhibit images
