# CGEF import and merge

> Import external graph data in the Codeweb Graph Exchange Format and merge it with locally analyzed stores.

---

LLMS index: [llms.txt](/codeweb/llms.txt)

---

## Why CGEF {#why-cgef}

CGEF (Codeweb Graph Exchange Format) is the JSON format for graph data produced outside of codeweb — for example, call relationships of a private ERP system whose source cannot be scanned. Import it as a standalone store, merge it with local analysis, and trace chains across the boundary.

## Document structure {#document-structure}

A CGEF document is a JSON file with these top-level fields:

```json
{
  "format_version": 1,
  "metadata": {
    "source": "erp-system",
    "generated_at": "2026-04-28T10:00:00Z"
  },
  "node_schemas": {},
  "edge_schemas": {},
  "nodes": [],
  "edges": []
}
```

| Field | Required | Meaning |
| ----- | -------- | ------- |
| `format_version` | yes | Format version; currently `1` |
| `metadata` | yes | `source` identifier and ISO 8601 `generated_at` |
| `node_schemas` | no | Declarations for custom node types |
| `edge_schemas` | no | Declarations for custom edge types |
| `nodes` | yes | Node array (may be empty) |
| `edges` | yes | Edge array (may be empty) |

Standard node types cover all built-in codeweb objects (`procedure`, `function`, `table`, `view`, `mapped_statement`, `java_method`, `java_class`, `java_sql`, `package`, `trigger`, `type`, `sequence`, `index`, `materialized_view`, …). The full per-type key fields are specified in the [CGEF user guide](https://github.com/c2j/codeweb/blob/main/docs/cgef-user-guide.md) and the [JSON Schema](https://github.com/c2j/codeweb/blob/main/docs/cgef-schema.json).

## Custom types {#custom-types}

Node or edge types that have no built-in equivalent are declared in `node_schemas` / `edge_schemas` (display name, key fields, property definitions). Their edges import as `CustomEdge` and their nodes with tag `custom`, so they behave like first-class nodes in trace, impact, and export.

## Import {#import}

```bash
codeweb import --file enterprise-graph.json --output erp-store.bincode
codeweb import --file enterprise-graph.json --output erp.json --prefix "/opt/erp/src" --name "erp"
codeweb import --file broken.json --output erp.bincode --force
```

| Flag | Meaning |
| ---- | ------- |
| `--file` | CGEF JSON input |
| `--output` | Output store: `.bincode` or `.json` |
| `--prefix` | Path prefix prepended to all relative file paths |
| `--name` | Project name for the imported store |
| `--force` | Import even when validation or parse errors are found |

## Merge {#merge}

```bash
codeweb merge -o full-graph.bincode my-project.bincode erp-store.bincode
codeweb merge -o full-graph.bincode --name "combined" my-project.bincode erp-store.bincode
```

Merging deduplicates nodes and edges across stores, so the same table analyzed locally and imported via CGEF collapses into one node. The merged store behaves like any local store for `trace`, `serve`, and `export`.

## View the full guide {#view-the-full-guide}

The Chinese guide [docs/cgef-user-guide.md](https://github.com/c2j/codeweb/blob/main/docs/cgef-user-guide.md) walks through a complete worked example, including the OP Excel lineage converter (`lib/op-lineage.py`).

---

Backlinks:

- [CLI reference](/codeweb/docs/cli-reference/)
