Code Collection
Overview
Canonical current source-code projection used by Des2Code. code-import
replaces one strict document per backend code record. Rendered Storybook states,
resolved dependencies, and project readiness are stored separately in
code_variation, code_graph, and code_index.
Table Definition
| Logical Name | Physical Name | Column Name | Data Type | Primary Key | Relation | Unique | Nullable | Default Value | Remarks |
|---|---|---|---|---|---|---|---|---|---|
| Code Information | 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 or page name | |||||||
| type | number | 0: page 1: component |
|||||||
| based_on | number | 0: imported 1: design 2: wireframe |
|||||||
| source_code | string | Current source; returned in matched code detail | |||||||
| css_code | string | โฏ | Current CSS when present | ||||||
| visual.metadata.name | string | Display name | |||||||
| visual.metadata.image_url | string | โฏ | Optional preview URL; no code visual vector is stored | ||||||
| semantics.metadata.words | string[] | Non-empty semantic retrieval vocabulary | |||||||
| semantics.vector_embedding | float[512] | Semantic vector used by Des2Code | |||||||
| context.metadata.component_level | string | Parsed level such as page/atom/molecule/organism | |||||||
| 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 symbols | ||||||
| context.metadata.referenced_components | string[] | [] | Resolved source reference names | ||||||
| context.metadata.class_names | string[] | [] | Parsed CSS/class names | ||||||
| context.metadata.source_tokens | string[] | [] | Normalized source tokens | ||||||
| context.metadata.text | string | Deterministic source-context text embedded for retrieval | |||||||
| context.vector_embedding | float[512] | Source-context vector used by Des2Code | |||||||
| processing.hash | string | 64-character SHA-256 idempotency fingerprint |
Relations
project_idโ PostgreSQLproject.id(logical; enforced by application scope checks)code_variation.code_idโcode._idin the same organization/projectcode_graph.source_code_id/target_code_idโcode._idin the same scopecode_index.profile.components[].code_idโcode._idin the same scope- DocumentDB does not enforce foreign keys; import/index workers validate them.
Indexes
- 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)
For Atlas, vector indexes also declare organization_id and project_id as
filter paths. DocumentDB uses a scoped $match before exact vector search.
Vector Index Options
- dimensions: 512
- similarity: cosine
- m: 16
- efConstruction: 64
Type Codes
- 0: Page
- 1: Component
Based On Codes
- 0: Imported
- 1: Design
- 2: Wireframe
Notes
code-importowns replacements incode; undeclared legacy fields are rejected.- There is no
index_schema_version, top-levelcode_context, visual embedding, variation inventory, model/encoder metadata, profile pin, or history field. - An effective code write marks the scoped
code_indexstale. code_variationstores one successfully rendered Storybook state with_id, scope,variation_id,code_id,name, image metadata/description,visual.vector_embedding, andprocessing.hash. Its unique index is(organization_id, project_id, variation_id); it also has scopedcode_idandvariationVisualVectorIndexindexes.code_graphstores current resolved edges with_id, scope,source_code_id,source_name, nullabletarget_code_id,target_name, andrelation=references. Scoped source/target indexes support expansion.code_indexstores one stable current document per organization/project:status(ready/stale),context.terms,profile.components[{code_id, variation_mode}], and nullableprocessing.rebuild{token, expires_at}. A unique scope index enforces the singleton; its_idis scope-derived, not a content version.- The explicit
code-indexworker rebuildscode_graphand publishes the readycode_indextransactionally after validating all current code/variation inputs.