# Derived values

Beside the raw, IR-shaped context, the engine offers **derived** context: deterministic facts that templates would otherwise reconstruct. It exists so a template can mostly look like the code it emits, in any renderer, including logic-light ones such as Handlebars.

Derived context follows the same rules as all context:

- **Demand-driven.** Only analysed and validated requirement paths are projected. Requesting `value.is.boolean` produces that one flag; sibling flags and raw branches stay absent.
- **Renderer- and framework-neutral.** No field names a target language, framework or database. Mapping a classification to code (`z.string().uuid()`, `@Column("uuid")`) stays visible in the pack.
- **Explainable.** Each field carries provenance: `derived` (semantic facts) or `planning` (provider `planning-file`). `dryv context show <path>` prints it.
- **Additive.** Raw fields stay; derived fields sit next to them.
- **Snake case.** Every renderer-facing path segment is lower `snake_case`, including pack input names. Dryv-known keys in `dryv.yaml` and `dryv.pack.yaml` are snake_case too; Dryv-known values stay kebab- or dot-case.

## Classifications: `is`

Closed boolean flags replace `kind`/`type`/`format` comparisons. Exactly the flags that apply are `true`.

| Path                                                                           | Flags                                                                                                                                                                                                                                                                                                                                   |
| ------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<value>.is` (semantic values)                                                 | `schema`, `property`, `unknown`, `dynamic`; property kinds (`primitive`, `enum`, `composite`, `literal`, `union`, `record`, `tuple`, `generic`, `temporal`); primitive types, kinds and formats (`string`, `number`, `boolean`, `integer`, `decimal`, `uuid`, `email`, `hex_color`, …); temporal kinds (`date`, `time`, `date_time`, …) |
| `property.primitive.is`, `property.temporal.is`                                | the primitive or temporal flags alone                                                                                                                                                                                                                                                                                                   |
| `relation.is`, `relation.on_delete_is`, `relation.on_update_is`                | `one_to_one`, `one_to_many`, `many_to_one`, `many_to_many`; `restrict`, `cascade`, `detach`, `reset`                                                                                                                                                                                                                                    |
| `facets.http.is`                                                               | `get`, `post`, `put`, `patch`, `delete`, `head`, `options`, `trace` (there is no `method_name`: turning a method into a target name is the pack's decision)                                                                                                                                                                             |
| `facets.http.inputs[].is`                                                      | `path`, `query`, `query_object`, `header`, `cookie`, `body`, `multipart`, `form`                                                                                                                                                                                                                                                        |
| representations `.is`                                                          | `json`, `xml`, `csv`, `text`, `bytes`, `event_stream`                                                                                                                                                                                                                                                                                   |
| `facets.http.path.segments[].is`                                               | `literal`, `parameter`                                                                                                                                                                                                                                                                                                                  |
| invariant `form.is`, `comparisons[].is`, operand `.is`, operand `.operator_is` | form, comparison operator, operand kind and arithmetic operator flags                                                                                                                                                                                                                                                                   |

Top-level value flags (`schema`, `property`, `unknown`, `dynamic`) never resolve the referenced property; property-specific flags resolve it only when requested.

## Presence: `has_*`

`length.has_exact|has_min|has_max`, `range.has_min|has_max`, `array.has_min|has_max`, and `constraints.has_multiple_of|has_bits|has_unsigned|has_precision|has_scale` say whether a bound is declared. They are true for `0` and `false`, so templates never rely on truthiness.

## JSON literals: `*_json`

The JSON text of a canonical literal, beside the raw value, for renderers that cannot encode values:

`default.value_json`, enum `values[].value_json`, `pattern.match_json[]` (and `starts_json`, `ends_json`, `allow_json`, `deny_json`), invariant `message_json`, operand and term `value_json`. JSON is the IR's own value format, so the text is a safe literal for any JSON-compatible target; templates embed it raw (`{{{field.default.value_json}}}`).

## HTTP views

- `facets.http.input_groups.<kind>[]`: the bindings of one kind (`path`, `query`, `query_object`, `header`, `cookie`, `body`, `multipart`, `form`) in declaration order. A body-only request never materialises the other groups. `facets.http.inputs` stays the canonical ordered list.
- `facets.http.path.effective`: the deterministic full route assembled from the active application HTTP root, the owning group's parent chain from root to leaf, and the operation-local path. Scope roots remain canonical semantic facts; only the join is derived.
- `facets.http.path.segments[]`: the canonical local path split once into `literal` text and `parameter` names, from the same `{name}` grammar IR validation uses. Target syntax such as `:id` stays in packs.

## Field storage

`schema.fields[].storage.primary_key`: whether the field is part of the effective primary key, using the validator's `effective_primary_key` rule (inherited storage included). A schema without local or inherited storage gives `storage: null`. Storage facts come from canonical declarations, never field names.

## Planned generated representations

How the planner already represents a subject **for the current file**, from that file's own dependencies only:

| Path                                                                                                                                                                                                           | Meaning                                                                                                                                                                                                                          |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `<value>.generated.all[]`, `<field link>.generated.all[]`                                                                                                                                                      | every representation of the subject, in planner order                                                                                                                                                                            |
| `….generated.same_pack[]`                                                                                                                                                                                      | representations from the current pack (a list: several templates may represent one subject)                                                                                                                                      |
| `….generated.schema_types` · `schema_validation` · `schema_persistence` · `schema_examples` · `property_enum_types` · `property_types` · `operation_client` · `operation_implementation` · `operation_usecase` | the representation through that bound slot, or null. A bound slot resolves to one provider template, so at most one exists; if the planner ever yields more, projection fails with `context.projection.representation_ambiguous` |
| `file.dependency_groups.<group>[]`                                                                                                                                                                             | the file's dependencies grouped the same way (`same_pack` and the five slot groups)                                                                                                                                              |
| `file.dependencies[].is_self`                                                                                                                                                                                  | the dependency is the current file (self-referencing subjects), so templates can skip a self-import                                                                                                                              |

Each item is a generated dependency: `symbol`, `symbols`, `path`, `template`, `pack`, `slot`, `target`.

## Discovery

`dryv context list` prints every root and type; `dryv context show <path>` explains one path (root, cardinality, provenance, provider, and the fields it leads to), with `--json` for both. The engine derives these from the registries requirement validation uses, served read-only by `GET /v1/context/catalog` and `GET /v1/context/path?path=…`. A lookup always answers with `info` or a stable `error` code: `context.root.unknown`, `context.path.collection_invalid`, `context.path.field_unknown`, `context.path.named_map_key`.

## Renderers

Jinja, Handlebars and Liquid read the same vocabulary. `source/plugins/templating/_conformance/` holds one case written in all three; each renderer's tests check that it yields the same leaf requirement paths (exact paths that are not a prefix of another; Handlebars `{{#with}}` also lists the object it tests, which the engine merges into the same request tree). Mustache is render-only: its sections don't distinguish booleans, objects and lists, so it can't derive exact requirements.

The `sdk/_examples/packs/zod` pack is the logic-light proof: one Handlebars template with no custom helpers whose output is byte-identical to its earlier Jinja version. Other packs stay on Jinja, where macros keep target mappings readable, and use derived flags instead of `kind` comparisons.

## Known gaps

- **Partials.** Packs have no non-emitted resources: every file under a template boundary is generated, and `.dryvignore` also hides files from snapshots. Logic-light templates therefore repeat reusable mappings or inline them.
- **Representation traits.** The `schema.validation` slot doesn't say whether its representation is a class, a Zod schema or a Joi schema. That is a capability-model question, deferred to its own design; packs keep their current behaviour.
- **Mustache analysis** stays deferred without a protocol change.
