テンプレート
一言でいうと
Template は「テーブル・ドキュメント・画面・自動化ルールをひとまとめにして一括投入できる雛形」です。3種類の TemplateType があり、単純な「既存テーブルへレコードを流し込む」ものから、複数リソースを組み合わせた複合セット、さらにテンプレート同士を組み合わせるものまで段階があります。業種(法律事務所/visa/it-ops)別のスターターコンテンツとして、テナント作成時に自動投入される用途が中心です。
主要ドメイン概念
| 概念 | 役割 |
|---|---|
Template | テンプレート本体。type: TemplateType + content: TemplateContent(polymorphic JSONB) |
TemplateType | RECORD_SET(既存テーブルへのレコード一括作成、階層対応) / RESOURCE_SET(テーブル・フィルタプリセット・ドキュメント構造・ファイル・画面・automationの複合) / WORKSPACE(複数テンプレートの組み合わせ適用、Phase 2) |
TemplateContent | sealed interface。RecordSetContent / ResourceSetContent / WorkspaceContent が @SerialName discriminator で分岐 |
VariableDefinition | テンプレート適用時にユーザー入力で埋める変数(型・バリデーションルール・表示条件を持つ) |
StarterContentCatalog / StarterContentSeed | 業種プラグイン別のスターターコンテンツ定義。テナント作成時に tenant.hasPlugin(pluginId) を見て投入 |
Backend 構造
api/controller/TemplateController.kt: CRUD、複製(/duplicate)、適用系3エンドポイント —/{id}/apply(RECORD_SET)、/{id}/apply-resource-set、/{id}/apply-workspaceapi/controller/TemplateExportController.kt: 既存フォルダ/ワークスペースをテンプレート化するための export(/folder-tree/{folderId}、/workspace/{workspaceId})domain/service/TemplateService.kt: CRUD 本体domain/service/ResourceSetApplyService.kt/WorkspaceApplyService.kt: 適用フロー本体。ResourceSetApplyService.tryApplyResourceSetByKeyはスターターコンテンツ seeder からも再利用される単一の実体化経路domain/service/VariableResolver.kt:content内の変数プレースホルダをユーザー入力値で解決domain/model/content/:RecordSetContent(records: List<RecordDefinition>+ 親子関係のparentField)、ResourceSetContent(tables/filterPresets/documents/files/tableScreens/automations)、WorkspaceContent(templates: List<TemplateReference>+applyOrder)infrastructure/seeder/StarterContentSeeder.kt: テナント作成時、業種プラグインごとのRESOURCE_SETを可視ワークスペースへ投入する。フォルダ存在ベースの冪等性(同名フォルダが既にあればスキップ)infrastructure/listener/StarterContentBootstrapListener.kt/StarterContentBackfillListener.kt: テナント作成イベント契機の投入、既存テナントへの後追い投入
Frontend 構造
app/modules/template/ は4分類に加えて save-as/ サブディレクトリを持ちます。
composables/:useTemplates(一覧)、useTemplateDetail、useTemplateForm、useTemplateApply/useResourceSetApply/useWorkspaceApply(3種の適用フロー)、useVariableResolver、useConditionalVisibility(変数の表示条件)、useSaveAsTemplate(既存リソースをテンプレート化)components/:TemplateBrowserDialog.vue(一覧・選択)、TemplateApplyDialog.vue/TemplateVariableInputPanel.vue(適用時の変数入力)、TemplateImpactSummary.vue(適用結果プレビュー)、OrganizeSchemaEditor.vue(organizeの護ひな型スキーマ編集UI。テンプレートタイプではなく、テンプレート内で扱う JSONB スキーマの編集器として同居)
他モジュールとの辺
table:RECORD_SETの適用は最終的にRecordService.persistNewRecordsを通る(テーブルの単一レコード作成経路と同じ)editor:RESOURCE_SETのドキュメント構造・ファイルはドキュメントツリー上に実体化されるscreen:ResourceSetContent.tableScreensで、テーブル雛形と同時にダッシュボード画面も投入できるautomation:ResourceSetContent.automationsで自動化ルールも同時にプロビジョニングできる(AutomationPresetJsonDecoderでデコード)organize: 護(mamoru)ひな型(markdown ベース)は別軸のOrganizeSchemaSeederが担当し、templateの seeder とは別フォルダ・別カタログで競合しない(下記callout参照)
TemplateType は過去 ORGANIZE_SCHEMA を含む4種でしたが、2026-05 の Phase 4-A で削除されています。OrganizeSchema(護のMDB解析ひな型)は templates.content JSONB ベースの管理をやめ、document_node + markdown frontmatter ベースへ移行済みです(OrganizeSchemaMarkdownSerializer 参照)。「テンプレートは4種」という古い記述を見かけたら、それは stale です — 現在の TemplateType は RECORD_SET / RESOURCE_SET / WORKSPACE の3種のみ。