# gaigai315/yuzuki-phone architecture

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

- Interactive diagram: https://gitdiagram.com/gaigai315/yuzuki-phone
- Repository: https://github.com/gaigai315/yuzuki-phone

## Overview

#### Purpose and host integration
This is a browser-side SillyTavern extension that renders an immersive virtual phone and app ecosystem for roleplay. The extension entry is `index.js`; metadata and installation identity are in `manifest.json`. It is loaded under SillyTavern’s third-party extension runtime, not as a standalone web service.

#### Phone shell and navigation
The phone UI is a persistent shell with home-screen launching, floating entry access, and layered in-phone navigation. `phone/phone-shell.js`, `phone/home-screen.js`, and `phone/floating-entry.js` form the primary UI control boundary; `phone.css` supplies shell-wide styling. The architecture favors retained view layers and gesture-driven back navigation rather than page reloads.

#### Shared state, time, and persistence
Cross-app state and host-facing persistence are centralized in configuration managers. `config/storage.js` persists phone/app data; `config/time-manager.js` derives phone time from story context; `config/global-social-store.js` coordinates shared social entities/activity. `config/context-settings.js` and `config/worldbook-manager.js` bridge phone behavior with SillyTavern character/chat context and lore data.

#### AI and generation boundary
AI calls are mediated rather than embedded directly in individual apps. `config/api-manager.js` supports independent model/API communication, while `config/prompt-manager.js` owns prompt construction and `config/tag-filter.js` constrains generated content. This separates “online” phone-only AI interactions from story-context injection and keeps provider-specific logic outside application views.

#### App composition pattern
Most apps follow an explicit three-part structure: app orchestration, state/data operations, and DOM rendering, e.g. `apps/wechat/wechat-app.js`, `apps/wechat/wechat-data.js`, and `apps/wechat/chat-view.js`; similarly `apps/diary/diary-app.js` and `apps/diary/diary-view.js`. `config/apps.js` is the app registry/launch integration point. This makes each app a feature module mounted into the common phone shell.

#### Social and communication subsystems
WeChat is the deepest social subsystem: chat, contacts, Moments, themes, snapshots, voice-to-text, and style presets are split across `apps/wechat/wechat-app.js`, `apps/wechat/chat-view.js`, and `apps/wechat/moments-view.js`. Phone calling/SMS is isolated in `apps/phone/phone-app.js`, `apps/phone/sms-popup.js`, and `apps/phone/phone-data.js`. Weibo, Honey, Diary, Music, Album, Calendar, and Wangxiang reuse the same app/data/view boundary for generated or user-managed social content.

#### Media, TTS, and image infrastructure
Image ingestion is handled through crop/upload components in `apps/settings/image-cropper.js` and `apps/settings/image-upload.js`; the intended storage model is server-hosted paths rather than Base64 blobs. `config/image-generation-manager.js` and `config/tts-manager.js` abstract media generation/playback. Optional relay and queue infrastructure lives in `workers/doubao-clone-worker.js`, `workers/mimo-tts-relay-worker.js`, and `workers/nai-queue-worker.js`, enabling external image/TTS providers where configured.

#### Games and specialized experiences
`apps/games/games-app.js` is a games hub with independently scoped game modules such as `apps/games/poker/poker-app.js`, `apps/games/sudoku/sudoku-data.js`, and `apps/games/werewolf/werewolf-view.js`. Shared AI/game context is centralized in `apps/games/common/games-ai-context.js`, preserving a boundary between common roleplay-aware generation and each game’s rules/UI.

Main entry points: [`config/apps.js`](https://github.com/gaigai315/yuzuki-phone/blob/main/config/apps.js) (App Registry), [`apps/wechat/wechat-app.js`](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/wechat/wechat-app.js) (WeChat), [`config/storage.js`](https://github.com/gaigai315/yuzuki-phone/blob/main/config/storage.js) (Phone Storage), [`config/api-manager.js`](https://github.com/gaigai315/yuzuki-phone/blob/main/config/api-manager.js) (AI Generation Boundary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host Integration"]
  node_entry["Extension Entry<br/>extension bootstrap<br/>[index.js]"]
  node_context["Story &amp; Lore Bridge<br/>host context"]
end

subgraph group_core["Phone Platform"]
  node_shell["Phone Shell<br/>persistent UI shell<br/>[phone-shell.js]"]
  node_home["Home &amp; Floating Entry<br/>phone navigation UI<br/>[home-screen.js]"]
  node_registry["App Registry<br/>app launcher<br/>[apps.js]"]
  node_storage[("Phone Storage<br/>persistence manager<br/>[storage.js]")]
  node_time["Story Time<br/>time manager<br/>[time-manager.js]"]
  node_social[("Global Social Store<br/>shared social state")]
  node_ai{{"AI Generation Boundary<br/>API and prompt pipeline<br/>[api-manager.js]"}}
end

subgraph group_apps["App Ecosystem"]
  node_wechat["WeChat<br/>social app orchestration<br/>[wechat-app.js]"]
  node_wechat_views["WeChat Chat &amp; Moments<br/>social views<br/>[chat-view.js]"]
  node_phone_app["Calls &amp; SMS<br/>communication app<br/>[phone-app.js]"]
  node_diary["Diary<br/>feature app<br/>[diary-app.js]"]
  node_other_apps["Other Social Apps<br/>feature modules"]
end

subgraph group_media["Media Services"]
  node_image_io["Image Ingestion<br/>crop and upload<br/>[image-upload.js]"]
  node_media{{"Image &amp; TTS Managers<br/>media abstraction"}}
  node_workers["Optional Provider Workers<br/>relay and queue workers"]
end

subgraph group_games["Games"]
  node_games_hub["Games Hub<br/>game launcher<br/>[games-app.js]"]
  node_game_context["Games AI Context<br/>shared game context"]
  node_game_modules["Scoped Game Modules<br/>game rules and views<br/>[poker-app.js]"]
end

node_entry -->|"boots"| node_shell
node_entry -->|"uses host context"| node_context
node_shell -->|"hosts"| node_home
node_home -->|"launches apps"| node_registry
node_registry -->|"mounts"| node_wechat
node_registry -->|"mounts"| node_phone_app
node_registry -->|"mounts"| node_diary
node_registry -->|"mounts"| node_other_apps
node_registry -->|"mounts"| node_games_hub
node_context -->|"supplies story context"| node_time
node_context -->|"enriches prompts"| node_ai
node_wechat -->|"orchestrates"| node_wechat_views
node_wechat -->|"shares activity"| node_social
node_wechat -->|"persists data"| node_storage
node_phone_app -->|"persists calls and SMS"| node_storage
node_diary -->|"persists entries"| node_storage
node_other_apps -->|"persist content"| node_storage
node_wechat -->|"requests generation"| node_ai
node_other_apps -->|"requests generation"| node_ai
node_image_io -->|"stores image paths"| node_storage
node_media -.->|"optionally relays"| node_workers
node_games_hub -->|"launches"| node_game_modules
node_game_modules -->|"uses shared context"| node_game_context
node_game_context -->|"requests roleplay-aware generation"| node_ai

click node_entry "https://github.com/gaigai315/yuzuki-phone/blob/main/index.js"
click node_context "https://github.com/gaigai315/yuzuki-phone/blob/main/config/context-settings.js"
click node_shell "https://github.com/gaigai315/yuzuki-phone/blob/main/phone/phone-shell.js"
click node_home "https://github.com/gaigai315/yuzuki-phone/blob/main/phone/home-screen.js"
click node_registry "https://github.com/gaigai315/yuzuki-phone/blob/main/config/apps.js"
click node_storage "https://github.com/gaigai315/yuzuki-phone/blob/main/config/storage.js"
click node_time "https://github.com/gaigai315/yuzuki-phone/blob/main/config/time-manager.js"
click node_social "https://github.com/gaigai315/yuzuki-phone/blob/main/config/global-social-store.js"
click node_ai "https://github.com/gaigai315/yuzuki-phone/blob/main/config/api-manager.js"
click node_wechat "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/wechat/wechat-app.js"
click node_wechat_views "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/wechat/chat-view.js"
click node_phone_app "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/phone/phone-app.js"
click node_diary "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/diary/diary-app.js"
click node_image_io "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/settings/image-upload.js"
click node_media "https://github.com/gaigai315/yuzuki-phone/blob/main/config/image-generation-manager.js"
click node_workers "https://github.com/gaigai315/yuzuki-phone/blob/main/workers/doubao-clone-worker.js"
click node_games_hub "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/games/games-app.js"
click node_game_context "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/games/common/games-ai-context.js"
click node_game_modules "https://github.com/gaigai315/yuzuki-phone/blob/main/apps/games/poker/poker-app.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_entry,node_context toneBlue
class node_shell,node_home,node_registry,node_storage,node_time,node_social,node_ai toneAmber
class node_wechat,node_wechat_views,node_phone_app,node_diary,node_other_apps toneMint
class node_image_io,node_media,node_workers toneRose
class node_games_hub,node_game_context,node_game_modules toneIndigo
```

## Components

### Host Integration

- [Extension Entry](https://github.com/gaigai315/yuzuki-phone/blob/main/index.js): extension bootstrap · Loads in SillyTavern's third-party extension runtime. · `index.js`
- [Story & Lore Bridge](https://github.com/gaigai315/yuzuki-phone/blob/main/config/context-settings.js): host context · `config/context-settings.js`

### Phone Platform

- [Phone Shell](https://github.com/gaigai315/yuzuki-phone/blob/main/phone/phone-shell.js): persistent UI shell · Retains phone layers and gesture-driven navigation. · `phone/phone-shell.js`
- [Home & Floating Entry](https://github.com/gaigai315/yuzuki-phone/blob/main/phone/home-screen.js): phone navigation UI · `phone/home-screen.js`
- [App Registry](https://github.com/gaigai315/yuzuki-phone/blob/main/config/apps.js): app launcher · `config/apps.js`
- [Phone Storage](https://github.com/gaigai315/yuzuki-phone/blob/main/config/storage.js): persistence manager · Persists phone and app data. · `config/storage.js`
- [Story Time](https://github.com/gaigai315/yuzuki-phone/blob/main/config/time-manager.js): time manager · Derives phone time from story context. · `config/time-manager.js`
- [Global Social Store](https://github.com/gaigai315/yuzuki-phone/blob/main/config/global-social-store.js): shared social state · `config/global-social-store.js`
- [AI Generation Boundary](https://github.com/gaigai315/yuzuki-phone/blob/main/config/api-manager.js): API and prompt pipeline · Mediates provider calls, prompts, and generated-content constraints. · `config/api-manager.js`

### App Ecosystem

- [WeChat](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/wechat/wechat-app.js): social app orchestration · Deep social subsystem for chat, contacts, Moments, and related features. · `apps/wechat/wechat-app.js`
- [WeChat Chat & Moments](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/wechat/chat-view.js): social views · `apps/wechat/chat-view.js`
- [Calls & SMS](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/phone/phone-app.js): communication app · `apps/phone/phone-app.js`
- [Diary](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/diary/diary-app.js): feature app · `apps/diary/diary-app.js`
- **Other Social Apps**: feature modules · Weibo, Honey, Music, Album, Calendar, and Wangxiang follow the shared app pattern.

### Media Services

- [Image Ingestion](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/settings/image-upload.js): crop and upload · Stores server-hosted image paths rather than Base64 blobs. · `apps/settings/image-upload.js`
- [Image & TTS Managers](https://github.com/gaigai315/yuzuki-phone/blob/main/config/image-generation-manager.js): media abstraction · `config/image-generation-manager.js`
- [Optional Provider Workers](https://github.com/gaigai315/yuzuki-phone/blob/main/workers/doubao-clone-worker.js): relay and queue workers · Relays external image and TTS providers when configured. · `workers/doubao-clone-worker.js`

### Games

- [Games Hub](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/games/games-app.js): game launcher · `apps/games/games-app.js`
- [Games AI Context](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/games/common/games-ai-context.js): shared game context · Separates roleplay-aware generation from game rules and UI. · `apps/games/common/games-ai-context.js`
- [Scoped Game Modules](https://github.com/gaigai315/yuzuki-phone/blob/main/apps/games/poker/poker-app.js): game rules and views · Poker, Sudoku, and Werewolf remain independently scoped. · `apps/games/poker/poker-app.js`

## Connections

- Extension Entry → Phone Shell: boots
- Extension Entry → Story & Lore Bridge: uses host context
- Phone Shell → Home & Floating Entry: hosts
- Home & Floating Entry → App Registry: launches apps
- App Registry → WeChat: mounts
- App Registry → Calls & SMS: mounts
- App Registry → Diary: mounts
- App Registry → Other Social Apps: mounts
- App Registry → Games Hub: mounts
- Story & Lore Bridge → Story Time: supplies story context
- Story & Lore Bridge → AI Generation Boundary: enriches prompts
- WeChat → WeChat Chat & Moments: orchestrates
- WeChat → Global Social Store: shares activity
- WeChat → Phone Storage: persists data
- Calls & SMS → Phone Storage: persists calls and SMS
- Diary → Phone Storage: persists entries
- Other Social Apps → Phone Storage: persist content
- WeChat → AI Generation Boundary: requests generation
- Other Social Apps → AI Generation Boundary: requests generation
- Image Ingestion → Phone Storage: stores image paths
- Image & TTS Managers → Optional Provider Workers: optionally relays
- Games Hub → Scoped Game Modules: launches
- Scoped Game Modules → Games AI Context: uses shared context
- Games AI Context → AI Generation Boundary: requests roleplay-aware generation
