← ソースコード説明書

モノレポ全体構造

概要

kaedevn-monorepo は、Nintendo Switch(主)と Web(副)を対象としたクロスプラットフォームのノベルゲームと RPG ゲームが両方作れるプラットフォームのモノレポ。ノベル側は VRM / Live2D キャラ対応で稼働中、RPG 側(Database・マップ・イベント・コマンドバトル)は開発中。エディタ、API、プレビュー、コンパイラ、インタプリタ、ネイティブエンジンなど 16 以上のパッケージで構成される。

技術スタック

レイヤー技術
フロントエンドReact 19, Vite 7, Tailwind CSS, Zustand 5
バックエンドHono 4, Prisma 5, PostgreSQL
レンダリングPixiJS (Web), SDL2/OpenGL (Native)
スクリプト.ks (TyranoScript風), .ksc (TypeScript風)
AIOpenAI, Anthropic, Google Vertex AI
インフラAzure Container Apps, Static Web Apps, Blob Storage
CI/CDGitHub Actions (deploy.yml, deploy-swa.yml, ci.yml)
テストVitest (unit), Playwright (E2E)

ディレクトリ構成

kaedevn-monorepo/
├── apps/
│   ├── editor/          # メインエディタ SPA (Vite + React, :5176)
│   ├── hono/            # バックエンド API (Hono, :8080)
│   ├── next/            # 認証・管理画面 (Next.js, :3000)
│   └── ksc-editor/      # KSC スクリプトエディタ (Vite + React + Monaco, :5177)
├── packages/
│   ├── core/            # 共有型定義・Op 型・Timeline 型
│   ├── compiler/        # .ks → Op[] コンパイラ
│   ├── ksc-compiler/    # .ksc コンパイラ + VM
│   ├── web/             # PixiJS WebGL エンジン・プレビュー (:5175)
│   ├── interpreter/     # スクリプトインタプリタ
│   ├── ai-gateway/      # LLM クライアント抽象化
│   ├── battle/          # コマンドバトルシステム
│   ├── ui/              # 共有 React UI コンポーネント
│   ├── tools/           # アセット処理 CLI ツール
│   ├── native-engine/   # C++ ネイティブエンジン (Switch/Android)
│   ├── sdl/             # SDL2 ライブラリ
│   └── vscode-ks-ksc/   # VSCode 拡張(.ks/.ksc 構文ハイライト)
├── tests/               # Playwright E2E テスト (48 ファイル)
├── e2e/                 # KSC デモ E2E テスト
├── scripts/             # 開発・テスト・デプロイスクリプト (39 ファイル)
├── projects/            # コンテンツデータ(対象外)
├── docs/                # ドキュメント
├── .github/workflows/   # CI/CD (7 ワークフロー)
├── .husky/              # Git hooks (pre-push, pre-commit)
└── package.json         # ワークスペース定義

パッケージ依存関係

core ← compiler ← web
core ← ksc-compiler ← web
core ← interpreter
core ← battle ← web
ai-gateway ← hono (API)

apps/editor → core (型のみ)
apps/hono → core, ai-gateway
apps/next → (独立)
apps/ksc-editor → (独立)

packages/web → core, compiler, ksc-compiler, battle

依存方向の原則

  • core は他パッケージに依存しない(基盤層)
  • compiler, ksc-compiler, interpreter, battlecore のみに依存
  • web はすべてのランタイムパッケージに依存(統合層)
  • ai-gateway は独立(外部 LLM API のみ)
  • アプリ層(apps/)はパッケージ層に依存するが、パッケージ層はアプリ層に依存しない

サーバー構成

サーバーポートディレクトリ役割
Hono API8080apps/honoREST API、認証、DB
Next.js3000apps/next認証画面、管理画面、マイページ
Editor5176apps/editorノベルエディタ SPA(VRM / Live2D / Shape Ch 対応)
KSC Editor5177apps/ksc-editorKSC スクリプトエディタ
Preview5175packages/webPixiJS プレビューエンジン

データフロー

[Editor SPA]  →  PUT /api/projects/:id  →  [Hono API]  →  [PostgreSQL]
     ↓                                          ↓
[buildPreviewScript()]              GET /api/preview/:id
     ↓                                          ↓
[Preview Engine]  ←  KSC Script  ←  [generateKSCScript()]
     ↓
[PixiJS / WebGL Rendering]

スクリプト処理パイプライン

エディタブロック → .ks スクリプト → Compiler → Op[] → OpRunner → WebOpHandler → PixiJS
                    or
エディタブロック → .ksc スクリプト → KSC Compiler → IR → VM → HostAPI → WebOpHandler → PixiJS

コア抽象化インターフェース

Switch 移植を見据え、以下のインターフェースを通じてプラットフォーム差異を吸収する。

インターフェース役割Web 実装
IInput入力アクション dispatchPixiJS pointer/keyboard
IAudioBGM/SE/VOICE 再生Web Audio API
IStorageセーブ/ロードIndexedDB
IOpHandlerOp 命令実行WebOpHandler (PixiJS)

デプロイ構成

コンポーネントAzure サービスデプロイ方法
API (Hono)Container AppsGitHub Actions → ACR → Container Apps
Next.jsContainer AppsGitHub Actions → ACR → Container Apps
EditorStatic Web AppsGitHub Actions → SWA deploy
PreviewStatic Web AppsGitHub Actions → SWA deploy
DBPostgreSQL Flexible Serverマネージド
AssetsBlob StorageAPI 経由アップロード

ファイル規模

カテゴリファイル数(概算)総行数(概算)
apps/editor10513,500
apps/hono136 (src: 74, test: 46)16,000
apps/next788,000
apps/ksc-editor20800
packages/web10912,000
packages/core373,000
packages/compiler364,000
packages/ksc-compiler243,000
packages/interpreter363,000
packages/ai-gateway181,000
packages/battle161,500
packages/native-engine752,000
tests/ (E2E)489,500
scripts/393,000
合計~780~80,000
Ad: stickyBottom (728x90)
kaedevn - ノベルゲームを作れるプラットフォーム