# farmernettw/mybot architecture

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

- Interactive diagram: https://gitdiagram.com/farmernettw/mybot
- Repository: https://github.com/farmernettw/mybot

## Overview

This repository is a Discord bot for Taiwanese transit, weather, and MyGo meme lookups. Discord users invoke commands or mention the bot; the relevant Cog fetches and interprets data, then sends a response through Discord. Transit and YouBike use TDX, while weather queries the Central Weather Administration. Meme search tokenizes keywords, searches a local inverted index, ranks image metadata, and returns an image view. The README documents the bus, YouBike, and weather capabilities; sampled source also shows the MyGo search feature. Some internal wiring is omitted where excerpts do not establish it.

Main entry points: [`main.py`](https://github.com/farmernettw/mybot/blob/main/main.py) (Bot entry), [`Cogs/ubike.py`](https://github.com/farmernettw/mybot/blob/main/Cogs/ubike.py) (YouBike lookup), [`Cogs/mygo/__init__.py`](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/__init__.py) (Meme commands), [`Cogs/mygo/search_engine.py`](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/search_engine.py) (Meme search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_main["Bot entry<br/>[main.py]"]
  node_config["Bot settings<br/>[cfg.yml]"]
end

subgraph group_transit["Transit lookups"]
  node_bus["Bus routes<br/>[bus.py]"]
  node_ubike["YouBike lookup<br/>[ubike.py]"]
  node_tdx["TDX client<br/>[bus.py]"]
end

subgraph group_weather["Weather lookup"]
  node_weather["Weather forecast<br/>[weather.py]"]
end

subgraph group_mygo["Meme search"]
  node_mygo_cog["Meme commands<br/>[__init__.py]"]
  node_search["Meme search<br/>[search_engine.py]"]
  node_image_map["Image metadata<br/>[image_map.json]"]
  node_index["Inverted index"]
  node_tags["Search tags<br/>[tags.json]"]
end

node_user(("Discord user"))
node_discord(("Discord platform"))
node_tdx_api{{"TDX API"}}
node_cwa{{"CWA API"}}
node_image_host{{"Meme image host"}}

node_user -->|"invokes"| node_discord
node_discord -->|"delivers events"| node_main
node_main -->|"reads settings"| node_config
node_main -->|"loads Cog"| node_bus
node_main -->|"loads Cog"| node_ubike
node_main -->|"loads Cog"| node_weather
node_main -->|"loads Cog"| node_mygo_cog
node_discord -->|"dispatches command"| node_bus
node_bus -->|"requests route data"| node_tdx
node_tdx -->|"fetches data"| node_tdx_api
node_bus -->|"sends route results"| node_discord
node_discord -->|"dispatches command"| node_ubike
node_ubike -->|"requests station data"| node_tdx
node_ubike -->|"requests availability"| node_tdx
node_ubike -->|"sends station status"| node_discord
node_discord -->|"dispatches command"| node_weather
node_weather -->|"requests forecast"| node_cwa
node_weather -->|"sends forecast"| node_discord
node_discord -->|"dispatches search"| node_mygo_cog
node_mygo_cog -->|"searches keyword"| node_search
node_search -->|"loads metadata"| node_image_map
node_search -->|"loads index"| node_index
node_search -->|"loads tags"| node_tags
node_mygo_cog -->|"embeds image"| node_image_host
node_mygo_cog -->|"replies with result"| node_discord

click node_main "https://github.com/farmernettw/mybot/blob/main/main.py"
click node_config "https://github.com/farmernettw/mybot/blob/main/cfg.yml"
click node_bus "https://github.com/farmernettw/mybot/blob/main/Cogs/bus.py"
click node_ubike "https://github.com/farmernettw/mybot/blob/main/Cogs/ubike.py"
click node_tdx "https://github.com/farmernettw/mybot/blob/main/Cogs/bus.py"
click node_weather "https://github.com/farmernettw/mybot/blob/main/Cogs/weather.py"
click node_mygo_cog "https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/__init__.py"
click node_search "https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/search_engine.py"
click node_image_map "https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/data/image_map.json"
click node_index "https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/database/inverted_index.json"
click node_tags "https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/database/tags.json"

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_main,node_config,node_user toneBlue
class node_bus,node_ubike,node_tdx toneAmber
class node_weather,node_tdx_api,node_cwa toneMint
class node_mygo_cog,node_search,node_image_map,node_index,node_tags toneRose
class node_discord,node_image_host toneIndigo
```

## Components

### Bot runtime

- [Bot entry](https://github.com/farmernettw/mybot/blob/main/main.py): `main.py`
- [Bot settings](https://github.com/farmernettw/mybot/blob/main/cfg.yml): `cfg.yml`

### Transit lookups

- [Bus routes](https://github.com/farmernettw/mybot/blob/main/Cogs/bus.py): `Cogs/bus.py`
- [YouBike lookup](https://github.com/farmernettw/mybot/blob/main/Cogs/ubike.py): `Cogs/ubike.py`
- [TDX client](https://github.com/farmernettw/mybot/blob/main/Cogs/bus.py): `Cogs/bus.py`

### Weather lookup

- [Weather forecast](https://github.com/farmernettw/mybot/blob/main/Cogs/weather.py): `Cogs/weather.py`

### Meme search

- [Meme commands](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/__init__.py): `Cogs/mygo/__init__.py`
- [Meme search](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/search_engine.py): `Cogs/mygo/search_engine.py`
- [Image metadata](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/data/image_map.json): `Cogs/mygo/data/image_map.json`
- [Inverted index](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/database/inverted_index.json): `Cogs/mygo/database/inverted_index.json`
- [Search tags](https://github.com/farmernettw/mybot/blob/main/Cogs/mygo/database/tags.json): `Cogs/mygo/database/tags.json`

### Other components

- **Discord user**
- **Discord platform**
- **TDX API**
- **CWA API**
- **Meme image host**

## Connections

- Discord user → Discord platform: invokes
- Discord platform → Bot entry: delivers events
- Bot entry → Bot settings: reads settings
- Bot entry → Bus routes: loads Cog
- Bot entry → YouBike lookup: loads Cog
- Bot entry → Weather forecast: loads Cog
- Bot entry → Meme commands: loads Cog
- Discord platform → Bus routes: dispatches command
- Bus routes → TDX client: requests route data
- TDX client → TDX API: fetches data
- Bus routes → Discord platform: sends route results
- Discord platform → YouBike lookup: dispatches command
- YouBike lookup → TDX client: requests station data
- YouBike lookup → TDX client: requests availability
- YouBike lookup → Discord platform: sends station status
- Discord platform → Weather forecast: dispatches command
- Weather forecast → CWA API: requests forecast
- Weather forecast → Discord platform: sends forecast
- Discord platform → Meme commands: dispatches search
- Meme commands → Meme search: searches keyword
- Meme search → Image metadata: loads metadata
- Meme search → Inverted index: loads index
- Meme search → Search tags: loads tags
- Meme commands → Meme image host: embeds image
- Meme commands → Discord platform: replies with result
