Skip to content

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 โ†’ PostgreSQL project.id (logical; enforced by application scope checks)
  • code_variation.code_id โ†’ code._id in the same organization/project
  • code_graph.source_code_id / target_code_id โ†’ code._id in the same scope
  • code_index.profile.components[].code_id โ†’ code._id in 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-import owns replacements in code; undeclared legacy fields are rejected.
  • There is no index_schema_version, top-level code_context, visual embedding, variation inventory, model/encoder metadata, profile pin, or history field.
  • An effective code write marks the scoped code_index stale.
  • code_variation stores one successfully rendered Storybook state with _id, scope, variation_id, code_id, name, image metadata/description, visual.vector_embedding, and processing.hash. Its unique index is (organization_id, project_id, variation_id); it also has scoped code_id and variationVisualVectorIndex indexes.
  • code_graph stores current resolved edges with _id, scope, source_code_id, source_name, nullable target_code_id, target_name, and relation=references. Scoped source/target indexes support expansion.
  • code_index stores one stable current document per organization/project: status (ready/stale), context.terms, profile.components[{code_id, variation_mode}], and nullable processing.rebuild{token, expires_at}. A unique scope index enforces the singleton; its _id is scope-derived, not a content version.
  • The explicit code-index worker rebuilds code_graph and publishes the ready code_index transactionally after validating all current code/variation inputs.