# Artifact graph

Planning turns selections and the template filesystem into concrete files, symbols and edges **before rendering** (decision 0007).

## Three levels

```text
SelectionPartition  ─▶  TemplateInvocation  ─▶  PlannedFileArtifact(s)
(which subjects)        (why this instance)      (which concrete files)
```

| Level      | Holds                                                                                                                             |
| ---------- | --------------------------------------------------------------------------------------------------------------------------------- |
| Partition  | selection, subject, scope, axis (`subject:<kind>`, `all`, `feature`, `group`), key, represented subjects                          |
| Invocation | pack, template key, kind (selection, global, export), partition, resolved output (name, path, symbols), imports, exports, trace   |
| File       | identity, source path, workspace path, `raw` or `rendered`, renderer, represented subjects, symbols, dependencies, exports, trace |

Partition identity comes from canonical relationships, never from filenames, tags or output.

## Identity and paths

- File identity = pack + template key (or global resource) + partition identity + source resource. It never depends on render order, content or list position.
- Workspace path = destination path + activation destination root + static prefix before `{key}` + `output.path` + static suffix + filename minus renderer suffix.
  `src/{entity}/entities/$(name).entity.ts.j2` for `User` in `users` → `src/users/entities/user.entity.ts`.
- Paths are portable and relative. Absolute paths, `..`, backslashes, empty names and escaping the source root are all rejected.
- **Collisions are errors.** That covers exact matches, including raw versus rendered (`user.ts` and `user.ts.j2`), and case-folded equivalents (`User.ts` and `user.ts`), within or across packs. There's no last-writer-wins.

## Symbols

- Declared `output.symbol(s)` are the only source of symbol identity. Rendered code is never parsed.
- A symbol-bearing invocation must own exactly one file. If it owns several, planning fails; Dryv never guesses from names or extensions.

## Imports

After producers are planned, Dryv indexes `(pack, template key, canonical subject) → invocation → file → symbols`. For each consumer:

1. collect the canonical references of its represented subjects, through a typed index rather than JSON walking;
2. for each producer allowed in `imports`, find the invocations that represent those targets;
3. record a generated-dependency edge carrying the producer's path and symbols.

- A missing representation adds no edge. Dryv never invents a file.
- Several producer templates for one target are fine, because they're different representations.
- One producer template with several addressable files for the same target is an ambiguity error.
- Import cycles are allowed. Generated references aren't build-order edges.
- An edge says a dependency is _eligible_. The template decides whether to emit import syntax.

## Exports and barrels

- The export stream follows declared `exports` order, then stable file identity or path within each producer. Only identical identities are deduplicated.
- The template key is the unit of export. To keep some files out, split them into another key; there's no filename filtering.
- `barrel: all` makes one invocation. Its subjects are the union of its producers' subjects, with no scalar feature or group.
- `barrel: each` keeps the producer partitions. The producers' axes must be compatible (all `feature`, or all `subject:schema`); otherwise the plan is rejected. When key sets differ, the barrel takes the deterministic union.
- Barrels can export barrels.

## Edge types

Three kinds of edge are kept separate, with no generic "depends on": a **generated reference** (import eligibility), an **export aggregation** (barrel membership) and **invocation ownership** (file belongs to invocation).

## Determinism and trace

Selections, partitions, invocations, files, edges and export streams all have canonical order. Every file can explain which pack, selection, subjects, template, source resource, output and dependencies produced it. See [tracing](/pack-builders/context/tracing).
