|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +Discord Music Bot - A .NET 9 application that provides music playback functionality for Discord servers. Supports YouTube, SoundCloud, Spotify (for playlist fetching), and radio streams. |
| 8 | + |
| 9 | +## Build & Run Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build and run with Docker (recommended) |
| 13 | +docker-compose -f deployment/docker-compose.yml up --build |
| 14 | + |
| 15 | +# Build .NET solution |
| 16 | +dotnet build discord-project.slnx |
| 17 | + |
| 18 | +# Run the Worker (main entry point) |
| 19 | +dotnet run --project src/Worker/Worker.csproj |
| 20 | + |
| 21 | +# Run with specific configuration |
| 22 | +dotnet run --project src/Worker/Worker.csproj -c Release |
| 23 | + |
| 24 | +# Frontend dev server (from src/UI/App) |
| 25 | +npm run dev |
| 26 | + |
| 27 | +# Frontend production build |
| 28 | +npm run build |
| 29 | + |
| 30 | +# Frontend development build |
| 31 | +npm run build:dev |
| 32 | +``` |
| 33 | + |
| 34 | +## Architecture |
| 35 | + |
| 36 | +### Clean Architecture Layers |
| 37 | + |
| 38 | +- **Domain** (`src/Domain/`) - Core entities (Song, User, PlayHistory, RadioSource), event interfaces (`IEventHandler<T>`, `IAsyncEventHandler<T>`), and common abstractions |
| 39 | +- **Application** (`src/Application/`) - Business logic services, DTOs, configuration models, event dispatching system, and service interfaces |
| 40 | +- **Infrastructure** (`src/Infrastructure/`) - Discord bot implementation using NetCord, audio processing with FFmpeg/NAudio, database access via EF Core, YouTube/SoundCloud integration |
| 41 | +- **UI** (`src/UI/`) - Contains two sub-projects: |
| 42 | + - `Api/` - ASP.NET Core REST API with JWT authentication |
| 43 | + - `App/` - Lit-based TypeScript frontend (Vite build) |
| 44 | +- **Worker** (`src/Worker/`) - Main entry point that composes all layers, hosts the Discord bot and web API |
| 45 | + |
| 46 | +### Key Patterns |
| 47 | + |
| 48 | +**Event System**: Custom domain event dispatching via `IEventHandler<T>` and `IAsyncEventHandler<T>`. Handlers are auto-discovered from assemblies at startup via `AddEventing()`. |
| 49 | + |
| 50 | +**Service Registration**: Keyed services pattern for multiple implementations: |
| 51 | +```csharp |
| 52 | +services.AddKeyedScoped<IStreamService, YoutubeService>(nameof(YoutubeService)); |
| 53 | +services.AddKeyedScoped<IStreamService, SoundCloudService>(nameof(SoundCloudService)); |
| 54 | +``` |
| 55 | + |
| 56 | +**Discord Commands**: Organized in `src/Infrastructure/Commands/`: |
| 57 | +- `MusicPlayCommands.cs` - Play/queue commands |
| 58 | +- `MusicActionCommands.cs` - Pause, skip, volume, etc. |
| 59 | +- `AdminCommands.cs` - Admin functionality |
| 60 | +- `MiscCommands.cs` - Utility commands |
| 61 | + |
| 62 | +### Database |
| 63 | + |
| 64 | +PostgreSQL with EF Core. Context: `Infrastructure/Data/DiscordBotContext.cs`. Migrations run automatically on startup. |
| 65 | + |
| 66 | +### Audio Pipeline |
| 67 | + |
| 68 | +Audio flows through: YoutubeDLSharp/YoutubeExplode -> FFmpeg processing (`FfmpegProcessService`) -> NAudio conversion -> NetCord voice client |
| 69 | + |
| 70 | +### Native Dependencies (Linux/Docker) |
| 71 | + |
| 72 | +- FFmpeg |
| 73 | +- libsodium |
| 74 | +- libopus |
| 75 | +- yt-dlp |
| 76 | + |
| 77 | +## Configuration |
| 78 | + |
| 79 | +Environment variables (via docker-compose or appsettings.json): |
| 80 | +- `Discord__Token` - Discord bot token |
| 81 | +- `SpotifySettings__ClientId/ClientSecret` - Spotify API credentials |
| 82 | +- `ConnectionStrings__DefaultConnection` - PostgreSQL connection string |
| 83 | +- `JwtSettings__Secret/Issuer/Audience` - JWT configuration |
| 84 | +- `WebsiteSettings__Url` - Base URL for the web UI |
| 85 | +- `Cors__AllowedOrigins` - Allowed CORS origins |
| 86 | + |
| 87 | +## Frontend Stack |
| 88 | + |
| 89 | +TypeScript with Lit web components, Vaadin Router, Chart.js. Build output goes to `src/Worker/wwwroot/`. |
0 commit comments