# chenxing3060/tcw architecture

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

- Interactive diagram: https://gitdiagram.com/chenxing3060/tcw
- Repository: https://github.com/chenxing3060/tcw

## Overview

##### 项目类型与目的
- 这是一个纯前端的视觉小说游戏（Single-Page Application），支持多平台部署：
- Web 浏览器 （静态站点，PWA）
- 移动端原生容器（通过 Capacitor 打包成 Android APK）
- 主要功能是按顺序加载并播放 JSON 剧情数据与视频资源，管理游戏状态与用户交互。

##### 文件结构要点分析
- 根目录：静态资源（index.html、game.html、css/、js/、data/、game/videos/、service-worker.js）
- js/：分模块的核心逻辑（GameController、ScenePlayer、UIManager、AssetLoader 等）
- data/ & game/videos/：游戏剧情 JSON 与视频文件
- service-worker.js：PWA 离线缓存与资源拦截
- capacitor.config*.json + android/：Capacitor 原生工程，用于安卓打包
- functions/：Serverless（示例 helloworld），可用于未来后台扩展
- vercel.json：Vercel 平台静态站点部署配置

##### README 额外洞察
- 强调“直接打开”与“本地服务器”两种运行方式
- 无传统后端，仅依赖本地/静态托管与可选 Serverless 函数
- 支持 PWA 与移动原生，包含 service-worker 离线逻辑和 Capacitor 桥接

##### 系统设计图的核心组件与关系

a. 客户端层（浏览/移动）
- Browser PWA
- index.html/game.html + CSS/JS 静态资源
- service-worker 负责离线缓存、拦截网络请求
- Capacitor Android
- WebView 容器 + 本地桥接（MainActivity.java）
- 使用 Capacitor 插件调用原生功能（文件访问、全屏、媒体解码等）

b. 静态托管层
- Vercel（或相似 CDN）托管所有静态文件：HTML、CSS、JS、JSON、视频
- HTTP(S) GET 请求由客户端发起，service-worker 先查缓存再回源

c. 剧情数据与媒体
- data/*.json：由 AssetLoader 请求并缓存（Memory 或 IndexedDB）
- game/videos/*：按需流式加载，service-worker 缓存策略可分文件大小调整

d. 可选 Serverless 扩展
- functions/helloworld：示例 Lambda/Cloud Function

##### 绘制系统设计图的要点
- 使用矩形/泳道划分：
- 客户端泳道：Browser PWA / Capacitor App
- 托管泳道：静态文件 CDN（Vercel）
- 后台泳道：Serverless Function（可选）
- 数据流箭头：
1. 客户端 → CDN：请求 HTML/CSS/JS/JSON/视频
2. CDN → 客户端：返回资源
3. 客户端 service-worker → 缓存 → 拦截/存取资源
4. Capacitor App → WebView → 调用原生插件
5. 客户端 → Serverless（可选）：数据上报、云存档
- 色彩与形状区分：
- 蓝色：静态资源（HTML/CSS/JS/JSON/视频）
- 绿色：客户端逻辑（模块化 JS、service-worker、WebView）
- 橙色：原生桥（Capacitor/Android）
- 灰色：后台服务（Serverless）

##### 重要架构模式与设计原则
- 单页面应用（SPA） + PWA：离线优先，缓存策略
- 分层模块化 JS：控制器、状态管理、资源加载、UI 渲染分离
- 混合移动（Hybrid App）：前端主导 + 原生容器
- 静态托管 + Serverless：零服务器运维

##### 针对本项目的绘图指南
- 左侧画出用户设备（Browser / Android App）。
- 中间画出 service-worker 层，突出其拦截与缓存职责。
- 右侧画出 CDN（Vercel）静态存储桶，下面可选挂载 Serverless 函数。
- 用箭头标明请求/响应，标注协议（HTTP GET/POST）、文件类型（.json/.mp4）。
- 在 Capacitor 容器中细分 WebView 与 Native Plugin 接口。
- 图例中注释各组件技术栈：
- JS 框架：无框架，原生模块化
- PWA 技术：service-worker, manifest.json
- 移动容器：Capacitor, Android Gradle
- 部署平台：Vercel CDN
- 后台样例：Serverless Function (Node.js)

##### 元素清单
- 组件标签：明确命名（Browser PWA、Service Worker、CDN、Capacitor App、Serverless）
- 数据流箭头：单向或双向，注明请求/响应方向
- 颜色/形状图例：静态 vs 动态 vs 原生 vs 后端
- 注释：缓存策略、周期性清理、离线优先策略

通过上述思路，您将能绘制出一张既简洁又细致、准确反映“万象行者”静态 PWA + 混合移动 + Serverless 架构的系统设计图。祝构图顺利！

## Diagram (Mermaid)

```mermaid
graph TB
    %% Client Layer
    subgraph "Client Layer"
        direction TB
        subgraph "Browser PWA" 
            direction TB
            B_Index["index.html"]:::static
            B_Game["game.html"]:::static
            B_Manifest["manifest.json"]:::static
            subgraph "Global Styles & UI CSS"
                direction TB
                CSS_UI["css/game-ui.css"]:::static
                CSS_Global["style.css"]:::static
            end
            subgraph "Core Client Logic (SPA Modules)"
                direction TB
                AL["AssetLoader.js"]:::client
                SDM["SceneDataManager.js"]:::client
                SP["ScenePlayer.js"]:::client
                GC["GameController.js"]:::client
                GSM["GameStateManager.js"]:::client
                UI["UIManager.js"]:::client
                MM["MusicManager.js"]:::client
                TM["TransitionManager.js"]:::client
                RM["RouteManager.js"]:::client
            end
            SW["Service Worker"]:::client
        end

        subgraph "Capacitor Android App"
            direction TB
            CA_WebView["WebView"]:::client
            NP["Native Plugin Bridge"]:::native
            C_Config["capacitor.config.json"]:::native
            C_ConfigDev["capacitor.config.dev.json"]:::native
            MA["MainActivity.java"]:::native
        end
    end

    %% Hosting & Backend
    subgraph "Hosting & Backend"
        direction TB
        subgraph "Static Hosting (Vercel/CDN)"
            direction TB
            CDN_HTML["HTML/CSS/JS"]:::static
            CDN_JSON[".json Data"]:::static
            CDN_Video["Video Resources (.mp4)"]:::static
            VercelConfig["vercel.json"]:::static
            VercelDir[".vercel/"]:::static
        end

        subgraph "Serverless Functions (Optional)"
            direction TB
            SL_Hello["helloworld/index.js"]:::backend
        end
    end

    %% Data Assets
    subgraph "Game Data & Media Assets"
        direction TB
        JSON_Data["data/*.json"]:::static
        Videos["game/videos/*"]:::static
    end

    %% Connections
    B_Index -->|loads| AL
    B_Game -->|loads| AL
    AL -->|fetch JSON| JSON_Data
    AL -->|fetch video| Videos
    B_Index -->|register| SW
    B_Game -->|register| SW
    SW -->|intercept/ cache| CDN_HTML
    SW -->|intercept/ cache| CDN_JSON
    SW -->|intercept/ cache| CDN_Video
    CA_WebView -->|loads SPA| AL
    CA_WebView -->|register| SW
    CA_WebView -->|calls| NP
    NP -->|bridge config| C_Config
    NP -->|bridge config| C_ConfigDev
    NP -->|invokes| MA
    B_Index -->|GET| CDN_HTML
    B_Game -->|GET| CDN_HTML
    AL -->|GET JSON| CDN_JSON
    AL -->|GET video| CDN_Video
    B_Index -->|POST| SL_Hello
    B_Game -->|POST| SL_Hello

    %% Click Events
    click B_Index "https://github.com/chenxing3060/tcw/blob/main/index.html"
    click B_Game "https://github.com/chenxing3060/tcw/blob/main/game.html"
    click B_Manifest "https://github.com/chenxing3060/tcw/blob/main/manifest.json"
    click CSS_UI "https://github.com/chenxing3060/tcw/blob/main/css/game-ui.css"
    click CSS_Global "https://github.com/chenxing3060/tcw/blob/main/style.css"
    click AL "https://github.com/chenxing3060/tcw/blob/main/js/AssetLoader.js"
    click SDM "https://github.com/chenxing3060/tcw/blob/main/js/SceneDataManager.js"
    click SP "https://github.com/chenxing3060/tcw/blob/main/js/ScenePlayer.js"
    click GC "https://github.com/chenxing3060/tcw/blob/main/js/GameController.js"
    click GSM "https://github.com/chenxing3060/tcw/blob/main/js/GameStateManager.js"
    click UI "https://github.com/chenxing3060/tcw/blob/main/js/UIManager.js"
    click MM "https://github.com/chenxing3060/tcw/blob/main/js/MusicManager.js"
    click TM "https://github.com/chenxing3060/tcw/blob/main/js/TransitionManager.js"
    click RM "https://github.com/chenxing3060/tcw/blob/main/js/RouteManager.js"
    click SW "https://github.com/chenxing3060/tcw/blob/main/service-worker.js"
    click JSON_Data "https://github.com/chenxing3060/tcw/blob/main/data/act1.json"
    click Videos "https://github.com/chenxing3060/tcw/tree/main/game/videos/bg/"
    click C_Config "https://github.com/chenxing3060/tcw/blob/main/capacitor.config.json"
    click C_ConfigDev "https://github.com/chenxing3060/tcw/blob/main/capacitor.config.dev.json"
    click MA "https://github.com/chenxing3060/tcw/blob/main/android/app/src/main/java/com/thecodexwalker/app/MainActivity.java"
    click VercelConfig "https://github.com/chenxing3060/tcw/blob/main/vercel.json"
    click VercelDir "https://github.com/chenxing3060/tcw/tree/main/.vercel/"
    click SL_Hello "https://github.com/chenxing3060/tcw/blob/main/functions/helloworld/index.js"

    %% Styles
    classDef static fill:#D0E7FF,stroke:#5B9BD5
    classDef client fill:#DFF7D8,stroke:#4FAF33
    classDef native fill:#FFE5B4,stroke:#E69A00
    classDef backend fill:#E0E0E0,stroke:#999999
```
