Lenses

A Lens is a named graph pattern over DNA — typed node slots joined by directed edges — that the same definition uses to both query the graph and assert bindings into it.

DNA's nouns (resource types) and its connections (relationship types) describe the graph. A Lens names a pattern over that graph: a small set of typed node slots, the directed edges between them, and an optional sentence that reads the pattern in plain language.

The same Lens definition works in two directions:

  • Query — find every subgraph in a DNA document that matches the pattern (e.g. every subject holds assignment within boundary binding that exists).
  • Command — assert a specific binding of the pattern into the graph (e.g. grant this subject that assignment). No separate schema is needed for each direction.

The LensType contract

Every lens — the core ones below and any you declare inside a DNA document's lenses block — composes a shared base contract:

  • name — a human-readable name for the pattern.
  • nodes[] — the typed slots. Each declares a type (the resource type it holds) and, when an edge or the sentence references it, a slot identifier.
  • edges[] — directed connections between slots. Each declares from and to (slot names) and via (the relationship type traversed). Layer lenses omit edges entirely.
  • sentence — an optional template with {{slot}} markers, one per declared slot, giving a readable rendering of the pattern.

The lenses below ship with @dna-codes/dna-core and fall into two shapes: layer lenses, which group a whole layer's resource types with no edges, and subgraph & traversal lenses, which wire a few slots together along named relationships.

Layer lenses

Each layer lens groups all the resource types in one DNA layer — nodes, no edges.

Operational layer lens

Resource types

  • Person
  • Group
  • Role
  • Membership
  • Domain
  • Resource
  • Operation
  • Action
  • Process
  • Rule
  • Task
  • Trigger

Product layer lens

Resource types

  • User
  • Role
  • Resource
  • Operation
  • Action
  • Field
  • Endpoint
  • Namespace
  • Param
  • Schema
  • Block
  • Layout
  • Page
  • Route

Technical layer lens

Resource types

  • Cell
  • Connection
  • Construct
  • Environment
  • Node
  • Output
  • Provider
  • Variable
  • View
  • Zone

Subgraph & traversal lenses

These lenses connect resource types across relationships, with a sentence that reads the pattern aloud.

People subgraph lens

person belongs to group

Node slots

SlotResource type
personPerson
groupGroup

Edges

FromToVia (relationship)
persongroupPerson_Group

Access Control subgraph lens

subject holds assignment within boundary , granting grant against target

Node slots

SlotResource type
subjectUser
assignmentRole
boundaryDomain
grantOperation
targetResource

Edges

FromToVia (relationship)
subjectassignmentUser_Role
assignmentboundaryRole_Domain
assignmentgrantRole_Operation
granttargetOperation_Resource

Execution subgraph lens

process runs through task , triggered by trigger

Node slots

SlotResource type
processProcess
taskTask
triggerTrigger

Edges

FromToVia (relationship)
processtaskProcess_Task
triggerprocessTrigger_Process