# lu1120/tibame_test architecture

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

- Interactive diagram: https://gitdiagram.com/lu1120/tibame_test
- Repository: https://github.com/lu1120/tibame_test

## Overview

#### Purpose and Scope
A Python-based data-collection repository centered on Taiwan transport/tourism data. It contains separate crawlers for TDX and media/blog sources, plus producer/worker scripts suggesting asynchronous or batch-oriented execution. Root JSON files and `attraction_*` files appear to be collected/exported artifacts.

#### Entry Points and Execution Roles
- TDX collection entry point: `crawler/crawler_tdx.py`
- Blog/media collection entry point: `crawler/crawler_blog.py`
- Job-producing scripts: `crawler/producer.py`, `crawler/producer_mediaTW.py`
- Worker consumers: `crawler/worker.py`
- Task definitions or task-specific dispatch: `crawler/tasks_crawler_tdx.py`, `crawler/tasks_crawler_mediaTW.py`

The expected control pattern is producer → task payload → worker → source-specific crawler → local output.

#### Source-Specific Crawling
TDX integration is isolated around `crawler/crawler_tdx.py` and `crawler/tasks_crawler_tdx.py`. The checked-in environment includes `tdx_proxy`, provided by `motc-tdx-proxy`, indicating integration with Taiwan Ministry of Transportation and Communications TDX APIs.

Media/Taiwan crawling is separated from TDX flow in `crawler/crawler_blog.py`, `crawler/tasks_crawler_mediaTW.py`, and `crawler/producer_mediaTW.py`. This boundary allows source-specific request, parsing, and scheduling behavior.

#### Configuration Boundary
`crawler/config.py` is the central likely location for crawler settings, credentials, endpoints, queue/broker configuration, or output parameters. Producer, worker, and crawler scripts should depend on this module rather than duplicating operational values.

#### Processing and Persistence Flow
Crawler outputs are persisted locally rather than through an evident database layer. Repository-level data includes `data_d.json` and `trail_data.json`; files named `attraction_345040000g_*` likely represent individual attraction records or raw/result snapshots. This makes filesystem/JSON the material persistence boundary and implies downstream consumers read generated files directly.

#### Runtime and Infrastructure
The runtime is Python 3.12, represented by `crawler/myenv/pyvenv.cfg` and `crawler/myenv/bin/python`. HTTP access is supported by checked-in `requests` and `urllib3` packages. `docker-compose-local.yml` is the available local infrastructure definition and likely supports producer/worker dependencies; its exact services cannot be determined from the provided tree.

#### Architecture-Defining Components
1. Configuration: `crawler/config.py`
2. TDX ingestion: `crawler/crawler_tdx.py`
3. Blog/media ingestion: `crawler/crawler_blog.py`
4. TDX task orchestration: `crawler/tasks_crawler_tdx.py`
5. Media task orchestration: `crawler/tasks_crawler_mediaTW.py`
6. Producer-side dispatch: `crawler/producer.py`, `crawler/producer_mediaTW.py`
7. Worker-side execution: `crawler/worker.py`
8. JSON/file output dataset: `data_d.json`, `trail_data.json`

Main entry points: [`crawler/worker.py`](https://github.com/lu1120/tibame_test/blob/main/crawler/worker.py) (Worker), [`crawler/crawler_tdx.py`](https://github.com/lu1120/tibame_test/blob/main/crawler/crawler_tdx.py) (TDX Crawler), [`crawler/config.py`](https://github.com/lu1120/tibame_test/blob/main/crawler/config.py) (Crawler Config), [`crawler/crawler_blog.py`](https://github.com/lu1120/tibame_test/blob/main/crawler/crawler_blog.py) (Blog Crawler)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_dispatch["Job Dispatch"]
  node_tdx_producer["TDX Producer<br/>producer script<br/>[producer.py]"]
  node_media_producer["Media Producer<br/>producer script"]
  node_tdx_tasks["TDX Tasks<br/>task dispatch"]
  node_media_tasks["Media Tasks<br/>task dispatch"]
  node_worker["Worker<br/>task consumer<br/>[worker.py]"]
end

subgraph group_ingestion["Source Ingestion"]
  node_tdx_crawler["TDX Crawler<br/>ingestion script<br/>[crawler_tdx.py]"]
  node_blog_crawler["Blog Crawler<br/>ingestion script<br/>[crawler_blog.py]"]
  node_tdx_api{{"Taiwan TDX APIs<br/>external API"}}
  node_media_sources{{"Blog &amp; Media Sources<br/>external sources"}}
end

subgraph group_storage["Local Data"]
  node_json_dataset["JSON Datasets<br/>file dataset<br/>[data_d.json]"]
  node_trail_dataset["Trail Dataset<br/>file dataset<br/>[trail_data.json]"]
  node_attraction_exports["Attraction Exports<br/>file snapshots"]
end

node_config["Crawler Config<br/>configuration<br/>[config.py]"]
node_docker_local["Local Infrastructure<br/>compose environment"]
node_python_runtime["Python 3.12 Runtime<br/>[pyvenv.cfg]"]

node_tdx_producer -->|"submits jobs"| node_tdx_tasks
node_media_producer -->|"submits jobs"| node_media_tasks
node_tdx_tasks -->|"task payloads"| node_worker
node_media_tasks -->|"task payloads"| node_worker
node_worker -->|"executes"| node_tdx_crawler
node_worker -->|"executes"| node_blog_crawler
node_tdx_crawler -->|"fetches transport data"| node_tdx_api
node_blog_crawler -->|"collects content"| node_media_sources
node_tdx_crawler -->|"writes results"| node_json_dataset
node_tdx_crawler -->|"writes trail data"| node_trail_dataset
node_tdx_crawler -->|"writes attraction records"| node_attraction_exports
node_blog_crawler -->|"writes results"| node_json_dataset
node_config -.->|"settings"| node_tdx_producer
node_config -.->|"settings"| node_media_producer
node_config -.->|"settings"| node_worker
node_config -.->|"settings"| node_tdx_crawler
node_config -.->|"settings"| node_blog_crawler
node_docker_local -.->|"local dependencies"| node_worker
node_python_runtime -.->|"runs"| node_worker

click node_config "https://github.com/lu1120/tibame_test/blob/main/crawler/config.py"
click node_tdx_producer "https://github.com/lu1120/tibame_test/blob/main/crawler/producer.py"
click node_media_producer "https://github.com/lu1120/tibame_test/blob/main/crawler/producer_mediaTW.py"
click node_tdx_tasks "https://github.com/lu1120/tibame_test/blob/main/crawler/tasks_crawler_tdx.py"
click node_media_tasks "https://github.com/lu1120/tibame_test/blob/main/crawler/tasks_crawler_mediaTW.py"
click node_worker "https://github.com/lu1120/tibame_test/blob/main/crawler/worker.py"
click node_tdx_crawler "https://github.com/lu1120/tibame_test/blob/main/crawler/crawler_tdx.py"
click node_blog_crawler "https://github.com/lu1120/tibame_test/blob/main/crawler/crawler_blog.py"
click node_json_dataset "https://github.com/lu1120/tibame_test/blob/main/data_d.json"
click node_trail_dataset "https://github.com/lu1120/tibame_test/blob/main/trail_data.json"
click node_docker_local "https://github.com/lu1120/tibame_test/blob/main/docker-compose-local.yml"
click node_python_runtime "https://github.com/lu1120/tibame_test/blob/main/crawler/myenv/pyvenv.cfg"

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_tdx_producer,node_media_producer,node_tdx_tasks,node_media_tasks,node_worker toneBlue
class node_tdx_crawler,node_blog_crawler,node_tdx_api,node_media_sources toneAmber
class node_json_dataset,node_trail_dataset,node_attraction_exports toneMint
class node_config,node_docker_local,node_python_runtime toneNeutral
```

## Components

### Job Dispatch

- [TDX Producer](https://github.com/lu1120/tibame_test/blob/main/crawler/producer.py): producer script · `crawler/producer.py`
- [Media Producer](https://github.com/lu1120/tibame_test/blob/main/crawler/producer_mediaTW.py): producer script · `crawler/producer_mediaTW.py`
- [TDX Tasks](https://github.com/lu1120/tibame_test/blob/main/crawler/tasks_crawler_tdx.py): task dispatch · `crawler/tasks_crawler_tdx.py`
- [Media Tasks](https://github.com/lu1120/tibame_test/blob/main/crawler/tasks_crawler_mediaTW.py): task dispatch · `crawler/tasks_crawler_mediaTW.py`
- [Worker](https://github.com/lu1120/tibame_test/blob/main/crawler/worker.py): task consumer · Executes dispatched source-specific crawl work. · `crawler/worker.py`

### Source Ingestion

- [TDX Crawler](https://github.com/lu1120/tibame_test/blob/main/crawler/crawler_tdx.py): ingestion script · `crawler/crawler_tdx.py`
- [Blog Crawler](https://github.com/lu1120/tibame_test/blob/main/crawler/crawler_blog.py): ingestion script · `crawler/crawler_blog.py`
- **Taiwan TDX APIs**: external API · Transport and tourism source accessed through the TDX integration.
- **Blog & Media Sources**: external sources

### Local Data

- [JSON Datasets](https://github.com/lu1120/tibame_test/blob/main/data_d.json): file dataset · Collected and exported JSON data read directly from the filesystem. · `data_d.json`
- [Trail Dataset](https://github.com/lu1120/tibame_test/blob/main/trail_data.json): file dataset · `trail_data.json`
- **Attraction Exports**: file snapshots · Individual attraction raw or result records.

### Other components

- [Crawler Config](https://github.com/lu1120/tibame_test/blob/main/crawler/config.py): configuration · Central settings for endpoints, credentials, queues, and output. · `crawler/config.py`
- [Local Infrastructure](https://github.com/lu1120/tibame_test/blob/main/docker-compose-local.yml): compose environment · Local producer/worker dependency definition. · `docker-compose-local.yml`
- [Python 3.12 Runtime](https://github.com/lu1120/tibame_test/blob/main/crawler/myenv/pyvenv.cfg): runtime · `crawler/myenv/pyvenv.cfg`

## Connections

- TDX Producer → TDX Tasks: submits jobs
- Media Producer → Media Tasks: submits jobs
- TDX Tasks → Worker: task payloads
- Media Tasks → Worker: task payloads
- Worker → TDX Crawler: executes
- Worker → Blog Crawler: executes
- TDX Crawler → Taiwan TDX APIs: fetches transport data
- Blog Crawler → Blog & Media Sources: collects content
- TDX Crawler → JSON Datasets: writes results
- TDX Crawler → Trail Dataset: writes trail data
- TDX Crawler → Attraction Exports: writes attraction records
- Blog Crawler → JSON Datasets: writes results
- Crawler Config → TDX Producer: settings
- Crawler Config → Media Producer: settings
- Crawler Config → Worker: settings
- Crawler Config → TDX Crawler: settings
- Crawler Config → Blog Crawler: settings
- Local Infrastructure → Worker: local dependencies
- Python 3.12 Runtime → Worker: runs
