# tokioshi/reine architecture

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

- Interactive diagram: https://gitdiagram.com/tokioshi/reine
- Repository: https://github.com/tokioshi/reine

## Overview

Reine Workers is a serverless Discord interactions bot. Discord users invoke slash commands or interact with message components; the Worker routes and verifies requests, dispatches handlers, and returns Discord responses. Its distinct product branches include community information panels, moderation and message/embed utilities, AniList watchlists with scheduled episode checks, and private-thread tickets with close/reopen management. Shared Discord API and D1 modules support these workflows. Some command and scheduled internals were not excerpted, so those links are included only where the README or source index establishes them.

Main entry points: [`handler/commands.js`](https://github.com/tokioshi/reine/blob/main/handler/commands.js) (Command Registry), [`utils/tickets.js`](https://github.com/tokioshi/reine/blob/main/utils/tickets.js) (Ticket Workflow), [`utils/discord.js`](https://github.com/tokioshi/reine/blob/main/utils/discord.js) (Discord Client), [`handler/interactions.js`](https://github.com/tokioshi/reine/blob/main/handler/interactions.js) (Interaction Router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Worker Runtime"]
  node_worker["Worker Entry<br/>[index.js]"]
  node_fetch["HTTP Routes<br/>[fetch.js]"]
  node_scheduled["Scheduled Event<br/>[scheduled.js]"]
end

subgraph group_dispatch["Interaction Dispatch"]
  node_interaction["Interaction Router<br/>[interactions.js]"]
  node_command_registry["Command Registry<br/>[commands.js]"]
  node_moderation["Moderation Commands<br/>[ban.js]"]
  node_messages["Message Utilities<br/>[message.js]"]
  node_embed["Embed Builder<br/>[embed.js]"]
end

subgraph group_community["Community Features"]
  node_panels["Info Panels<br/>[faq.js]"]
  node_payment["Payment Panel<br/>[payment-method.js]"]
  node_price_panels["Price Panels<br/>[bot-price-list.js]"]
  node_server_prices["Server Price Panel"]
end

subgraph group_tracking["Anime Tracking"]
  node_watch_commands["Watch Commands<br/>[watch.js]"]
  node_watchlist_commands["Watchlist Commands<br/>[list.js]"]
  node_watchlist_store[("Watchlist Store<br/>[database.js]")]
  node_episode_checker["Episode Checker<br/>[episode-checker.js]"]
  node_anilist["AniList Client<br/>[anilist.js]"]
  node_notifier["Episode Notifier<br/>[notify.js]"]
end

subgraph group_tickets["Ticket System"]
  node_ticket_command["Ticket Panel Command<br/>[ticket-panel.js]"]
  node_ticket_workflow["Ticket Workflow<br/>[tickets.js]"]
  node_ticket_store[("Ticket Store<br/>[ticket-database.js]")]
end

subgraph group_shared["Shared Services"]
  node_discord_api{{"Discord API"}}
  node_discord_client["Discord Client<br/>[discord.js]"]
  node_response_helpers["Response Helpers<br/>[responses.js]"]
  node_signature_check["Request Verification<br/>[verify.js]"]
  node_d1[("Cloudflare D1")]
end

node_users(("Discord Users"))
node_anilist_service{{"AniList Service"}}

node_users -->|"sends requests"| node_fetch
node_worker -->|"forwards HTTP"| node_fetch
node_worker -->|"forwards schedules"| node_scheduled
node_fetch -->|"routes interactions"| node_interaction
node_fetch -->|"routes registration"| node_command_registry
node_interaction -->|"verifies requests"| node_signature_check
node_interaction -->|"dispatches interactions"| node_command_registry
node_command_registry -->|"registers commands"| node_moderation
node_command_registry -->|"registers commands"| node_messages
node_command_registry -->|"registers commands"| node_embed
node_command_registry -->|"registers commands"| node_watch_commands
node_command_registry -->|"registers commands"| node_watchlist_commands
node_command_registry -->|"registers handlers"| node_panels
node_command_registry -->|"registers handlers"| node_payment
node_command_registry -->|"registers handlers"| node_price_panels
node_command_registry -->|"registers handlers"| node_server_prices
node_command_registry -->|"registers commands"| node_ticket_command
node_watch_commands -->|"looks up anime"| node_anilist
node_watch_commands -->|"updates watchlist"| node_watchlist_store
node_watchlist_commands -->|"reads watchlist"| node_watchlist_store
node_scheduled -->|"starts checks"| node_episode_checker
node_episode_checker -->|"reads and updates"| node_watchlist_store
node_episode_checker -->|"checks releases"| node_anilist
node_episode_checker -->|"notifies episodes"| node_notifier
node_anilist -.->|"requests metadata"| node_anilist_service
node_ticket_command -->|"starts ticket flow"| node_ticket_workflow
node_interaction -.->|"dispatches ticket actions"| node_ticket_workflow
node_scheduled -->|"runs ticket tasks"| node_ticket_workflow
node_ticket_workflow -->|"manages ticket state"| node_ticket_store
node_watchlist_store -.->|"queries D1"| node_d1
node_ticket_store -.->|"queries D1"| node_d1
node_moderation -->|"performs moderation"| node_discord_client
node_messages -.->|"manages messages"| node_discord_client
node_embed -->|"sends and edits"| node_discord_client
node_ticket_workflow -->|"manages threads"| node_discord_client
node_discord_client -->|"calls API"| node_discord_api

click node_worker "https://github.com/tokioshi/reine/blob/main/index.js"
click node_fetch "https://github.com/tokioshi/reine/blob/main/events/fetch.js"
click node_scheduled "https://github.com/tokioshi/reine/blob/main/events/scheduled.js"
click node_interaction "https://github.com/tokioshi/reine/blob/main/handler/interactions.js"
click node_command_registry "https://github.com/tokioshi/reine/blob/main/handler/commands.js"
click node_moderation "https://github.com/tokioshi/reine/blob/main/commands/ban.js"
click node_messages "https://github.com/tokioshi/reine/blob/main/commands/message.js"
click node_embed "https://github.com/tokioshi/reine/blob/main/commands/embed.js"
click node_watch_commands "https://github.com/tokioshi/reine/blob/main/commands/watch.js"
click node_watchlist_commands "https://github.com/tokioshi/reine/blob/main/commands/list.js"
click node_watchlist_store "https://github.com/tokioshi/reine/blob/main/utils/database.js"
click node_episode_checker "https://github.com/tokioshi/reine/blob/main/utils/episode-checker.js"
click node_anilist "https://github.com/tokioshi/reine/blob/main/utils/anilist.js"
click node_notifier "https://github.com/tokioshi/reine/blob/main/utils/notify.js"
click node_panels "https://github.com/tokioshi/reine/blob/main/components/faq.js"
click node_payment "https://github.com/tokioshi/reine/blob/main/components/payment-method.js"
click node_price_panels "https://github.com/tokioshi/reine/blob/main/components/bot-price-list.js"
click node_server_prices "https://github.com/tokioshi/reine/blob/main/components/server-price-list.js"
click node_ticket_command "https://github.com/tokioshi/reine/blob/main/commands/ticket-panel.js"
click node_ticket_workflow "https://github.com/tokioshi/reine/blob/main/utils/tickets.js"
click node_ticket_store "https://github.com/tokioshi/reine/blob/main/utils/ticket-database.js"
click node_discord_client "https://github.com/tokioshi/reine/blob/main/utils/discord.js"
click node_response_helpers "https://github.com/tokioshi/reine/blob/main/utils/responses.js"
click node_signature_check "https://github.com/tokioshi/reine/blob/main/utils/verify.js"

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_worker,node_fetch,node_scheduled,node_users toneBlue
class node_interaction,node_command_registry,node_moderation,node_messages,node_embed toneAmber
class node_panels,node_payment,node_price_panels,node_server_prices toneMint
class node_watch_commands,node_watchlist_commands,node_watchlist_store,node_episode_checker,node_anilist,node_notifier toneRose
class node_ticket_command,node_ticket_workflow,node_ticket_store,node_anilist_service toneIndigo
class node_discord_api,node_discord_client,node_response_helpers,node_signature_check,node_d1 toneTeal
```

## Components

### Worker Runtime

- [Worker Entry](https://github.com/tokioshi/reine/blob/main/index.js): `index.js`
- [HTTP Routes](https://github.com/tokioshi/reine/blob/main/events/fetch.js): `events/fetch.js`
- [Scheduled Event](https://github.com/tokioshi/reine/blob/main/events/scheduled.js): `events/scheduled.js`

### Interaction Dispatch

- [Interaction Router](https://github.com/tokioshi/reine/blob/main/handler/interactions.js): `handler/interactions.js`
- [Command Registry](https://github.com/tokioshi/reine/blob/main/handler/commands.js): `handler/commands.js`
- [Moderation Commands](https://github.com/tokioshi/reine/blob/main/commands/ban.js): `commands/ban.js`
- [Message Utilities](https://github.com/tokioshi/reine/blob/main/commands/message.js): `commands/message.js`
- [Embed Builder](https://github.com/tokioshi/reine/blob/main/commands/embed.js): `commands/embed.js`

### Community Features

- [Info Panels](https://github.com/tokioshi/reine/blob/main/components/faq.js): `components/faq.js`
- [Payment Panel](https://github.com/tokioshi/reine/blob/main/components/payment-method.js): `components/payment-method.js`
- [Price Panels](https://github.com/tokioshi/reine/blob/main/components/bot-price-list.js): `components/bot-price-list.js`
- [Server Price Panel](https://github.com/tokioshi/reine/blob/main/components/server-price-list.js): `components/server-price-list.js`

### Anime Tracking

- [Watch Commands](https://github.com/tokioshi/reine/blob/main/commands/watch.js): `commands/watch.js`
- [Watchlist Commands](https://github.com/tokioshi/reine/blob/main/commands/list.js): `commands/list.js`
- [Watchlist Store](https://github.com/tokioshi/reine/blob/main/utils/database.js): `utils/database.js`
- [Episode Checker](https://github.com/tokioshi/reine/blob/main/utils/episode-checker.js): `utils/episode-checker.js`
- [AniList Client](https://github.com/tokioshi/reine/blob/main/utils/anilist.js): `utils/anilist.js`
- [Episode Notifier](https://github.com/tokioshi/reine/blob/main/utils/notify.js): `utils/notify.js`

### Ticket System

- [Ticket Panel Command](https://github.com/tokioshi/reine/blob/main/commands/ticket-panel.js): `commands/ticket-panel.js`
- [Ticket Workflow](https://github.com/tokioshi/reine/blob/main/utils/tickets.js): `utils/tickets.js`
- [Ticket Store](https://github.com/tokioshi/reine/blob/main/utils/ticket-database.js): `utils/ticket-database.js`

### Shared Services

- **Discord API**
- [Discord Client](https://github.com/tokioshi/reine/blob/main/utils/discord.js): `utils/discord.js`
- [Response Helpers](https://github.com/tokioshi/reine/blob/main/utils/responses.js): `utils/responses.js`
- [Request Verification](https://github.com/tokioshi/reine/blob/main/utils/verify.js): `utils/verify.js`
- **Cloudflare D1**

### Other components

- **Discord Users**
- **AniList Service**

## Connections

- Discord Users → HTTP Routes: sends requests (evidence: `README.md`)
- Worker Entry → HTTP Routes: forwards HTTP (evidence: `index.js`)
- Worker Entry → Scheduled Event: forwards schedules (evidence: `index.js`)
- HTTP Routes → Interaction Router: routes interactions (evidence: `events/fetch.js`)
- HTTP Routes → Command Registry: routes registration (evidence: `events/fetch.js`)
- Interaction Router → Request Verification: verifies requests (evidence: `handler/interactions.js`)
- Interaction Router → Command Registry: dispatches interactions (evidence: `handler/interactions.js`)
- Command Registry → Moderation Commands: registers commands (evidence: `handler/commands.js`)
- Command Registry → Message Utilities: registers commands (evidence: `handler/commands.js`)
- Command Registry → Embed Builder: registers commands (evidence: `handler/commands.js`)
- Command Registry → Watch Commands: registers commands (evidence: `handler/commands.js`)
- Command Registry → Watchlist Commands: registers commands (evidence: `handler/commands.js`)
- Command Registry → Info Panels: registers handlers (evidence: `handler/commands.js`)
- Command Registry → Payment Panel: registers handlers (evidence: `handler/commands.js`)
- Command Registry → Price Panels: registers handlers (evidence: `handler/commands.js`)
- Command Registry → Server Price Panel: registers handlers (evidence: `handler/commands.js`)
- Command Registry → Ticket Panel Command: registers commands (evidence: `handler/commands.js`)
- Watch Commands → AniList Client: looks up anime (evidence: `commands/watch.js`)
- Watch Commands → Watchlist Store: updates watchlist (evidence: `commands/watch.js`)
- Watchlist Commands → Watchlist Store: reads watchlist (evidence: `commands/list.js`)
- Scheduled Event → Episode Checker: starts checks (evidence: `events/scheduled.js`)
- Episode Checker → Watchlist Store: reads and updates (evidence: `utils/episode-checker.js`)
- Episode Checker → AniList Client: checks releases (evidence: `utils/episode-checker.js`)
- Episode Checker → Episode Notifier: notifies episodes (evidence: `utils/episode-checker.js`)
- AniList Client → AniList Service: requests metadata
- Ticket Panel Command → Ticket Workflow: starts ticket flow (evidence: `commands/ticket-panel.js`)
- Interaction Router → Ticket Workflow: dispatches ticket actions
- Scheduled Event → Ticket Workflow: runs ticket tasks (evidence: `events/scheduled.js`)
- Ticket Workflow → Ticket Store: manages ticket state (evidence: `utils/tickets.js`)
- Watchlist Store → Cloudflare D1: queries D1
- Ticket Store → Cloudflare D1: queries D1
- Moderation Commands → Discord Client: performs moderation (evidence: `commands/ban.js`)
- Message Utilities → Discord Client: manages messages (evidence: `commands/message.js`)
- Embed Builder → Discord Client: sends and edits (evidence: `commands/embed.js`)
- Ticket Workflow → Discord Client: manages threads (evidence: `utils/tickets.js`)
- Discord Client → Discord API: calls API (evidence: `utils/discord.js`)
