メインコンテンツへ

テンプレート

一言でいうと

Template は「テーブル・ドキュメント・画面・自動化ルールをひとまとめにして一括投入できる雛形」です。3種類の TemplateType があり、単純な「既存テーブルへレコードを流し込む」ものから、複数リソースを組み合わせた複合セット、さらにテンプレート同士を組み合わせるものまで段階があります。業種(法律事務所/visa/it-ops)別のスターターコンテンツとして、テナント作成時に自動投入される用途が中心です。

主要ドメイン概念

概念役割
Templateテンプレート本体。type: TemplateType + content: TemplateContent(polymorphic JSONB)
TemplateTypeRECORD_SET(既存テーブルへのレコード一括作成、階層対応) / RESOURCE_SET(テーブル・フィルタプリセット・ドキュメント構造・ファイル・画面・automationの複合) / WORKSPACE(複数テンプレートの組み合わせ適用、Phase 2)
TemplateContentsealed 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-workspace
  • api/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/: RecordSetContentrecords: List<RecordDefinition> + 親子関係の parentField)、ResourceSetContenttables/filterPresets/documents/files/tableScreens/automations)、WorkspaceContenttemplates: List<TemplateReference> + applyOrder
  • infrastructure/seeder/StarterContentSeeder.kt: テナント作成時、業種プラグインごとの RESOURCE_SET を可視ワークスペースへ投入する。フォルダ存在ベースの冪等性(同名フォルダが既にあればスキップ)
  • infrastructure/listener/StarterContentBootstrapListener.kt / StarterContentBackfillListener.kt: テナント作成イベント契機の投入、既存テナントへの後追い投入

Frontend 構造

app/modules/template/ は4分類に加えて save-as/ サブディレクトリを持ちます。

  • composables/: useTemplates(一覧)、useTemplateDetailuseTemplateFormuseTemplateApply / useResourceSetApply / useWorkspaceApply(3種の適用フロー)、useVariableResolveruseConditionalVisibility(変数の表示条件)、useSaveAsTemplate(既存リソースをテンプレート化)
  • components/: TemplateBrowserDialog.vue(一覧・選択)、TemplateApplyDialog.vue / TemplateVariableInputPanel.vue(適用時の変数入力)、TemplateImpactSummary.vue(適用結果プレビュー)、OrganizeSchemaEditor.vueorganize の護ひな型スキーマ編集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 です — 現在の TemplateTypeRECORD_SET / RESOURCE_SET / WORKSPACE の3種のみ。