Template schema and option flags
Template data gives the catalog and the scaffolding flow one shared description of a starter project. The system validates catalog records before selection, then reads a second template contract from the generated project's package.json to apply template-specific choices from the command line.
This page is a child of Template catalog and selection. Read Template catalog retrieval for how validated records become catalog choices and Template menu and prompts for how users select them.
Template data model
The catalog model describes templates as entries inside named groups. The catalog is a list of groups. Each group has a description, a display name, a path, and its templates. A template has the required identity and display fields below, plus optional presentation fields.
| Field | Role |
|---|---|
id | Stable identity used by listing and later source handling |
name | User-facing name and direct lookup value |
description | Short explanation shown in catalog and menu output |
path | Source path for a catalog template |
keywords | Terms used by menu filters |
displayName | Optional alternate display label |
image | Optional visual asset reference |
usecase | Optional description of the intended use |
The catalog contract keeps source data separate from menu policy. Menu records reuse the template entries but add the category identity and selected group information needed for prompts. A selected template may also be a local or external descriptor, so the internal Template type permits fields such as keywords and path to be absent after lookup.
References: src/…/template-schema.ts• L3-25 src/…/template-schema.ts• L46-64 src/…/template.ts• L1-6 src/…/find-template.ts• L16-53
Catalog validation
Catalog validation is the trust boundary between a remote templates.json document and the selection flow. The parser first reads JSON and then checks the complete value against the group and template schemas. A parse error or shape error returns a failed result, so fetching cannot pass a partial or malformed catalog to menus or lookup.
The catalog schemas are also exported as types and public parsing tools. This keeps producers of catalog data and consumers of catalog data aligned around one contract rather than relying only on TypeScript declarations.
References: src/…/template-schema.ts• L24-49 src/…/fetch-templates.ts• L3-17 src/index.ts• L43-56
Runtime template contract
The runtime template contract lives in the create-solana-dapp field of the generated project's package.json. It describes work that the scaffolding flow can perform after it copies the template. The contract is optional, which lets a template remain usable without custom setup behavior.
The top-level contract supports these areas:
packageManagercan state the package manager required by the template.optionsdefines named template choices exposed to command-line flags.instructionssupplies messages for the final init step.renameandskillsdescribe other template setup actions.versionsdeclares tool versions that the init flow can check.
The package reader validates this field while allowing unrelated package.json fields to pass through. This makes the runtime contract strict where the scaffolder depends on it without making the scaffolder own the full package format.
References: src/…/init-script-schema.ts• L4-17 src/…/init-script-schema.ts• L47-74 src/…/get-package-json.ts• L6-31
Template option metadata
Template option metadata turns a short flag into a supported, repeatable setup choice. Each option is keyed by a lower-case name such as ollama, which the CLI exposes as --ollama. The metadata can describe its default state, prompt-facing description, option group, file changes, instructions, and an optional package script to run.
| Metadata | Effect |
|---|---|
default | Selects the option when no option in its group was requested |
description | Describes the choice to a user-facing consumer |
group | Places choices in a mutually exclusive set |
rename | Applies option-specific file or path changes during init |
instructions | Adds option-specific messages to the init result |
run | Names a package script and optional safe arguments to run before install |
Groups express alternatives rather than a display-only category. A requested option suppresses other defaults in its group. If more than one selected option belongs to the same group, option resolution rejects the combination before creation work continues.
The schema restricts option names to lower-case letters, digits, and hyphens. It also limits run values to a safe command form because the value reaches a shell. The template must provide the named package script when the option is selected.
References: src/…/init-script-schema.ts• L49-65 src/…/init-script-options.ts• L10-62 src/…/create-app-task-run-option-script.ts• L15-53
Option flag extraction
Option extraction separates template-defined boolean flags from the CLI's own options before the main argument parser runs. It keeps registered options and their values in the normal argument list. It stores each unknown long flag as a template option name for later validation against the selected template.
The extraction boundary is deliberately syntax-only. It accepts flags that match --name and deduplicates repeated names, but it does not know whether the selected template supports them. This allows the same CLI parser to work with different templates while preserving normal options such as --template <name> and --skip-install.
The extraction rules are:
- Registered long and short options remain normal CLI input.
- A value for a registered option remains attached to that option, even when the value starts with
--. --ends option scanning, so later values remain positional input.- Unknown short flags and flags with inline values are rejected because template options are boolean long flags only.
References: src/…/extract-template-option-flags.ts• L3-57 src/…/extract-template-option-flags.ts• L60-74 test/extract-template-option-flags.test.ts• L9-61
Option selection lifecycle
The selected flag names travel with the resolved creation input until the chosen template's runtime metadata can validate them. This delays template-specific checks until the template has been selected and copied, while still failing before option scripts or init transformations can change the project.
The lifecycle connects catalog identity, CLI input, runtime metadata, and setup effects as follows.
flowchart TD
A[Catalog template record] --> B[Selected template]
C[CLI input] --> D[Extract boolean long flags]
D --> E[Resolved creation input]
B --> E
E --> F[Read create-solana-dapp metadata]
F --> G{Flags supported?}
G -- No --> H[Stop with supported-option error]
G -- Yes --> I[Resolve defaults and groups]
I --> J[Run option scripts]
J --> K[Apply init changes and instructions]
Option resolution occurs before option scripts run. The creation flow snapshots the init metadata and resolved selections first. This preserves the selected behavior even if an option script changes package.json; dependency installation and the later init step then use the same resolved choices.
References: src/…/get-args.ts• L54-65 src/…/get-args.ts• L124-157 src/…/create-app.ts• L50-72 src/…/init-script-options.ts• L13-73
Public schema surface
The schema types and parsers are part of the public package surface. Consumers can use the catalog schemas and parser to validate catalog data, while runtime contract types describe the metadata that templates can publish in package.json.
This public surface makes schema changes cross-boundary changes. A field can affect remote catalog authors, menu filtering, direct template lookup, CLI flags, or the generated project's setup behavior even when the change starts in one schema file.
References: src/index.ts• L19-56 src/…/template-schema.ts• L27-49 src/…/init-script-schema.ts• L76-84
Change checklist
When these files or sections are changed, remember to consider these:
- Keep catalog field changes aligned with remote templates.json producers, menu filters, listing output, and direct lookup.
- Keep
Templateidentity variants aligned with catalog, external, and local template sources. - Keep option-name syntax aligned between CLI extraction and runtime option metadata.
- Keep option group and default rules aligned with the error checks that run before option scripts.
- Preserve the order between option-script execution, dependency installation, and init transformations when changing the runtime contract.
- Keep exported schema types and parsers aligned with the package's public API.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A catalog record omits a required field or uses the wrong shape | Catalog retrieval stops before template selection | Validate the full catalog against the shared schema |
| A CLI flag uses short syntax or an inline value | Argument handling stops before template selection | Use a lower-case boolean long flag such as --ollama |
A requested flag is absent from the selected template's options | Creation stops before option scripts run | Define the option in the template metadata or remove the flag |
| Two selected options share a group | Creation stops before setup changes are applied | Select only one option in each mutually exclusive group |
| An option names a missing package script | The option stage fails before dependency install | Add the named script to the template's package.json |
| A runtime option script rewrites metadata before selections are resolved | Intended option changes can be lost | Snapshot and resolve metadata before running option scripts |
Key files
| File | Why to read it |
|---|---|
| src/…/template-schema.ts | Defines the catalog, group, menu, and parser contracts |
| src/…/template.ts | Defines the internal template shape used after source resolution |
| src/…/init-script-schema.ts | Defines the package.json runtime contract and option metadata |
| src/…/init-script-options.ts | Resolves requested flags, defaults, groups, and option effects |
| src/…/extract-template-option-flags.ts | Defines the boundary between CLI options and template flags |
| src/…/get-args.ts | Connects flag extraction to template selection and resolved inputs |
| src/…/create-app.ts | Places metadata validation and option resolution in the creation lifecycle |
| src/…/create-app-task-run-option-script.ts | Shows how selected option scripts affect setup before install |
| src/index.ts | Shows which schema types and parsers are public |