# fe4528/jikanrewrite architecture

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

- Interactive diagram: https://gitdiagram.com/fe4528/jikanrewrite
- Repository: https://github.com/fe4528/jikanrewrite

## Overview

Jikan is a Discord bot for tracking members’ voice-channel time and presenting global, server-local, and in-memory realtime leaderboards. Discord interactions enter through the bot runtime and dispatch to commands or button handling; voice-state changes are processed separately, with elapsed time persisted to MySQL and active sessions kept in memory. Developer commands expose operational and diagnostic functions, including leaderboard and telemetry views. The README identifies MySQL and Discord configuration; unsampled command implementations are represented by their existing directories, and no behavior beyond the shown excerpts or README is assumed.

Main entry points: [`index.js`](https://github.com/fe4528/jikanrewrite/blob/main/index.js) (Jikan runtime), [`static/jikan_mysql_manager.js`](https://github.com/fe4528/jikanrewrite/blob/main/static/jikan_mysql_manager.js) (MySQL data access), [`static/utils.js`](https://github.com/fe4528/jikanrewrite/blob/main/static/utils.js) (Shared utilities), [`static/telemetry.js`](https://github.com/fe4528/jikanrewrite/blob/main/static/telemetry.js) (Database telemetry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Bot runtime"]
  node_bot["Jikan runtime<br/>[index.js]"]
  node_reload["Module reloader<br/>[refresh_modules.js]"]
  node_utils["Shared utilities<br/>[utils.js]"]
end

subgraph group_tracking["Voice tracking"]
  node_voice["Voice state handler<br/>[voice_update.js]"]
  node_temp["Active session cache<br/>[temptime.js]"]
end

subgraph group_data["Data and telemetry"]
  node_mysql["MySQL data access"]
  node_store[("MySQL database")]
  node_telemetry["Database telemetry<br/>[telemetry.js]"]
end

subgraph group_commands["Commands and presentation"]
  node_buttons["Telemetry button<br/>[button.js]"]
  node_publiccmd["Public commands"]
  node_devcmd["Developer commands"]
  node_leaderboard["Leaderboard view"]
  node_devtelemetry["Telemetry command<br/>[telemetry.js]"]
  node_locales["Translation data<br/>[default.json]"]
end

node_discord(("Discord users/events"))

node_discord -->|"sends events"| node_bot
node_bot -->|"dispatches voice changes"| node_voice
node_bot -->|"dispatches buttons"| node_buttons
node_bot -->|"loads commands"| node_publiccmd
node_bot -->|"loads commands"| node_devcmd
node_bot -->|"attaches database"| node_mysql
node_bot -->|"clears guild cache"| node_temp
node_voice -->|"tracks sessions"| node_temp
node_voice -->|"persists elapsed time"| node_mysql
node_leaderboard -->|"queries stored rankings"| node_mysql
node_leaderboard -->|"reads realtime rankings"| node_temp
node_devtelemetry -->|"requests statistics"| node_telemetry
node_buttons -->|"requests statistics"| node_telemetry
node_mysql -->|"reads and writes"| node_store
node_mysql -->|"records database calls"| node_telemetry
node_telemetry -->|"formats durations"| node_utils
node_mysql -->|"uses shared helpers"| node_utils
node_publiccmd -.->|"uses translations"| node_utils
node_utils -->|"loads translations"| node_locales
node_bot -.->|"initializes reloader"| node_reload

click node_bot "https://github.com/fe4528/jikanrewrite/blob/main/index.js"
click node_voice "https://github.com/fe4528/jikanrewrite/blob/main/events/voice_update.js"
click node_buttons "https://github.com/fe4528/jikanrewrite/blob/main/events/button.js"
click node_reload "https://github.com/fe4528/jikanrewrite/blob/main/refresh_modules.js"
click node_publiccmd "https://github.com/fe4528/jikanrewrite/tree/main/commands/public"
click node_devcmd "https://github.com/fe4528/jikanrewrite/tree/main/commands/dev"
click node_leaderboard "https://github.com/fe4528/jikanrewrite/blob/main/commands/dev/leaderboards_dev.js"
click node_devtelemetry "https://github.com/fe4528/jikanrewrite/blob/main/commands/dev/telemetry.js"
click node_temp "https://github.com/fe4528/jikanrewrite/blob/main/static/temptime.js"
click node_mysql "https://github.com/fe4528/jikanrewrite/blob/main/static/jikan_mysql_manager.js"
click node_telemetry "https://github.com/fe4528/jikanrewrite/blob/main/static/telemetry.js"
click node_utils "https://github.com/fe4528/jikanrewrite/blob/main/static/utils.js"
click node_locales "https://github.com/fe4528/jikanrewrite/blob/main/locales/default.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_bot,node_reload,node_utils,node_discord toneBlue
class node_voice,node_temp toneAmber
class node_mysql,node_store,node_telemetry toneMint
class node_buttons,node_publiccmd,node_devcmd,node_leaderboard,node_devtelemetry,node_locales toneRose
```

## Components

### Bot runtime

- [Jikan runtime](https://github.com/fe4528/jikanrewrite/blob/main/index.js): `index.js`
- [Module reloader](https://github.com/fe4528/jikanrewrite/blob/main/refresh_modules.js): `refresh_modules.js`
- [Shared utilities](https://github.com/fe4528/jikanrewrite/blob/main/static/utils.js): `static/utils.js`

### Voice tracking

- [Voice state handler](https://github.com/fe4528/jikanrewrite/blob/main/events/voice_update.js): `events/voice_update.js`
- [Active session cache](https://github.com/fe4528/jikanrewrite/blob/main/static/temptime.js): `static/temptime.js`

### Data and telemetry

- [MySQL data access](https://github.com/fe4528/jikanrewrite/blob/main/static/jikan_mysql_manager.js): `static/jikan_mysql_manager.js`
- **MySQL database**
- [Database telemetry](https://github.com/fe4528/jikanrewrite/blob/main/static/telemetry.js): `static/telemetry.js`

### Commands and presentation

- [Telemetry button](https://github.com/fe4528/jikanrewrite/blob/main/events/button.js): `events/button.js`
- [Public commands](https://github.com/fe4528/jikanrewrite/tree/main/commands/public): `commands/public`
- [Developer commands](https://github.com/fe4528/jikanrewrite/tree/main/commands/dev): `commands/dev`
- [Leaderboard view](https://github.com/fe4528/jikanrewrite/blob/main/commands/dev/leaderboards_dev.js): `commands/dev/leaderboards_dev.js`
- [Telemetry command](https://github.com/fe4528/jikanrewrite/blob/main/commands/dev/telemetry.js): `commands/dev/telemetry.js`
- [Translation data](https://github.com/fe4528/jikanrewrite/blob/main/locales/default.json): `locales/default.json`

### Other components

- **Discord users/events**

## Connections

- Discord users/events → Jikan runtime: sends events (evidence: `index.js`)
- Jikan runtime → Voice state handler: dispatches voice changes (evidence: `index.js`)
- Jikan runtime → Telemetry button: dispatches buttons (evidence: `index.js`)
- Jikan runtime → Public commands: loads commands (evidence: `index.js`)
- Jikan runtime → Developer commands: loads commands (evidence: `index.js`)
- Jikan runtime → MySQL data access: attaches database (evidence: `index.js`)
- Jikan runtime → Active session cache: clears guild cache (evidence: `index.js`)
- Voice state handler → Active session cache: tracks sessions (evidence: `events/voice_update.js`)
- Voice state handler → MySQL data access: persists elapsed time (evidence: `events/voice_update.js`)
- Leaderboard view → MySQL data access: queries stored rankings (evidence: `commands/dev/leaderboards_dev.js`)
- Leaderboard view → Active session cache: reads realtime rankings (evidence: `commands/dev/leaderboards_dev.js`)
- Telemetry command → Database telemetry: requests statistics (evidence: `commands/dev/telemetry.js`)
- Telemetry button → Database telemetry: requests statistics (evidence: `events/button.js`)
- MySQL data access → MySQL database: reads and writes (evidence: `static/jikan_mysql_manager.js`)
- MySQL data access → Database telemetry: records database calls (evidence: `static/jikan_mysql_manager.js`)
- Database telemetry → Shared utilities: formats durations (evidence: `static/telemetry.js`)
- MySQL data access → Shared utilities: uses shared helpers (evidence: `static/jikan_mysql_manager.js`)
- Public commands → Shared utilities: uses translations
- Shared utilities → Translation data: loads translations (evidence: `static/utils.js`)
- Jikan runtime → Module reloader: initializes reloader (evidence: `index.js`)
