# cc.json 2.0 — `{ meta, files, lenses }` > Status: **implemented on both the analysis (`ccsh`) and the visualization side.** `ccsh` emits 2.x > only (currently 2.1); every `ccsh` command reads 2.x, and the legacy 1.x format is read solely by `ccsh convert` > (which upgrades it). The visualization reads 2.0 natively and still opens legacy 1.x files by > normalizing them to 2.0 on load. See > [ADR 12](adr/2026-06-25-ADR_12_separate_file_structure_from_analysis_lenses.md). > > **Machine-readable schema:** [`cc-json-2.0.schema.json`](cc-json-2.0.schema.json) (JSON Schema draft-07). > `ccsh check` validates against the bundled copy in `ValidationTool`; a drift-guard test keeps the two in sync. ## Why The 1.5 format conflated three concerns: file **identity**, analysis **signals** (metrics, edges), and visualization **view state** (blacklist). Identity was *positional* — merge matched nodes by walking the tree from the root down — so heterogeneous tools that root their trees differently (a backend and a frontend built separately, or a coverage report rooted by package) never lined up. 2.0 splits structure from signals and makes identity reproducible, so additive suite lenses (dependency, domain, security, …) can join the file tree without bloating the core. ## Shape ```json { "meta": { "projectName": "p", "apiVersion": "2.1", "checksum": "", "commitHash": "a1b2c3d" }, "files": [ { "id": "", "name": "root", "type": "Folder", "children": [ { "id": "", "name": "src", "type": "Folder", "children": [ { "id": "", "name": "App.kt", "type": "File", "contentHash": "" } ] } ] } ], "lenses": { "metrics": { "attributes": { "": { "rloc": 120, "mcc": 8 } }, "attributeDescriptors": {}, "attributeTypes": {} }, "dependency": { "edges": [ { "fromId": "", "toId": "", "attributes": { "dependencies": 3 }, "isCyclic": true, "isPointingUpwards": true } ], "nodes": { "": { "level": 2 } }, "namespaces": { "com": { "level": 0 }, "com.example": { "parent": "com", "level": 0 } }, "leaves": { "": { "Creature": { "kind": "class", "language": "java", "namespace": "com.example", "level": 2 } } }, "leafEdges": [ { "fromId": "", "fromLeaf": "Creature", "toId": "", "toLeaf": "HitPoints", "attributes": { "dependencies": 1 }, "usage": ["inheritance"], "isCyclic": true, "isPointingUpwards": true } ], "attributeTypes": {}, "attributeDescriptors": {} }, "clusters": { "clusterings": { "author-ownership": { "title": "Author ownership", "membership": "weighted", "weightBasis": "rloc", "analyzers": ["gitlogparser"], "clusters": [ { "id": "author-a", "name": "Author A", "members": [ { "nodeId": "", "weight": 0.62 } ] } ] } } }, "domain": { "nodes": { "": { "words": [ { "text": "invoice", "frequency": 12, "tfidf": 0.42 } ] } } }, "security": {} } } ``` - **`files`** is the identity layer: exactly one root folder, nested `children`, each node carrying a stable `id` and an optional `contentHash`. No metrics live on the node. CodeCharta represents the project root `/` as `/root` for compatibility with the legacy 1.x format: `/hello.ts` appears as `/root/hello.ts`. The JSON root node has `"name": "root"`, with project files and folders in its `children`; the project display name belongs in `meta.projectName`. - **`lenses`** are additive overlays joined to `files` by `id`. `metrics`, `dependency`, `domain` and `clusters` are concrete; `clusters` is optional, produced by `gitlogparser` for author ownership and commit changes, and shown by the metrics view — see [the `clusters` lens](cc-json-2.0-clusters-lens.md) for its full definition and merge semantics; `dependency` carries the graph in both projections — `edges` between node ids plus an optional `nodes` map giving each file and folder the `level` it sits on, and the logical layer (`namespaces`, `leaves`, `leafEdges`), whose declarations are grouped under the id of their file node (see [the dependency graph](#the-dependency-graph-in-the-dependency-lens)); `domain` carries a `nodes` map from node id to that node's entry, each entry holding a `words` bank (each word carrying `text`, `frequency` and an optional `tfidf`) — the envelope keeps room for lens-wide data beside `nodes` and per-node data beside `words`, and an unused lens slot stays `{}`; `security` is reserved. **Unknown top-level lenses are preserved verbatim** on round-trip, so a newer tool's lens survives an older tool. - **`metrics.attributes`** maps file or folder node IDs, not paths, to metric values. `metrics.attributeTypes` describes aggregation: `absolute` values such as line counts are additive, while `relative` values are not. - **`meta.checksum`** is an MD5 over the UTF-8 serialized body `{"files":...,"lenses":...}`, with `files` first and `lenses` second, using compact JSON rather than the whole document or its pretty-printed text. Recompute it when changing the body. See [`ProjectToCcJsonV2Mapper.serializeBody`](../analysis/model/src/main/kotlin/de/maibornwolff/codecharta/serialization/ProjectToCcJsonV2Mapper.kt) for the writer's serialization details. The checksum is folded into `meta`, unlike the 1.5 `{ checksum, data }` wrapper. `commitHash` is an optional short git SHA. ## The dependency graph in the `dependency` lens An `Edge` carries its weight as an ordinary numeric attribute (`dependencies`: how many individual code-level references the edge stands for), so it works with the existing edge-metric machinery, `attributeTypes` and descriptors. Two optional booleans describe the edge's place in the graph: - **`isCyclic`** — the edge takes part in a dependency cycle. - **`isPointingUpwards`** — the edge runs against the levelized flow, i.e. its target sits at the same level as or above its source. Both default to `false` and are **omitted when false**, so a producer that sets neither writes exactly what producers wrote before the fields existed. The four edge types are a pure function of the pair and are therefore **derived where they are consumed, never stored**: regular (neither), cyclic (`isCyclic`), container-level feedback (`isPointingUpwards`), leaf-level feedback (both). **Reading the graph.** Four rules a consumer relies on without the schema spelling them out: - **The flags describe the dependency graph only.** `edges` is shared with every other edge producer — `gitlogparser` writes `temporal_coupling` edges into it — and two producers' edges of one pair fold into one. `isCyclic` and `isPointingUpwards` are only meaningful on an edge that carries `dependencies`; on any other edge their absence means "not a dependency", not "not cyclic". - **No `nodes` entry means not in the graph.** A file without supported source code, or a folder holding none, has no entry; it does not sit at level 0. - **Levels are local.** A level orders a node among its siblings — the files and folders of one folder, the declarations and sub-namespaces of one namespace. Levels of nodes under different parents do not compare. - **A leaf edge weighs 1 unless its source is declared more than once in its file.** Declarations of one file that share a logical path are one leaf, and each of them that references the target counts once. **`nodes`** maps a node id to that node's `DependencyNode`, currently just its `level`: the node's levelization depth within its parent — 0 for a node that depends on nothing, *n* for one that depends only on nodes below level *n*. It is an object rather than a bare number so per-node facts (declaration kind, detected language) can be added later without a break, and it is optional so an unused lens slot stays `{}` — the form `carriesData()` treats as carrying nothing. Both halves are keyed by node id, so a filter that re-paths the tree re-keys `nodes` along with it (`DependencyLens.rekeyed`) while the edges are re-pathed by the restructuring itself. Merging two levelized projects takes the **higher** level of a node both describe; that is a conservative reconciliation, not a recomputation — levels are only meaningful within one producer's graph, so exact levels for a merged tree mean re-running the parser on it. ### The logical layer: `namespaces`, `leaves` and `leafEdges` `edges` and `nodes` are the graph as the *file tree* sees it. The three optional tables beside them are the same graph as the *code* declares it — packages and declarations rather than folders and files. - **`leaves`** maps a file node id to the declarations of that file, each under a key that is unique within the file. A leaf has no id of its own: it is addressed by that pair, and the key is opaque — a reader never parses or splits it. A leaf carries its `kind` and, each only when set, `name` (written only when it differs from the key), `language`, `namespace` (a key of `namespaces`), `parent` (the key of the declaration of the same file it is nested in) and `level`. - **`namespaces`** maps a declared package name to its `level` and its `parent`, the key of the package containing it; a top-level package has none. The hierarchy is `parent` alone, never the dots of a key. - **`leafEdges`** are the dependencies between declarations. `fromId` and `toId` are file node ids exactly as on an `Edge`, `fromLeaf` and `toLeaf` the keys within those files. Beside them sit the edge weight in `attributes`, the same two graph flags as an `Edge`, and `usage`: every way the source uses the target. `kind`, `usage` and `language` are open lower-case vocabularies, not enums, so a producer can add a value without a schema change. Known values: `kind` — `class`, `valueclass`, `interface`, `annotation`, `enum`, `function`, `variable`, `reexport`, `script`, `unknown`; `usage` — `usage`, `inheritance`, `implementation`, `instantiation`, `argument`, `return_value`, `constant_access`, `friend`, `part_of`; `language` — `java`, `kotlin`, `csharp`, `cpp`, `go`, `php`, `python`, `typescript`, `javascript`, `vue`, `delphi`, `rust`. A reader must not assume a producer fills in every usage, and `ccsh dependencyparser` currently reports more than `usage` for PHP only. **Why the file node id is the key.** A dotted logical path is the declared package in Java, Kotlin, C#, PHP and C++, but merely the re-encoded file path everywhere else. As a key it collides (`app.config.ts` beside `app_config.ts`), goes stale when a file moves, and makes the parent ambiguous (`user.ts` beside `user/User.ts`). The node id is the identity the file tree already has, and it follows the file through every filter. **`namespace` only where packages are real.** A leaf carries a `namespace`, and `namespaces` an entry for it, only where the language has packages apart from its files — for `ccsh dependencyparser` that is Java, Kotlin, C#, PHP and C++, and there only for a declaration that sits in one (a PHP or C++ file without a `namespace` declares none). TypeScript, JavaScript, Vue, Python, Go, Rust and Delphi leaves carry no `namespace`: their grouping is the file tree. A namespace entry requires a `level`, so a run with `--omit-graph-analysis` writes neither `namespaces` nor `namespace`. **A declaration split across files** — a partial class, the same package and name in two modules — is one leaf per file with the same `namespace` and key; a reader that wants the one class groups on that pair. An edge *into* it targets the first of those files, in both projections. **`parent` is reserved.** The schema lets a leaf name the declaration it is nested in, and such a leaf inherits its namespace through it. No producer emits it yet: `ccsh dependencyparser` writes a nested declaration as an ordinary leaf of its file, in the package of the declaration around it. Every table is optional and omitted when empty, so the lens of a file carrying only the physical projection reads as it did before they existed. `leafEdges` is a list of its own rather than a widened `Edge`, because the edge-metric machinery, `edgefilter` and the 3D map all read `edges`. It carries the two signals the file-collapsed `edges` cannot: a dependency between two declarations of the *same* file, and the kind of use each dependency is. **Merge and re-key.** `namespaces` merges max-wins on `level`, like `nodes`. `leaves` merge by file node id and key: the leaves of two inputs union, and for a pair both declare the first input's description stays, with a warning when the two differ. `leafEdges` fold by their four endpoint fields the way `edges` fold by two: the first weight wins, the flags OR, `usage` unions. Re-keying follows the tree: the outer keys of `leaves` and the `fromId`/`toId` of `leafEdges` move with their files, the leaves of a file that did not survive go with it, and with them every leaf edge that touched them and every namespace no surviving leaf lives in, directly or through `parent`. `merge --large`, which wraps each input in a folder, prefixes the namespace keys and the references to them with that folder, so two inputs declaring the same package stay apart in both projections. **The two projections can disagree, by design.** Folder levels are not a projection of namespace levels, so both trees are levelized separately. Where a language's packages and folders diverge — Java, C#, Go — or where two source roots share a package, the logical view merges what the physical view keeps apart. Both are correct for their own tree. ## Identity: the `id` and the canonical path A node's `id` is the first **16 lowercase hex chars** of `sha-256(type.name + canonicalPath)`, computed by the single `NodeId` owner in `model`. The identity is the node's **tree position and its `NodeType`**. The canonical path is the tree position: - segments are the names from the root's children down — **`root` is excluded**; - `/`-separated and prefixed with `/` (the root itself canonicalizes to `"/"`); - empty segments dropped, `.` removed, `..` collapsed; - **Unicode NFC-normalized** (macOS stores NFD, Linux NFC — without this the same file hashes differently across operating systems); - **case preserved**. The **type name is prepended** to the canonical path before hashing (`"File" + "/src/App.kt"`). This is what lets a File and a Folder legally share a name under one parent without their `id`s colliding; the preimage stays injective because a canonical path always begins with `/` and a `NodeType` name never contains `/`. The type is mixed in only at the hash, never into the canonical path itself, which also renders edge-endpoint strings and error messages. `NodeId.fromEndpoint("/root/src/App.kt")` strips the synthetic `root` and applies the same rules; an endpoint carries no type on the wire, so it defaults to **`File`** (a producer whose edge targets a non-File node resolves that node's real type from the tree). An edge endpoint and the file node it points at therefore resolve to the same `id`. For example, the root hashes `Folder/` and a file at `/root/hello.ts` hashes `File/hello.ts`, not `File/root/hello.ts`. See the [NodeId tests](../analysis/model/src/test/kotlin/de/maibornwolff/codecharta/model/NodeIdTest.kt) for ID calculation examples and explicit checks that the synthetic `/root` prefix is excluded. **What the `id` can and cannot promise.** The canonicalizer removes *spurious* divergence (separator, root name, leading slash, `.`/`..`, Unicode form, trailing slash): the same tree position ⇒ the same `id` everywhere. It deliberately does **not** reconcile *semantic* divergence — a tool that genuinely roots the tree at a different depth gives a file a different logical path and therefore a different `id`. Aligning differently-rooted trees is the merge resolver's job, not the hash's. **`contentHash`** is the existing per-file checksum (`ChecksumCalculator`, XXHash64) that already backs the `--base-file` incremental feature. It is a *matching signal*, never the identity, so two files with identical content (e.g. duplicated `README`) keep distinct `id`s. ## Merge resolver Merge is a resolver, not positional name-walking. For each incoming leaf it tries, in order: 1. **exact `id`** (same tree position and type), 2. **unique content hash** (a rename: same `contentHash`, matched only if that hash is unique in the reference), 3. **longest path-suffix** (differently-rooted trees), 4. otherwise **keep + warn** (kept only with `-a`/`--add-missing`, else dropped with a warning). Ambiguous content or suffix matches are skipped, never guessed. The union (recursive) mode keeps the same-rooting union of all inputs. Each lens owns its own `merge()`, so attribute types/descriptors combine consistently regardless of which tool produced them. ## Converting and reading - `ccsh` emits 2.x only (currently 2.1) — there is no 1.5 writer. - Every command reads 2.x only. Feeding a legacy 1.x file to `merge`/`modify`/`edgefilter`/`inspect`/an importer reports that the file is legacy and points at `ccsh convert`. Only `ccsh convert` reads 1.x. - `ccsh convert [-o out]` upgrades a 1.x (or older 2.x) file to the current 2.x — the one on-ramp for legacy files. - `ccsh check ` validates either format (the everit schema still accepts both via `anyOf`; the 2.0 branch is strict — `apiVersion` major 2, exactly one root, no unknown keys). ## Versioning & compatibility 2.x is **downward-compatible and additive-only**: - **Readers accept any major-2 version**, not exactly `2.0`. `apiVersion` matches `^2\.\d+$` in the schema; the analysis reader and the viz both gate on the *major* being `2`. - **Minors may only add.** A new minor (`2.1`, `2.2`, …) may introduce **optional** fields. Existing fields are never removed, renamed, or repurposed, and their types don't change. So the newest tools can always read every older 2.x file (**downward compatible**). - **Not upward compatible — by design.** `additionalProperties: false` stays on every object, so an *older* tool meeting a *newer* file that uses a field it doesn't know cleanly **rejects** it rather than loading partial data. The fix is to update CodeCharta; there is no "load the newer file anyway" path. (A newer file that only bumped the version but added nothing still loads.) - **Breaking change ⇒ new major (`3.0`).** The day a field must be removed or repurposed, that is a `3.0`, which major-2 tools reject. Practical rule for contributors: to extend 2.x, add an **optional** field (or a whole new lens — the `lenses` object already preserves unknown lenses verbatim) and bump the minor; never touch the meaning of an existing field. `ccsh` writes `2.1`: the dependency lens's edge flags, `nodes` and logical tables are its additions over `2.0`. When you add a field, update all three schema copies (this file's schema, the viz-vendored `ccJson2Schema.json`, and the `ccsh check` `cc.json`) so `EveritValidatorTest` and the viz drift guard stay green. ## What left the format `blacklist` and `markedPackages` are visualization view state and are **not** in 2.0. `blacklist` remains on the analysis domain as a filter-time concept (MergeFilter dedup, StructureModifier and LargeMerge path rewrites); a project read from 2.0 carries an empty blacklist. ## Known limitations These are deliberate gaps — see `plans/2026-06-26-ccjson-2-deferred-gaps.md`: - **Cross-tool / cross-repo joins need `--leaf`.** The *default* merge is recursive/union, which matches purely by tree position and name — differently-rooted trees (e.g. a Sonar import vs a parser scan, or two repos) are placed side-by-side, not joined. The content-hash / longest-suffix reconciliation that aligns differently-rooted files lives only in the `--leaf` (overlay) strategy, and the content-hash bridge requires content-reading producers (UnifiedParser / RawTextParser). - **`blacklist` does not survive 1.5 → 2.0 conversion.** Converting a 1.5 file with a non-empty blacklist to 2.0 silently drops it (it is not on the 2.0 wire), with no path back. ## Where the wire shape lives (single source of truth) All wire/identity/merge logic lives once in `model`/`serialization`; every parser/importer/filter *calls* it and never re-implements it: - `NodeId` — the only builder of a canonical path or `id`. - `ChecksumCalculator` — the only content-hash routine. - `CcJsonV2` DTO + `ProjectToCcJsonV2Mapper` / `CcJsonV2ToProjectMapper` — the only code that knows the 2.0 wire shape. There is no 1.5 **writer**; legacy 1.x input is read only on the `ccsh convert` on-ramp and immediately upgraded to the domain model. - `MergeResolverStrategy` — the only place node matching happens. - `Lens.merge()` per lens — the only place a lens's data is combined.