Generated code
Generated code
Section titled “Generated code”Generated files connect a consumer project’s maintained source to the public Studio and server boundaries. They are integration output, not a second authoring implementation.
Generation flow
Section titled “Generation flow”flowchart LR templateSource["src/templates/**/template.tsx"] --> discovery["findTemplates"] brandSource["src/brand/**"] --> brandDiscovery["findBrandComponents"] discovery --> summaries["validate definitions and collect summaries"] discovery --> registry["src/generated/framekit/templates.ts"] brandDiscovery --> brands["src/generated/framekit/brands.ts"] summaries --> registry assetSource["template assets/common and assets/variant"] --> assetSync["remove and copy current assets"] assetSync --> publicAssets["public/framekit/templates/**"] registry --> studioClient["src/generated/framekit/studio-client.tsx"] registry --> renderClient["src/generated/framekit/render-client.tsx"] brands --> studioClient
writeTemplateModule performs this flow for a project root:
- It discovers directories under
src/templates/that containtemplate.tsx, turns their path segments into a slash-separated slug, and sorts the discovered templates by slug. - It executes a temporary summary module with
tsx, validates each definition, and records metadata, dimensions, variants, and the declared content-key order. - It writes the
templatesregistry with lazy loaders, the brand registry, and the generated Studio and render client bindings. - It discovers image assets, removes the previous
public/framekit/templates/tree, copies the current files, and records the generated asset URLs in each registry entry.
Brand directories with a component.tsx are registered when they also provide
preview.tsx and a descriptive README.md. The generated brand module keeps
metadata and lazy preview loaders separate from the maintained component source.
Generated paths
Section titled “Generated paths”The canonical generated project contains:
src/generated/framekit/├── brands.ts├── render-client.tsx├── studio-client.tsx└── templates.ts
public/framekit/templates/└── <template-slug>/...templates.ts contains TemplateRegistryEntry metadata, assets, and lazy
definition loaders. studio-client.tsx binds the registries to
FrameKitStudio; render-client.tsx binds the template registry to
createRenderClient. These client graphs are intentionally separate: the
render client does not import Studio or the brand registry.
Asset files are copied only from the supported template asset directories. The generated public tree can be deleted and rebuilt. Other public files are not removed by this synchronization.
When output changes
Section titled “When output changes”Generation runs in these places:
framekit generateruns it explicitly.framekit checkgenerates before validation.framekit buildrunscheck, so it generates before the Next.js build.framekit devgenerates once before starting and watchessrc/templatesandsrc/brandfor changes.framekit startreads the existing production output and does not generate.
Generated output is ignored and disposable. Change template.tsx, brand source,
or maintained asset files, then regenerate. Do not edit
src/generated/framekit/, public/framekit/, .framekit/, or build output by
hand. The generated files reference lists
the consumer-facing paths, and the template registry reference
describes the registry entry shape.