Skip to content

Traits

A trait is a named micro-capability: a partial schema contributing zero or more attributes to the entity that declares it. Composition is commutative and associative; the trait vocabulary is closed and canonical, and a name is never renamed or aliased.

Traits marked (marker) contribute no attributes: they declare a capability whose data lives in edges, which are stored once, outgoing direction only.

An entity composes traits. The 20 traits of the closed vocabulary, in 7 families, each with the attributes it contributes; a dashed box is a marker trait, which contributes none.Codegraph MetamodelTraitsBASECONTAINMENT & ATTACHMENTSTRUCTUREMODULARITYMEASURESTYPESBEHAVIOR0..30..30..40..10..10..40..41Entity{ id, kind, traits[], …trait keys }Language Profilelicenses, per kind, the traits anentity must and may composeTNamedname: stringTSourceAnchoranchor: SourceAnchorTCommentcomments: string[]TWithChildrenchildren: derived from parentTChildOfparent: EntityIdTAttachedToattachedTo: EntityIdTStructuralvalue holder, target of accessesTWithAccesses→ access edgesTWithValuevalue: LiteralTWithReceiverneeds an instance of its typeTModuledefinedIn: string[]isStub: booleanTMetricsmetrics: Record<string, number>measured, never defaultedTTypeisStub: booleanTWithInheritances→ inheritance edgesTWithImplements→ interfaceImplementation edgesTTypedEntitydeclaredType?: EntityIdtypeExpr?: TypeExprTInvocablesignature: stringTWithParametersparameters: EntityId[]TWithLocalVariableslocalVariables: EntityId[]TWithInvocations→ invocation edgescontributes attributes to the entitymarker: contributes no attributeexample, a Clojure fn-var:TNamed + TStructural + TInvocable
Select a box to jump to its section. Open the diagram alone (SVG)

The diagram is a map of this page: an entity composes at most one of each trait, so zero to all of a family’s. A dashed box is a marker, and the three red dots are the composition that motivates the design.

Base

TraitAttributes contributedNotes
TNamedname: stringNot universal: lambdas, closures, Rust impl blocks, Java constructors have no own name
TSourceAnchoranchor: SourceAnchorEvidence for the entity’s declaration
TCommentcomments: string[]Attached documentation/comments

Containment and attachment

Where an entity is written (lexical containment) and what it semantically belongs to (attachment) are different relations, and both are kept.

TraitAttributes contributedRelation expressed
TWithChildrenchildren: EntityId[] (v1 only, see below)lexical containment, downward
TChildOfparent: EntityIdlexical containment, upward — the STORED direction
TAttachedToattachedTo: EntityIdsemantic attachment. Required by: Go receiver methods, Rust impl blocks, C# extension methods, Clojure extend-type/defmethod

A Go method with receiver (o *Order) is a child of its file/package and attached to Order.

children is an inverse index, not a fact. It is the exact inverse of parent, and inverse views are derived in memory, never serialized. TWithChildren stays a declared trait: it says an entity is a container. Only the serialized key goes.

Modularity

TraitAttributes contributedNotes
TModuledefinedIn: string[] (CodeFile paths), isStub: booleanmodule↔file cardinality varies by language: 1-1 (JS/TS/Python: module is the file), 1-N (Java package, C#/Go/PHP namespace), N-N (Rust inline mod). A stub module has definedIn: [], which is exactly what makes it external

Types

TraitAttributes contributedNotes
TTypeisStub: booleanany type-like entity: class, interface, struct, enum, protocol, PHP/Rust trait
TWithInheritances(marker) — see inheritance edgesmultiple inheritance = N edges (Python). Absent from the Go and Rust profiles — that absence is profile information, not a gap
TWithImplements(marker) — see interfaceImplementation edges
TTypedEntitydeclaredType?: EntityId, typeExpr?: TypeExprboth optional even when the trait is present: absent value in JS/Python/Clojure, C# var, inferred Go/TS/Rust. declaredType is the erased head; typeExpr (contract 1.2.0) the type as written — see Type expressions

Type expressions

typeExpr is the type a declaration writes, as a tree: List<OrderLine> is a named type with one argument, int[] an array of a primitive, T? a nullable. Eight forms, a closed vocabulary:

FormShapeNotes
named{k: "named", type: EntityId, args?: TypeExpr[]}a declared type or a stub, with its written type arguments in order; args absent when none is written
primitive{k: "primitive", name: string}the language’s own word: int, long, boolean
array{k: "array", of: TypeExpr}
nullable{k: "nullable", of: TypeExpr}only where the language writes it (T?, T | null)
function{k: "function", params: TypeExpr[], returns?: TypeExpr}returns absent = no value
union{k: "union", of: TypeExpr[]}at least two, in written order
variable{k: "variable", name: string}a type parameter
unevaluated{k: "unevaluated", source: string}a written type the extractor did not structure (a wildcard); the text is still a fact

It is what is written, never what is inferred: no typeExpr on a var or a void return. The ids inside count for closure, exactly like an edge’s ends, and the reference edges a written type emits are still emitted. No extractor writes it yet; the Java extractor is next.

Behavior

TraitAttributes contributedNotes
TInvocablesignature: stringsignature is part of identity (Java/C# overloads, Go receivers)
TWithParametersparameters: EntityId[]ordered
TWithLocalVariableslocalVariables: EntityId[]
TWithInvocations(marker) — see invocation edgesoutgoing only; incoming is derived by the analyzer, never stored

Structure

TraitAttributes contributedNotes
TStructural(marker) — value holderattributes, variables, parameters, Clojure vars. Legal target of access edges
TWithAccesses(marker) — see access edgesoutgoing only
TWithValuevalue: Literalthe entity’s declaration-site constant value. Optional wherever licensed — absence means “not constant”, never “empty”
TWithReceiver(marker)evaluated against an instance of the type it is written in or attached to: an instance field, an instance method, a constructor (contract 1.2.0)

TWithReceiver tells Order.channel from Order.MAX_LINES, which Java’s attribute kind does not. A profile licenses it, optional, on the kinds it can decide it for — Java: attribute, method, constructor. Where it is licensed, absence means “no receiver” (a static member, an enum constant); where it is not, absence means nothing. An access edge’s receiver is its counterpart on the edge.

Measures

TraitAttributes contributedNotes
TMetricsmetrics: Record<string, number>open map of measured finite numbers. Only a source reader writes it: the extractor, or the metrics pass over its model

See Measures and literals.

The composition that motivates the design

A Clojure var holding a function is simultaneously named, a value holder, and invocable: traits: [TNamed, TStructural, TInvocable]. No tree-shaped hierarchy can place it; trait composition expresses it directly. The argument is in Why traits.

The closed vocabulary

Twenty names, in the order the header dictionary’s enum declares them:

TNamed · TSourceAnchor · TComment · TWithChildren · TChildOf · TAttachedTo · TModule · TType · TWithInheritances · TWithImplements · TTypedEntity · TInvocable · TWithParameters · TWithLocalVariables · TWithInvocations · TStructural · TWithAccesses · TWithReceiver · TMetrics · TWithValue

The keys each contributes on the wire are listed under model.jsonl.

Last updated on