# nwuww/phi-plugin architecture

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

- Interactive diagram: https://gitdiagram.com/nwuww/phi-plugin
- Repository: https://github.com/nwuww/phi-plugin

## Overview

phi-plugin is a Phigros information bot plugin for Yunzai and Koishi. Users issue chat commands for account binding, score and player queries, song/chart lookup, history, rankings, and games; handlers use game metadata and saved records, optionally call the online API, then send textual or rendered results. The README documents these capability branches, while sampled source confirms shared configuration, platform handling, game calculations, API, save, and rendering layers. Some command-handler wiring and several feature implementations were not sampled, so those relationships are shown only where documented or indexed.

Main entry points: [`model/save/Save.js`](https://github.com/nwuww/phi-plugin/blob/main/model/save/Save.js) (Player Records), [`model/game/getInfo.js`](https://github.com/nwuww/phi-plugin/blob/main/model/game/getInfo.js) (Song Metadata), [`model/render/picmodle.js`](https://github.com/nwuww/phi-plugin/blob/main/model/render/picmodle.js) (Image Rendering), [`model/game/fCompute.js`](https://github.com/nwuww/phi-plugin/blob/main/model/game/fCompute.js) (Score Calculations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Chat and Platform"]
  node_plugin["Plugin Entry<br/>[index.js]"]
  node_platform["Platform Adapter<br/>[index.js]"]
  node_base["Message Base<br/>[baseClass.js]"]
end

subgraph group_features["Player Features"]
  node_session["Account and Session<br/>[session.js]"]
  node_queries["Score Queries<br/>[b19.js]"]
  node_games["Guess Games<br/>[guessGame.js]"]
  node_alias["Alias Proposals<br/>[aliasProposal.js]"]
  node_chart["Chart Queries<br/>[chart.js]"]
  node_ranking["Rank Lists<br/>[RankList.js]"]
end

subgraph group_domain["Game Domain"]
  node_gameinfo[("Song Metadata<br/>[getInfo.js]")]
  node_compute["Score Calculations<br/>[fCompute.js]"]
  node_records[("Player Records<br/>[Save.js]")]
end

subgraph group_services["Shared Services"]
  node_config["Configuration<br/>[Config.js]"]
  node_storage["Filesystem Paths<br/>[path.js]"]
  node_api["Phi API Client<br/>[makeRequest.js]"]
  node_permission["API Permissions<br/>[apiPermission.js]"]
end

subgraph group_presentation["Results and Themes"]
  node_render["Image Rendering<br/>[picmodle.js]"]
  node_send["Message Delivery<br/>[send.js]"]
  node_themes["Theme Management<br/>[manager.js]"]
end

node_user(("Chat User"))

node_user -->|"issues commands"| node_plugin
node_plugin -->|"loads adapter"| node_platform
node_plugin -.->|"loads handlers"| node_base
node_session -->|"updates records"| node_records
node_session -->|"requests account data"| node_api
node_queries -.->|"queries scores"| node_records
node_queries -.->|"requests online data"| node_api
node_games -->|"looks up songs"| node_gameinfo
node_games -->|"compares scores"| node_compute
node_alias -->|"checks song aliases"| node_gameinfo
node_chart -.->|"queries charts"| node_gameinfo
node_ranking -.->|"requests rankings"| node_api
node_records -->|"calculates ratings"| node_compute
node_records -->|"requests statistics"| node_api
node_records -->|"checks access"| node_permission
node_gameinfo -->|"reads game files"| node_storage
node_compute -->|"uses song metadata"| node_gameinfo
node_config -->|"resolves plugin paths"| node_storage
node_base -->|"sends replies"| node_send
node_base -->|"resolves song names"| node_gameinfo
node_send -->|"reads saved data"| node_records
node_render -->|"uses calculations"| node_compute
node_render -->|"resolves themes"| node_themes
node_queries -.->|"renders results"| node_render
node_render -.->|"produces images"| node_send

click node_plugin "https://github.com/nwuww/phi-plugin/blob/main/index.js"
click node_platform "https://github.com/nwuww/phi-plugin/blob/main/components/platform/index.js"
click node_base "https://github.com/nwuww/phi-plugin/blob/main/components/baseClass.js"
click node_session "https://github.com/nwuww/phi-plugin/blob/main/apps/session.js"
click node_queries "https://github.com/nwuww/phi-plugin/blob/main/apps/b19.js"
click node_games "https://github.com/nwuww/phi-plugin/blob/main/apps/guessGame.js"
click node_alias "https://github.com/nwuww/phi-plugin/blob/main/apps/aliasProposal.js"
click node_chart "https://github.com/nwuww/phi-plugin/blob/main/apps/chart.js"
click node_ranking "https://github.com/nwuww/phi-plugin/blob/main/apps/RankList.js"
click node_gameinfo "https://github.com/nwuww/phi-plugin/blob/main/model/game/getInfo.js"
click node_compute "https://github.com/nwuww/phi-plugin/blob/main/model/game/fCompute.js"
click node_records "https://github.com/nwuww/phi-plugin/blob/main/model/save/Save.js"
click node_config "https://github.com/nwuww/phi-plugin/blob/main/components/Config.js"
click node_storage "https://github.com/nwuww/phi-plugin/blob/main/model/filesystem/path.js"
click node_api "https://github.com/nwuww/phi-plugin/blob/main/model/api/makeRequest.js"
click node_permission "https://github.com/nwuww/phi-plugin/blob/main/model/user/apiPermission.js"
click node_render "https://github.com/nwuww/phi-plugin/blob/main/model/render/picmodle.js"
click node_send "https://github.com/nwuww/phi-plugin/blob/main/model/render/send.js"
click node_themes "https://github.com/nwuww/phi-plugin/blob/main/model/theme/manager.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_plugin,node_platform,node_base,node_user toneBlue
class node_session,node_queries,node_games,node_alias,node_chart,node_ranking toneAmber
class node_gameinfo,node_compute,node_records toneMint
class node_config,node_storage,node_api,node_permission toneRose
class node_render,node_send,node_themes toneIndigo
```

## Components

### Chat and Platform

- [Plugin Entry](https://github.com/nwuww/phi-plugin/blob/main/index.js): `index.js`
- [Platform Adapter](https://github.com/nwuww/phi-plugin/blob/main/components/platform/index.js): `components/platform/index.js`
- [Message Base](https://github.com/nwuww/phi-plugin/blob/main/components/baseClass.js): `components/baseClass.js`

### Player Features

- [Account and Session](https://github.com/nwuww/phi-plugin/blob/main/apps/session.js): `apps/session.js`
- [Score Queries](https://github.com/nwuww/phi-plugin/blob/main/apps/b19.js): `apps/b19.js`
- [Guess Games](https://github.com/nwuww/phi-plugin/blob/main/apps/guessGame.js): `apps/guessGame.js`
- [Alias Proposals](https://github.com/nwuww/phi-plugin/blob/main/apps/aliasProposal.js): `apps/aliasProposal.js`
- [Chart Queries](https://github.com/nwuww/phi-plugin/blob/main/apps/chart.js): `apps/chart.js`
- [Rank Lists](https://github.com/nwuww/phi-plugin/blob/main/apps/RankList.js): `apps/RankList.js`

### Game Domain

- [Song Metadata](https://github.com/nwuww/phi-plugin/blob/main/model/game/getInfo.js): `model/game/getInfo.js`
- [Score Calculations](https://github.com/nwuww/phi-plugin/blob/main/model/game/fCompute.js): `model/game/fCompute.js`
- [Player Records](https://github.com/nwuww/phi-plugin/blob/main/model/save/Save.js): `model/save/Save.js`

### Shared Services

- [Configuration](https://github.com/nwuww/phi-plugin/blob/main/components/Config.js): `components/Config.js`
- [Filesystem Paths](https://github.com/nwuww/phi-plugin/blob/main/model/filesystem/path.js): `model/filesystem/path.js`
- [Phi API Client](https://github.com/nwuww/phi-plugin/blob/main/model/api/makeRequest.js): `model/api/makeRequest.js`
- [API Permissions](https://github.com/nwuww/phi-plugin/blob/main/model/user/apiPermission.js): `model/user/apiPermission.js`

### Results and Themes

- [Image Rendering](https://github.com/nwuww/phi-plugin/blob/main/model/render/picmodle.js): `model/render/picmodle.js`
- [Message Delivery](https://github.com/nwuww/phi-plugin/blob/main/model/render/send.js): `model/render/send.js`
- [Theme Management](https://github.com/nwuww/phi-plugin/blob/main/model/theme/manager.js): `model/theme/manager.js`

### Other components

- **Chat User**

## Connections

- Chat User → Plugin Entry: issues commands
- Plugin Entry → Platform Adapter: loads adapter (evidence: `components/platform/index.js`)
- Plugin Entry → Message Base: loads handlers
- Account and Session → Player Records: updates records (evidence: `apps/session.js`)
- Account and Session → Phi API Client: requests account data (evidence: `apps/session.js`)
- Score Queries → Player Records: queries scores
- Score Queries → Phi API Client: requests online data
- Guess Games → Song Metadata: looks up songs (evidence: `apps/guessGame/guessIll.js`)
- Guess Games → Score Calculations: compares scores (evidence: `apps/guessGame/guessIll.js`)
- Alias Proposals → Song Metadata: checks song aliases
- Chart Queries → Song Metadata: queries charts
- Rank Lists → Phi API Client: requests rankings
- Player Records → Score Calculations: calculates ratings (evidence: `model/save/Save.js`)
- Player Records → Phi API Client: requests statistics (evidence: `model/save/Save.js`)
- Player Records → API Permissions: checks access (evidence: `model/save/Save.js`)
- Song Metadata → Filesystem Paths: reads game files (evidence: `model/game/getInfo.js`)
- Score Calculations → Song Metadata: uses song metadata (evidence: `model/game/fCompute.js`)
- Configuration → Filesystem Paths: resolves plugin paths (evidence: `components/Config.js`)
- Message Base → Message Delivery: sends replies (evidence: `components/baseClass.js`)
- Message Base → Song Metadata: resolves song names (evidence: `components/baseClass.js`)
- Message Delivery → Player Records: reads saved data (evidence: `model/render/send.js`)
- Image Rendering → Score Calculations: uses calculations (evidence: `model/render/picmodle.js`)
- Image Rendering → Theme Management: resolves themes (evidence: `model/render/picmodle.js`)
- Score Queries → Image Rendering: renders results
- Image Rendering → Message Delivery: produces images
