テンプレートの文脈
コードを生成するとき、Restorm は あなたの設計のすべて を ctx という
オブジェクトの形でテンプレートに渡します。あなたのモデル、enum、ルート、そして
何より その意図(searchable、PII、cache、そしてモデルの運用プロファイル
全体:volumetry、accessPattern、traffic、freshness、sensitivity、retention)が
そこにあります — テンプレートはそれらを読み取って何を生成するかを決めます。
そのために変数は不要です:あなたが設計にすでに入力した情報は直接利用できます。

ctx のかたち
Section titled “ctx のかたち”ctx├─ design # name, version, description, basePath, defaultAuth, vars├─ enums[] # name, description, values[]├─ models[] # name, description, inherits, identifier, timestamps, softDelete,│ # volumetry, accessPattern, traffic, freshness, sensitivity,│ # retention, properties[], allProperties[], examples[], vars└─ groups[] # name, basePath, versionPrefix, headers[], routes[] └─ routes[] # method, path, fullPath, params[], body, responses[], # auth, pagination, cacheSeconds, idempotent, deprecated, vars参照は名前で行われます(内部識別子では決してありません):property.enum
は enum の名前、property.references.model は対象モデルの名前、model.inherits
は親の名前です。モデルにおいて、properties[] はその 固有の プロパティを
列挙し(型の宣言のため)、allProperties[] は 固有 + 継承された、平坦化された
プロパティを列挙します(完全なインスタンスのため:例データ、SQL の列、リクエスト
ボディ)。
フラグを読む:黄金律
Section titled “フラグを読む:黄金律”真偽値フラグは、有効なときにのみ ctx に存在します。エンジンは
StrictUndefined でレンダリングします:したがって キーの存在をテスト する
必要があり、その値を決してテストしてはいけません。
{# ✅ correct — on teste la présence #}{% if 'searchable' in p %}INDEX({{ p['name'] }}){% endif %}
{# ❌ faux — lève une erreur quand le flag est absent #}{% if p.searchable %}…{% endif %}property.required(真偽値)と route.auth(列挙)だけが 常に 存在します。
ほかの真偽値フラグは「存在 = 真」です。値 を持つフィールド(volumetry、運用
プロファイル、cache…)は、入力されているときにその値を持ち、そうでなければ
存在しません — 同じ存在の規則です。
| プロパティ の場合 | モデル の場合 | ルート の場合 |
|---|---|---|
readOnly · writeOnly · nullable | timestamps · softDelete(真偽値) | idempotent · deprecated(真偽値) |
unique · searchable · immutable · pii | 運用プロファイル(値):volumetry · accessPattern · traffic · freshness · sensitivity · retention | cacheSeconds(数値) · pagination(オブジェクト) |
モデルの 運用プロファイル の値:accessPattern
(readHeavy / writeHeavy / balanced / appendOnly)、traffic
(low / medium / high)、freshness(strong / shortCache / longCache)、
sensitivity(public / internal / confidential / pii)、retention
(permanent / archivable / ephemeral)、volumetry(hundreds /
tenThousands / millions)。
例:読み取り需要の高いデータをキャッシュする
Section titled “例:読み取り需要の高いデータをキャッシュする”情報がすでに設計にあるかどうかに応じて、2 つのケースがあります。
a) 設計がすでにその情報を持っている
Section titled “a) 設計がすでにその情報を持っている”あるルートに キャッシュ期間 を入力していれば、それは route['cacheSeconds']
に届きます。route['idempotent'] は、それがキャッシュに安全(読み取り専用)で
あることを教えてくれます。
{% for group in ctx['groups'] %}{% for route in group['routes'] %}{% if 'cacheSeconds' in route and 'idempotent' in route %}// {{ route['method'] }} {{ route['fullPath'] }}app.use("{{ route['fullPath'] }}", cache({{ route['cacheSeconds'] }}));{% endif %}{% endfor %}{% endfor %}b)「読み取り需要が高い」はモデルのネイティブなフィールド
Section titled “b)「読み取り需要が高い」はモデルのネイティブなフィールド”変数は不要です:「読み取り需要が高い」は、モデルの アクセスプロファイル その
ものです。モデルの設定の 運用プロファイル グループで Lecture dominante
(読み取り優勢)を選ぶと、テンプレートはそれを model['accessPattern'] で
読み取ります。それを model['freshness'](フレッシュネスの許容度)と組み合わせて、
キャッシュすべきか、どれくらいの時間キャッシュするかを決めます。
{% for model in ctx['models'] %}{% if model['accessPattern'] == 'readHeavy' and model['freshness'] != 'strong' %}{% set ttl = 3600 if model['freshness'] == 'longCache' else 60 %}registerCache("{{ model['name'] }}", {{ ttl }}); // cache activé ({{ ttl }}s){% endif %}{% endfor %}!= 'strong' のテストに注目してください:読み取り優勢 だが 強い一貫性の
モデルは、キャッシュ すべきではありません。2 つの意図を設計の中で並べて持つ
ことの、まさにその意義がここにあります。
生成変数 は、設計がまだ持っていないもの(テンプレート 固有の設定)のためにとっておいてください:ビジネス上の意図 — volumetry、 accessPattern、traffic、freshness、sensitivity、retention — はモデルの ネイティブな フィールド です。
このコンテキストはバージョン管理され(ctx['contextVersion'])、アプリケーションの
リポジトリに同梱された JSON-Schema
(docs/contributing/design-codegen-context.schema.json)によって網羅的に記述
されています — それをあなたのテンプレートにコピーすれば、その CI が基準コンテ
キストを検証します。AI エージェントは、MCP ツール get_design_template_contract
を介して同じ契約をその場で取得します。