code コレクション
概要
Des2Code が使う canonical current source-code projection です。code-import は
backend code record ごとに strict document 1 件を replace します。rendered
Storybook state、resolved dependency、project readiness はそれぞれ
code_variation, code_graph, code_index に分離します。
テーブル定義
| 論理名 | 物理名 | カラム名 | データ型 | 主キー | リレーション | ユニーク | NULL許容 | デフォルト値 | 備考 |
|---|---|---|---|---|---|---|---|---|---|
| コード情報 | code | _id | string | ◯ | stable backend code UUID | ||||
| organization_id | number | tenant owner、positive integer | |||||||
| project_id | number | project:id | project scope、positive integer | ||||||
| name | string | component/page name | |||||||
| type | number | 0: page 1: component |
|||||||
| based_on | number | 0: imported 1: design 2: wireframe |
|||||||
| source_code | string | current source。matched code detail で返却 | |||||||
| css_code | string | ◯ | present の場合 current CSS | ||||||
| visual.metadata.name | string | display name | |||||||
| visual.metadata.image_url | string | ◯ | optional preview URL。code visual vector は保存しない | ||||||
| semantics.metadata.words | string[] | non-empty semantic vocabulary | |||||||
| semantics.vector_embedding | float[512] | Des2Code semantic vector | |||||||
| context.metadata.component_level | string | page/atom/molecule/organism などの parsed level | |||||||
| context.metadata.family | string | parsed implementation family | |||||||
| context.metadata.variant | string | ◯ | parsed source-level variant | ||||||
| context.metadata.imports | object[] | [] | {source, specifiers, default_import, namespace_import} |
||||||
| context.metadata.exports | string[] | [] | exported symbol | ||||||
| context.metadata.referenced_components | string[] | [] | resolved source reference name | ||||||
| context.metadata.class_names | string[] | [] | parsed CSS/class name | ||||||
| context.metadata.source_tokens | string[] | [] | normalized source token | ||||||
| context.metadata.text | string | retrieval 用 deterministic source-context text | |||||||
| context.vector_embedding | float[512] | Des2Code source-context vector | |||||||
| processing.hash | string | 64-character SHA-256 idempotency fingerprint |
リレーション
project_id→ PostgreSQLproject.id(logical。application scope check で enforcement)code_variation.code_id→ 同一 organization/project のcode._idcode_graph.source_code_id/target_code_id→ 同一 scope のcode._idcode_index.profile.components[].code_id→ 同一 scope のcode._id- DocumentDB は foreign key を enforcement しないため import/index worker が validate する。
インデックス
- PRIMARY KEY (
_id) - INDEX
code_scope_catalog(organization_id,project_id,type,name) - VECTOR INDEX
codeSemanticVectorIndex(semantics.vector_embedding) - VECTOR INDEX
codeContextVectorIndex(context.vector_embedding)
Atlas vector index は organization_id / project_id を filter path に含めます。
DocumentDB は exact vector search 前に scoped $match を使います。
ベクトルインデックスオプション
- dimensions: 512
- similarity: cosine
- m: 16
- efConstruction: 64
種別コード
- 0: Page
- 1: Component
由来コード (based_on)
- 0: Imported
- 1: Design
- 2: Wireframe
注記
code-importがcodereplace を所有し、undeclared legacy field は reject する。index_schema_version、top-levelcode_context、visual embedding、variation inventory、model/encoder metadata、profile pin、history field は存在しない。- effective code write は scoped
code_indexをstaleにする。 code_variationは successfully rendered Storybook state 1 件を_id, scope,variation_id,code_id,name, image metadata/description,visual.vector_embedding,processing.hashで保存する。unique index は(organization_id, project_id, variation_id)。scopedcode_idindex とvariationVisualVectorIndexも持つ。code_graphは current resolved edge を_id, scope,source_code_id,source_name, nullabletarget_code_id,target_name,relation=referencesで保存する。scoped source/target index を持つ。code_indexは organization/project ごとに stable current document 1 件を持つ。 field はstatus(ready/stale)、context.terms、profile.components[{code_id, variation_mode}]、nullableprocessing.rebuild{token, expires_at}。unique scope index が singleton を enforcement し、_idは scope-derived で content version ではない。- explicit
code-indexworker は current code/variation input 全体を validate 後、code_graphと readycode_indexを transaction 内で publish する。