# sunrisecommunity/sunrise architecture

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

- Interactive diagram: https://gitdiagram.com/sunrisecommunity/sunrise
- Repository: https://github.com/sunrisecommunity/sunrise

## Overview

##### Project type and purpose
- This is a full-stack, monorepo .NET application implementing a private osu! server.
- It provides two backends:
- Sunrise.Server – a real-time Bancho-protocol game server (TCP/UDP packet handlers, chat, multiplayer, lightweight HTTP endpoints)
- Sunrise.API – an HTTP/JSON + WebSocket REST API for the web client (Sunset) and external integrations.

##### File structure
- Top-level service folders:
- Sunrise.Server – packet handlers, chat commands, controllers, middlewares, services, repositories, EF Core migrations, Hangfire jobs.
- Sunrise.API – ASP .NET controllers (Auth, User, Beatmap, Score, WebSocket), serializable request/response DTOs, services, utilities.
- Sunrise.Shared – shared domain models, EF Core DbContext & migrations, repository & service abstractions, helpers, utilities.
- Data & Data.Tests – static asset files (avatars, replays, banners) and test fixtures.
- Sunrise.Server.Tests, Sunrise.Tests – unit and integration tests for both backends and shared components.
- Dockerfile + docker-compose*.yml – container definitions for each service, MySQL, Redis, Prometheus, Grafana, CI (.github/workflows).

##### Key insights from the README
- Core osu! features: login/registration, score submission, leaderboards, chat, multiplayer, spectating, achievements.
- Additional infra: Redis caching & rate limiting, Docker support, database migrations & backups, Prometheus metrics + Grafana.
- External dependency: Observatory beatmap manager.

##### Essential details
- Don’t collapse Redis or MySQL into a generic “Database”; show their distinct roles (cache vs persistent store).
- Docker Compose network to show how containers communicate.
- Hangfire scheduler and recurring job flows separately.
- If zooming in, break Sunrise.Server into PacketListener, Command modules, and Middleware.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Clients"
        OsuClient["osu! Game Client"]:::client
        WebClient["Web Client (Sunset)"]:::client
    end

    Proxy["Reverse Proxy / DNS Mapping"]:::infrastructure

    subgraph "Backend Services"
        subgraph "Game-Protocol Backend"
            SunriseServer["Sunrise.Server"]:::backend
            subgraph "Server Components"
                PacketHandlers["Packet Handlers"]:::backend
                ChatCommands["Chat Commands"]:::backend
                HTTPControllers["HTTP Controllers"]:::backend
                Middlewares["Middlewares"]:::backend
                ServicesServer["Services"]:::backend
                RepositoriesServer["Repositories"]:::backend
                HangfireJobs["Hangfire Recurring Jobs"]:::backend
            end
        end
        subgraph "HTTP/WS API Backend"
            SunriseAPI["Sunrise.API"]:::backend
            subgraph "API Components"
                APIControllers["Controllers"]:::backend
                WebSocketMgr["WebSocket Managers"]:::backend
                DTOs["Request/Response DTOs"]:::backend
                ServicesAPI["Services"]:::backend
                UtilsAPI["Utilities & Extensions"]:::backend
                AttributesAPI["Attributes"]:::backend
            end
        end
    end

    Shared["Sunrise.Shared"]:::library

    subgraph "Data Stores"
        MySQL["MySQL Database"]:::db
        Redis["Redis Cache"]:::db
    end

    External["Observatory\n(Beatmap Manager)"]:::external

    subgraph "Monitoring & Jobs"
        Prometheus["Prometheus"]:::monitor
        Grafana["Grafana"]:::monitor
    end

    OsuClient -->|"TCP/UDP"| SunriseServer
    OsuClient -->|"HTTP"| SunriseServer
    WebClient -->|"HTTP/JSON"| SunriseAPI
    WebClient -->|"WebSocket"| SunriseAPI

    Proxy --> SunriseServer
    Proxy --> SunriseAPI

    SunriseServer -->|"uses"| Shared
    SunriseAPI -->|"uses"| Shared

    Shared -->|"EF Core"| MySQL

    SunriseServer -->|"cache & rate limit"| Redis
    SunriseAPI -->|"cache & rate limit"| Redis

    SunriseAPI -->|"HTTP API Calls"| External

    SunriseServer -->|"recurring jobs"| MySQL
    SunriseAPI -->|"recurring jobs"| MySQL

    SunriseServer -->|"metrics endpoint"| Prometheus
    SunriseAPI -->|"metrics endpoint"| Prometheus
    Prometheus -->|"visualizes"| Grafana

    click SunriseServer "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/"
    click PacketHandlers "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/Packets/PacketHandlers/"
    click ChatCommands "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/Commands/ChatCommands/"
    click HTTPControllers "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/Controllers/"
    click Middlewares "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/Middlewares/"
    click ServicesServer "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/Services/"
    click RepositoriesServer "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Server/Repositories/"
    click HangfireJobs "https://github.com/sunrisecommunity/sunrise/blob/master/Sunrise.Server/Middlewares/HangfireAuthorizationMiddleware.cs"

    click SunriseAPI "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.API/"
    click APIControllers "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.API/Controllers/"
    click WebSocketMgr "https://github.com/sunrisecommunity/sunrise/blob/master/Sunrise.API/Managers/WebSocketManager.cs"
    click DTOs "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.API/Serializable/Request/"
    click ServicesAPI "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.API/Services/"
    click UtilsAPI "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.API/Utils/"
    click AttributesAPI "https://github.com/sunrisecommunity/sunrise/blob/master/Sunrise.API/Attributes/IgnoreMaintenanceAttribute.cs"

    click Shared "https://github.com/sunrisecommunity/sunrise/tree/master/Sunrise.Shared/"

    classDef backend fill:#d5f5e3,stroke:#27ae60
    classDef client fill:#aed6f1,stroke:#2980b9
    classDef db fill:#aed6f1,stroke:#2471a3
    classDef external fill:#fcf3cf,stroke:#f1c40f
    classDef monitor fill:#e8daef,stroke:#8e44ad
    classDef infrastructure fill:#f8c471,stroke:#d35400
    classDef library fill:#d5dbdb,stroke:#566573
```
