# gsg9hun/business architecture

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

- Interactive diagram: https://gitdiagram.com/gsg9hun/business
- Repository: https://github.com/gsg9hun/business

## Overview

DC Bot is a Discord music bot with a companion API and mobile app. The primary flow is Discord commands into bot music services, which manage playback, queues, and playlists using persisted state. Mobile clients also have authentication and API capabilities; the API exposes realtime updates and playback snapshots. The excerpts support specific API authentication, OAuth, snapshot, and persistence links. Bot command and music-service connections are shown as unverified because their runtime source was not sampled.

Main entry points: [`DC bot.Persistence/Db/BotDbContext.cs`](https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Db/BotDbContext.cs) (Application database), [`DC bot/Service/SlashCommands/SlashCommandExecutor.cs`](https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/SlashCommands/SlashCommandExecutor.cs) (Command runtime), [`API/Handlers/Auth/AuthHandler.cs`](https://github.com/gsg9hun/business/blob/main/API/Handlers/Auth/AuthHandler.cs) (API authentication), [`API/Snapshots/Playback/PlaybackSnapshotService.cs`](https://github.com/gsg9hun/business/blob/main/API/Snapshots/Playback/PlaybackSnapshotService.cs) (Playback snapshot)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_bot["Discord bot"]
  node_command_runtime["Command runtime"]
  node_music["Music services"]
  node_playlists["Playlist services"]
  node_bot_control["Bot control"]
end

subgraph group_api["Mobile API"]
  node_api_auth["API authentication<br/>[AuthHandler.cs]"]
  node_oauth["Discord OAuth"]
  node_api_routes["API endpoints"]
  node_playback_snapshot["Playback snapshot"]
  node_realtime["Realtime updates"]
end

subgraph group_data["Persistence"]
  node_session_repo["Session repository"]
  node_queue_repo["Queue repository<br/>[QueueRepository.cs]"]
  node_database[("Application database<br/>[BotDbContext.cs]")]
end

subgraph group_mobile["Mobile app"]
  node_mobile_auth["Mobile auth client<br/>[AuthApiService.kt]"]
  node_mobile_storage["Secure session storage"]
end

node_discord_user(("Discord user"))
node_discord(("Discord platform"))
node_mobile_user(("Mobile app user"))

node_discord_user -.->|"issues commands"| node_command_runtime
node_command_runtime -.->|"handles interactions"| node_discord
node_command_runtime -.->|"dispatches music"| node_music
node_command_runtime -.->|"dispatches playlist"| node_playlists
node_bot_control -.->|"controls playback"| node_music
node_mobile_user -.->|"starts login"| node_mobile_auth
node_mobile_auth -->|"posts auth requests"| node_api_auth
node_api_auth -->|"exchanges credentials"| node_oauth
node_oauth -->|"requests OAuth data"| node_discord
node_api_auth -->|"manages sessions"| node_session_repo
node_session_repo -->|"reads and writes"| node_database
node_playlists -.->|"loads playlist data"| node_database
node_music -.->|"manages queue"| node_queue_repo
node_queue_repo -.->|"reads and writes"| node_database
node_api_routes -.->|"serves playback"| node_playback_snapshot
node_playback_snapshot -->|"reads queue"| node_queue_repo
node_playback_snapshot -.->|"reads playback state"| node_database
node_realtime -.->|"listens for changes"| node_database
node_mobile_auth -.->|"stores session"| node_mobile_storage

click node_command_runtime "https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/SlashCommands/SlashCommandExecutor.cs"
click node_music "https://github.com/gsg9hun/business/tree/main/DC%20bot/Service/Music"
click node_playlists "https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/Music/PlaylistService/PlaylistQueryService.cs"
click node_bot_control "https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/BotControl/BotControlWorker.cs"
click node_api_auth "https://github.com/gsg9hun/business/blob/main/API/Handlers/Auth/AuthHandler.cs"
click node_oauth "https://github.com/gsg9hun/business/blob/main/API/Services/Auth/DiscordOAuthService.cs"
click node_api_routes "https://github.com/gsg9hun/business/tree/main/API/Endpoints"
click node_playback_snapshot "https://github.com/gsg9hun/business/blob/main/API/Snapshots/Playback/PlaybackSnapshotService.cs"
click node_realtime "https://github.com/gsg9hun/business/tree/main/API/Realtime"
click node_session_repo "https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Repositories/MobileApps/MobileAppSessionRepository.cs"
click node_queue_repo "https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Repositories/Queue/QueueRepository.cs"
click node_database "https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Db/BotDbContext.cs"
click node_mobile_auth "https://github.com/gsg9hun/business/blob/main/MobileApp/core/network/src/commonMain/kotlin/com/dc/melodiasmario/core/network/auth/AuthApiService.kt"
click node_mobile_storage "https://github.com/gsg9hun/business/blob/main/MobileApp/core/datastore/src/androidMain/kotlin/com/dc/melodiasmario/core/datastore/auth/SecureAuthSessionStorageImpl.kt"

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_command_runtime,node_music,node_playlists,node_bot_control,node_discord_user,node_mobile_user toneBlue
class node_api_auth,node_oauth,node_api_routes,node_playback_snapshot,node_realtime toneAmber
class node_session_repo,node_queue_repo,node_database toneMint
class node_mobile_auth,node_mobile_storage toneRose
class node_discord toneIndigo
```

## Components

### Discord bot

- [Command runtime](https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/SlashCommands/SlashCommandExecutor.cs): `DC bot/Service/SlashCommands/SlashCommandExecutor.cs`
- [Music services](https://github.com/gsg9hun/business/tree/main/DC%20bot/Service/Music): `DC bot/Service/Music`
- [Playlist services](https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/Music/PlaylistService/PlaylistQueryService.cs): `DC bot/Service/Music/PlaylistService/PlaylistQueryService.cs`
- [Bot control](https://github.com/gsg9hun/business/blob/main/DC%20bot/Service/BotControl/BotControlWorker.cs): `DC bot/Service/BotControl/BotControlWorker.cs`

### Mobile API

- [API authentication](https://github.com/gsg9hun/business/blob/main/API/Handlers/Auth/AuthHandler.cs): `API/Handlers/Auth/AuthHandler.cs`
- [Discord OAuth](https://github.com/gsg9hun/business/blob/main/API/Services/Auth/DiscordOAuthService.cs): `API/Services/Auth/DiscordOAuthService.cs`
- [API endpoints](https://github.com/gsg9hun/business/tree/main/API/Endpoints): `API/Endpoints`
- [Playback snapshot](https://github.com/gsg9hun/business/blob/main/API/Snapshots/Playback/PlaybackSnapshotService.cs): `API/Snapshots/Playback/PlaybackSnapshotService.cs`
- [Realtime updates](https://github.com/gsg9hun/business/tree/main/API/Realtime): `API/Realtime`

### Persistence

- [Session repository](https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Repositories/MobileApps/MobileAppSessionRepository.cs): `DC bot.Persistence/Repositories/MobileApps/MobileAppSessionRepository.cs`
- [Queue repository](https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Repositories/Queue/QueueRepository.cs): `DC bot.Persistence/Repositories/Queue/QueueRepository.cs`
- [Application database](https://github.com/gsg9hun/business/blob/main/DC%20bot.Persistence/Db/BotDbContext.cs): `DC bot.Persistence/Db/BotDbContext.cs`

### Mobile app

- [Mobile auth client](https://github.com/gsg9hun/business/blob/main/MobileApp/core/network/src/commonMain/kotlin/com/dc/melodiasmario/core/network/auth/AuthApiService.kt): `MobileApp/core/network/src/commonMain/kotlin/com/dc/melodiasmario/core/network/auth/AuthApiService.kt`
- [Secure session storage](https://github.com/gsg9hun/business/blob/main/MobileApp/core/datastore/src/androidMain/kotlin/com/dc/melodiasmario/core/datastore/auth/SecureAuthSessionStorageImpl.kt): `MobileApp/core/datastore/src/androidMain/kotlin/com/dc/melodiasmario/core/datastore/auth/SecureAuthSessionStorageImpl.kt`

### Other components

- **Discord user**
- **Discord platform**
- **Mobile app user**

## Connections

- Discord user → Command runtime: issues commands
- Command runtime → Discord platform: handles interactions
- Command runtime → Music services: dispatches music
- Command runtime → Playlist services: dispatches playlist
- Bot control → Music services: controls playback
- Mobile app user → Mobile auth client: starts login
- Mobile auth client → API authentication: posts auth requests (evidence: `MobileApp/core/network/src/commonMain/kotlin/com/dc/melodiasmario/core/network/auth/AuthApiService.kt`)
- API authentication → Discord OAuth: exchanges credentials (evidence: `API/Handlers/Auth/AuthHandler.cs`)
- Discord OAuth → Discord platform: requests OAuth data (evidence: `API/Services/Auth/DiscordOAuthService.cs`)
- API authentication → Session repository: manages sessions (evidence: `API/Handlers/Auth/AuthHandler.cs`)
- Session repository → Application database: reads and writes (evidence: `DC bot.Persistence/Repositories/MobileApps/MobileAppSessionRepository.cs`)
- Playlist services → Application database: loads playlist data
- Music services → Queue repository: manages queue
- Queue repository → Application database: reads and writes (evidence: `DC bot.Persistence/Repositories/Queue/QueueRepository.cs`)
- API endpoints → Playback snapshot: serves playback
- Playback snapshot → Queue repository: reads queue (evidence: `API/Snapshots/Playback/PlaybackSnapshotService.cs`)
- Playback snapshot → Application database: reads playback state
- Realtime updates → Application database: listens for changes
- Mobile auth client → Secure session storage: stores session
