# giakhnhvu/ocean-heart architecture

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

- Interactive diagram: https://gitdiagram.com/giakhnhvu/ocean-heart
- Repository: https://github.com/giakhnhvu/ocean-heart

## Overview

ocean-heart is a Discord bot that creates temporary voice channels when users join configured trigger channels, moves them into the new channel, and deletes empty temporary channels. Its runtime starts a Discord gateway connection; dispatch handlers update in-memory voice occupancy and reconcile guild state. The README only names the project, so capabilities beyond the sampled source are not documented. Edges below follow shown imports and calls; the configured trigger mapping comes from config/tempVoice.json.

Main entry points: [`src/discord/ws.js`](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/ws.js) (Gateway dispatch), [`src/feature/tempVoice.js`](https://github.com/giakhnhvu/ocean-heart/blob/main/src/feature/tempVoice.js) (Temporary voice manager), [`src/common/loadJson.js`](https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/loadJson.js) (JSON loader), [`src/common/logger.js`](https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/logger.js) (Logger)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Gateway runtime"]
  node_main["Runtime entry<br/>[main.js]"]
  node_gateway["Gateway dispatch<br/>[ws.js]"]
  node_rest["Discord REST<br/>[rest.js]"]
end

subgraph group_events["Discord events"]
  node_ready["Ready handler<br/>[ready.js]"]
  node_resumed["Resume handler<br/>[resumed.js]"]
  node_guild["Guild sync handler<br/>[guildCreate.js]"]
  node_voiceevent["Voice update handler"]
  node_channeldelete["Channel delete handler<br/>[channelDelete.js]"]
end

subgraph group_voice["Voice channel lifecycle"]
  node_tempvoice["Temporary voice manager<br/>[tempVoice.js]"]
  node_triggerconfig["Trigger configuration<br/>[tempVoice.json]"]
end

subgraph group_state["Voice state and utilities"]
  node_voicestate[("Voice occupancy state<br/>[voiceState.js]")]
  node_loadjson["JSON loader<br/>[loadJson.js]"]
  node_loadfile["File loader<br/>[loadFile.js]"]
  node_logger["Logger<br/>[logger.js]"]
end

node_operator(("Discord operator"))
node_discord{{"Discord API"}}

node_operator -.->|"configures bot"| node_discord
node_main -->|"connects"| node_gateway
node_gateway -->|"connects gateway"| node_discord
node_gateway -->|"provides REST"| node_rest
node_discord -->|"dispatches events"| node_gateway
node_gateway -->|"dispatches"| node_ready
node_gateway -->|"dispatches"| node_resumed
node_gateway -->|"dispatches"| node_guild
node_gateway -->|"dispatches"| node_voiceevent
node_gateway -->|"dispatches"| node_channeldelete
node_voiceevent -->|"updates state"| node_voicestate
node_voiceevent -->|"manages channels"| node_tempvoice
node_guild -->|"rebuilds state"| node_voicestate
node_guild -->|"cleans channels"| node_tempvoice
node_tempvoice -->|"checks participants"| node_voicestate
node_tempvoice -->|"creates and deletes"| node_rest
node_rest -->|"sends API requests"| node_discord
node_tempvoice -->|"loads triggers"| node_loadjson
node_loadjson -.->|"reads configuration"| node_triggerconfig
node_loadjson -->|"loads text"| node_loadfile
node_loadfile -->|"logs failures"| node_logger
node_loadjson -->|"logs failures"| node_logger
node_gateway -->|"logs errors"| node_logger
node_resumed -->|"logs resume"| node_logger

click node_main "https://github.com/giakhnhvu/ocean-heart/blob/main/src/main.js"
click node_gateway "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/ws.js"
click node_rest "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/rest.js"
click node_ready "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/ready.js"
click node_resumed "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/resumed.js"
click node_guild "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/guildCreate.js"
click node_voiceevent "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/voiceStateUpdate.js"
click node_channeldelete "https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/channelDelete.js"
click node_tempvoice "https://github.com/giakhnhvu/ocean-heart/blob/main/src/feature/tempVoice.js"
click node_triggerconfig "https://github.com/giakhnhvu/ocean-heart/blob/main/config/tempVoice.json"
click node_voicestate "https://github.com/giakhnhvu/ocean-heart/blob/main/src/service/voiceState.js"
click node_loadjson "https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/loadJson.js"
click node_loadfile "https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/loadFile.js"
click node_logger "https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/logger.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_main,node_gateway,node_rest toneBlue
class node_ready,node_resumed,node_guild,node_voiceevent,node_channeldelete toneAmber
class node_tempvoice,node_triggerconfig,node_discord toneMint
class node_voicestate,node_loadjson,node_loadfile,node_logger toneRose
class node_operator toneIndigo
```

## Components

### Gateway runtime

- [Runtime entry](https://github.com/giakhnhvu/ocean-heart/blob/main/src/main.js): `src/main.js`
- [Gateway dispatch](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/ws.js): `src/discord/ws.js`
- [Discord REST](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/rest.js): `src/discord/rest.js`

### Discord events

- [Ready handler](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/ready.js): `src/discord/event/ready.js`
- [Resume handler](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/resumed.js): `src/discord/event/resumed.js`
- [Guild sync handler](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/guildCreate.js): `src/discord/event/guildCreate.js`
- [Voice update handler](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/voiceStateUpdate.js): `src/discord/event/voiceStateUpdate.js`
- [Channel delete handler](https://github.com/giakhnhvu/ocean-heart/blob/main/src/discord/event/channelDelete.js): `src/discord/event/channelDelete.js`

### Voice channel lifecycle

- [Temporary voice manager](https://github.com/giakhnhvu/ocean-heart/blob/main/src/feature/tempVoice.js): `src/feature/tempVoice.js`
- [Trigger configuration](https://github.com/giakhnhvu/ocean-heart/blob/main/config/tempVoice.json): `config/tempVoice.json`

### Voice state and utilities

- [Voice occupancy state](https://github.com/giakhnhvu/ocean-heart/blob/main/src/service/voiceState.js): `src/service/voiceState.js`
- [JSON loader](https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/loadJson.js): `src/common/loadJson.js`
- [File loader](https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/loadFile.js): `src/common/loadFile.js`
- [Logger](https://github.com/giakhnhvu/ocean-heart/blob/main/src/common/logger.js): `src/common/logger.js`

### Other components

- **Discord operator**
- **Discord API**

## Connections

- Discord operator → Discord API: configures bot
- Runtime entry → Gateway dispatch: connects (evidence: `src/main.js`)
- Gateway dispatch → Discord API: connects gateway (evidence: `src/discord/ws.js`)
- Gateway dispatch → Discord REST: provides REST (evidence: `src/discord/ws.js`)
- Discord API → Gateway dispatch: dispatches events (evidence: `src/discord/ws.js`)
- Gateway dispatch → Ready handler: dispatches (evidence: `src/discord/ws.js`)
- Gateway dispatch → Resume handler: dispatches (evidence: `src/discord/ws.js`)
- Gateway dispatch → Guild sync handler: dispatches (evidence: `src/discord/ws.js`)
- Gateway dispatch → Voice update handler: dispatches (evidence: `src/discord/ws.js`)
- Gateway dispatch → Channel delete handler: dispatches (evidence: `src/discord/ws.js`)
- Voice update handler → Voice occupancy state: updates state (evidence: `src/discord/event/voiceStateUpdate.js`)
- Voice update handler → Temporary voice manager: manages channels (evidence: `src/discord/event/voiceStateUpdate.js`)
- Guild sync handler → Voice occupancy state: rebuilds state (evidence: `src/discord/event/guildCreate.js`)
- Guild sync handler → Temporary voice manager: cleans channels (evidence: `src/discord/event/guildCreate.js`)
- Temporary voice manager → Voice occupancy state: checks participants (evidence: `src/feature/tempVoice.js`)
- Temporary voice manager → Discord REST: creates and deletes (evidence: `src/feature/tempVoice.js`)
- Discord REST → Discord API: sends API requests (evidence: `src/discord/rest.js`)
- Temporary voice manager → JSON loader: loads triggers (evidence: `src/feature/tempVoice.js`)
- JSON loader → Trigger configuration: reads configuration
- JSON loader → File loader: loads text (evidence: `src/common/loadJson.js`)
- File loader → Logger: logs failures (evidence: `src/common/loadFile.js`)
- JSON loader → Logger: logs failures (evidence: `src/common/loadJson.js`)
- Gateway dispatch → Logger: logs errors (evidence: `src/discord/ws.js`)
- Resume handler → Logger: logs resume (evidence: `src/discord/event/resumed.js`)
