# starrydriver/musicplay architecture

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

- Interactive diagram: https://gitdiagram.com/starrydriver/musicplay
- Repository: https://github.com/starrydriver/musicplay

## Overview

##### Project type and purpose
- This is a static‐site, browser‐based rhythm game built with the Astro framework and TypeScript.
- The `src/pages` folder contains two routes: a landing page (`index.astro`) and the game page (`game.astro`).
- The `src/scripts` folder holds the core game logic (`game.ts`) and supporting scripts.
- All multimedia assets (audio, images, note‐sheet JSON) live under `public/`.

##### File structure
- Top level:
- configuration files (`astro.config.mjs`, `tsconfig.json`, `package.json`, etc.)
- `public/` folder with static assets served at runtime
- `src/` folder with Astro pages and TS scripts
- No backend or database layers—this is purely front‐end and static hosting.
- The build pipeline uses Astro + Node to produce a static output for deployment.

##### Key README insights
- The project is in active development, focusing on screen‐size adaptation and richer game modes.
- Future plans include new UI layouts and enhanced audio/visual/rhythm feedback.

##### Main components
a. Developer workstation
- Code repository (Git) containing all source files
- Build tools: Node.js + Astro + TypeScript compiler
b. Build & Deployment
- Astro build process (reads `src/`, processes `.astro` + `.ts` → outputs HTML/CSS/JS)
- Static assets from `public/` are copied directly
- Deployment target: any static‐hosting/CDN (Netlify, Vercel, S3+CloudFront, etc.)
c. Client (Browser)
- Receives static HTML + JS bundle + assets
- Executes `game.ts` to render canvas/DOM game, loads audio & JSON sheets via HTTP
d. Asset store
- Audio files (`public/audio`)
- Images (`public/images`)
- Sequence data (`public/sheets/*.json`)

##### Relationships & interactions
- Developer push → CI/CD → Astro build → Deploy static assets → Client request
- Browser requests `/game` page → server/host returns generated HTML + JS → game script fetches audio + JSON → user interacts → script updates DOM/canvas
- All data flows are unidirectional from host → client; game logic runs entirely client‐side.

##### Architectural patterns & principles
- Static‐site generation (SSG) via Astro for fast page loads
- Modular code separation: `.astro` pages for layout, TS modules for game logic
- Public folder as clear demarcation for static assets
- Future extensibility: new game modes can be additional TS modules and JSON sheets

##### Essential details to capture
- The Astro build step and where config files apply
- The two .astro routes (index vs. game)
- The single‐page game logic entry point (`game.ts`)
- All asset types and how they’re fetched
- The purely client‐side execution context

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Developer Workstation
    subgraph "Developer Workstation"
        REPO["Git Repository"]:::dev
        DEV_TOOLS["Node.js + Astro + TypeScript Compiler"]:::dev
        CONFIG1["astro.config.mjs"]:::dev
        CONFIG2["tsconfig.json"]:::dev
        CONFIG3["package.json"]:::dev
    end

    %% CI/CD & Build
    CICD["CI/CD Pipeline"]:::build
    ASTRO_BUILD["Astro Build Process"]:::build

    %% Deployment
    DEPLOY["Deploy to Static Hosting"]:::hosting
    CDN["Static Hosting / CDN (Netlify, Vercel, S3+CF)"]:::hosting

    %% Client Runtime
    subgraph "Client (Browser)"
        INDEX["Landing Page (index.astro)"]:::client
        GAME_PAGE["Game Page (game.astro)"]:::client
        GAME_SCRIPT["Core Game Logic (game.ts)"]:::client
        BACKUP_SCRIPT["Backup Logic (game_备份.ts)"]:::client
        TEST_SCRIPT["Test Script (test.ts)"]:::client

        subgraph "Asset Store"
            AUDIO["Audio Assets (/public/audio/)"]:::assets
            IMAGES["Image Assets (/public/images/)"]:::assets
            SHEETS["Note‐Sheet JSON (/public/sheets/)"]:::assets
        end
    end

    %% Flows
    REPO -->|"push code"| CICD
    DEV_TOOLS -->|uses configs| ASTRO_BUILD
    CONFIG1 -->|configs| ASTRO_BUILD
    CONFIG2 -->|configs| ASTRO_BUILD
    CONFIG3 -->|scripts| ASTRO_BUILD
    CICD -->|triggers| ASTRO_BUILD
    ASTRO_BUILD -->|output static files| DEPLOY
    DEPLOY -->|publish| CDN

    %% Client requests
    CDN -->|HTTP GET /index| INDEX
    CDN -->|HTTP GET /game| GAME_PAGE
    GAME_PAGE -->|loads script| GAME_SCRIPT
    GAME_SCRIPT -->|fetches| AUDIO
    GAME_SCRIPT -->|fetches| IMAGES
    GAME_SCRIPT -->|fetches| SHEETS
    GAME_PAGE -->|may load| BACKUP_SCRIPT
    GAME_PAGE -->|may load| TEST_SCRIPT

    %% Classes
    classDef dev fill:#f9f,stroke:#333,stroke-width:1px
    classDef build fill:#ff9,stroke:#333,stroke-width:1px
    classDef hosting fill:#9ff,stroke:#333,stroke-width:1px
    classDef client fill:#9f9,stroke:#333,stroke-width:1px
    classDef assets fill:#fcf,stroke:#333,stroke-width:1px

    %% Click Events
    click INDEX "https://github.com/starrydriver/musicplay/blob/master/src/pages/index.astro"
    click GAME_PAGE "https://github.com/starrydriver/musicplay/blob/master/src/pages/game.astro"
    click GAME_SCRIPT "https://github.com/starrydriver/musicplay/blob/master/src/scripts/game.ts"
    click BACKUP_SCRIPT "https://github.com/starrydriver/musicplay/blob/master/src/scripts/game_备份.ts"
    click TEST_SCRIPT "https://github.com/starrydriver/musicplay/blob/master/src/scripts/test.ts"
    click AUDIO "https://github.com/starrydriver/musicplay/tree/master/public/audio/"
    click IMAGES "https://github.com/starrydriver/musicplay/tree/master/public/images/"
    click SHEETS "https://github.com/starrydriver/musicplay/tree/master/public/sheets/"
    click CONFIG1 "https://github.com/starrydriver/musicplay/blob/master/astro.config.mjs"
    click CONFIG2 "https://github.com/starrydriver/musicplay/blob/master/tsconfig.json"
    click CONFIG3 "https://github.com/starrydriver/musicplay/blob/master/package.json"
```
