# bruju/prec architecture

> Architecture diagram of the GitHub repository bruju/prec, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bruju/prec
- Repository: https://github.com/bruju/prec

## Overview

PREC converts property graphs into RDF, optionally applying a Turtle context to map graph labels and properties into domain vocabularies. Users can start from Neo4j, Gremlin, or exported JSON; the CLI and library build a PREC-0 intermediate graph, then apply PREC-C or PRSC rules and emit an RDF dataset. It also supports applying contexts to existing RDF and reversing PREC-0 or well-behaved PRSC output back to property graphs. Some subsystem details are represented by their exact source directories because their implementations were not excerpted.

Main entry points: [`src/cli_.ts`](https://github.com/bruju/prec/blob/master/src/cli_.ts) (CLI), [`src/prec-0/PGDefinitions.ts`](https://github.com/bruju/prec/blob/master/src/prec-0/PGDefinitions.ts) (PREC-0 model), [`src/prec/graph-builder.ts`](https://github.com/bruju/prec/blob/master/src/prec/graph-builder.ts) (PG graph builder), [`src/prec/apply-context.ts`](https://github.com/bruju/prec/blob/master/src/prec/apply-context.ts) (Apply context)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Graph ingestion"]
  node_cli["CLI<br/>[cli_.ts]"]
  node_cypher_adapter["Cypher adapter<br/>[from-cypher.js]"]
  node_gremlin_adapter["Gremlin adapter<br/>[from-gremlin.js]"]
  node_graph_builder["PG graph builder<br/>[graph-builder.ts]"]
end

subgraph group_rdf["RDF conversion"]
  node_pg_model["PREC-0 model<br/>[PGDefinitions.ts]"]
  node_dataset[("RDF dataset<br/>[index.ts]")]
  node_rdf_parse["RDF parsing<br/>[parsing.ts]"]
  node_prec_namespace["PREC vocabulary<br/>[PRECNamespace.ts]"]
  node_path_tools["RDF path utilities<br/>[path-travelling.ts]"]
  node_quad_star["RDF-star utilities<br/>[quad-star.ts]"]
end

subgraph group_contexts["Context mapping"]
  node_apply_context["Apply context<br/>[apply-context.ts]"]
  node_precc_context["PREC-C context<br/>[Context.ts]"]
  node_precc_rules["PREC-C rule processing<br/>[context-loader.ts]"]
  node_precc_stages["PREC-C mapping rules"]
  node_prsc_context["PRSC context<br/>[PrscContext.ts]"]
  node_prsc_rules["PRSC rules<br/>[PrscRule.ts]"]
  node_prsc_apply["Apply PRSC<br/>[index.ts]"]
  node_prsc_check["Well-behaved check"]
end

subgraph group_reverse["Reverse conversion"]
  node_prec0_reverse["PREC-0 reversion"]
  node_prsc_reverse["PRSC reversion<br/>[prsc-reversion.ts]"]
  node_cypher_output["Cypher output<br/>[from-cypher.js]"]
  node_gremlin_output["Gremlin output<br/>[from-gremlin.js]"]
end

node_user(("User"))
node_neo4j[("Neo4j source")]
node_gremlin[("Gremlin source")]
node_json["Exported PG JSON"]

node_user -->|"runs commands"| node_cli
node_neo4j -->|"provides graph"| node_cli
node_gremlin -->|"provides graph"| node_cli
node_json -->|"provides export"| node_cli
node_cli -->|"loads Cypher data"| node_cypher_adapter
node_cli -->|"loads Gremlin data"| node_gremlin_adapter
node_cli -->|"builds graph"| node_graph_builder
node_cypher_adapter -->|"represents graph"| node_pg_model
node_gremlin_adapter -->|"represents graph"| node_pg_model
node_graph_builder -->|"builds dataset"| node_dataset
node_graph_builder -->|"uses definitions"| node_pg_model
node_cli -->|"applies context"| node_apply_context
node_cli -->|"parses RDF"| node_rdf_parse
node_apply_context -->|"applies PREC-C"| node_precc_context
node_apply_context -->|"applies PRSC"| node_prsc_apply
node_precc_context -->|"configures rules"| node_precc_rules
node_precc_context -->|"uses rule stages"| node_precc_stages
node_prsc_apply -->|"builds context"| node_prsc_context
node_prsc_context -->|"uses rules"| node_prsc_rules
node_prsc_context -->|"follows graph paths"| node_path_tools
node_prsc_rules -->|"characterizes triples"| node_quad_star
node_prsc_check -->|"checks validity"| node_prsc_rules
node_dataset -->|"handles RDF-star"| node_quad_star
node_cli -->|"reverts PREC-0"| node_prec0_reverse
node_cli -->|"reverts PRSC"| node_prsc_reverse
node_prsc_reverse -->|"checks context"| node_prsc_check
node_cli -->|"prints Cypher"| node_cypher_output
node_cli -->|"populates Gremlin"| node_gremlin_output
node_prec_namespace -->|"defines terms"| node_pg_model

click node_cli "https://github.com/bruju/prec/blob/master/src/cli_.ts"
click node_cypher_adapter "https://github.com/bruju/prec/blob/master/src/prec-0/from-cypher.js"
click node_gremlin_adapter "https://github.com/bruju/prec/blob/master/src/prec-0/from-gremlin.js"
click node_graph_builder "https://github.com/bruju/prec/blob/master/src/prec/graph-builder.ts"
click node_pg_model "https://github.com/bruju/prec/blob/master/src/prec-0/PGDefinitions.ts"
click node_dataset "https://github.com/bruju/prec/blob/master/src/dataset/index.ts"
click node_rdf_parse "https://github.com/bruju/prec/blob/master/src/rdf/parsing.ts"
click node_prec_namespace "https://github.com/bruju/prec/blob/master/src/PRECNamespace.ts"
click node_apply_context "https://github.com/bruju/prec/blob/master/src/prec/apply-context.ts"
click node_precc_context "https://github.com/bruju/prec/blob/master/src/prec-c/Context.ts"
click node_precc_rules "https://github.com/bruju/prec/blob/master/src/prec-c/context-loader.ts"
click node_precc_stages "https://github.com/bruju/prec/tree/master/src/prec-c"
click node_prsc_context "https://github.com/bruju/prec/blob/master/src/prsc/PrscContext.ts"
click node_prsc_rules "https://github.com/bruju/prec/blob/master/src/prsc/PrscRule.ts"
click node_prsc_apply "https://github.com/bruju/prec/blob/master/src/prsc/index.ts"
click node_prsc_check "https://github.com/bruju/prec/blob/master/src/prsc/well-behaved-check.ts"
click node_prec0_reverse "https://github.com/bruju/prec/blob/master/src/prec-0/prec-0-reversion.ts"
click node_prsc_reverse "https://github.com/bruju/prec/blob/master/src/prsc/prsc-reversion.ts"
click node_cypher_output "https://github.com/bruju/prec/blob/master/src/prec-0/from-cypher.js"
click node_gremlin_output "https://github.com/bruju/prec/blob/master/src/prec-0/from-gremlin.js"
click node_path_tools "https://github.com/bruju/prec/blob/master/src/rdf/path-travelling.ts"
click node_quad_star "https://github.com/bruju/prec/blob/master/src/rdf/quad-star.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_cypher_adapter,node_gremlin_adapter,node_graph_builder,node_user toneBlue
class node_pg_model,node_dataset,node_rdf_parse,node_prec_namespace,node_path_tools,node_quad_star,node_neo4j,node_gremlin toneAmber
class node_apply_context,node_precc_context,node_precc_rules,node_precc_stages,node_prsc_context,node_prsc_rules,node_prsc_apply,node_prsc_check toneMint
class node_prec0_reverse,node_prsc_reverse,node_cypher_output,node_gremlin_output toneRose
class node_json toneIndigo
```

## Components

### Graph ingestion

- [CLI](https://github.com/bruju/prec/blob/master/src/cli_.ts): `src/cli_.ts`
- [Cypher adapter](https://github.com/bruju/prec/blob/master/src/prec-0/from-cypher.js): `src/prec-0/from-cypher.js`
- [Gremlin adapter](https://github.com/bruju/prec/blob/master/src/prec-0/from-gremlin.js): `src/prec-0/from-gremlin.js`
- [PG graph builder](https://github.com/bruju/prec/blob/master/src/prec/graph-builder.ts): `src/prec/graph-builder.ts`

### RDF conversion

- [PREC-0 model](https://github.com/bruju/prec/blob/master/src/prec-0/PGDefinitions.ts): `src/prec-0/PGDefinitions.ts`
- [RDF dataset](https://github.com/bruju/prec/blob/master/src/dataset/index.ts): `src/dataset/index.ts`
- [RDF parsing](https://github.com/bruju/prec/blob/master/src/rdf/parsing.ts): `src/rdf/parsing.ts`
- [PREC vocabulary](https://github.com/bruju/prec/blob/master/src/PRECNamespace.ts): `src/PRECNamespace.ts`
- [RDF path utilities](https://github.com/bruju/prec/blob/master/src/rdf/path-travelling.ts): `src/rdf/path-travelling.ts`
- [RDF-star utilities](https://github.com/bruju/prec/blob/master/src/rdf/quad-star.ts): `src/rdf/quad-star.ts`

### Context mapping

- [Apply context](https://github.com/bruju/prec/blob/master/src/prec/apply-context.ts): `src/prec/apply-context.ts`
- [PREC-C context](https://github.com/bruju/prec/blob/master/src/prec-c/Context.ts): `src/prec-c/Context.ts`
- [PREC-C rule processing](https://github.com/bruju/prec/blob/master/src/prec-c/context-loader.ts): `src/prec-c/context-loader.ts`
- [PREC-C mapping rules](https://github.com/bruju/prec/tree/master/src/prec-c): `src/prec-c`
- [PRSC context](https://github.com/bruju/prec/blob/master/src/prsc/PrscContext.ts): `src/prsc/PrscContext.ts`
- [PRSC rules](https://github.com/bruju/prec/blob/master/src/prsc/PrscRule.ts): `src/prsc/PrscRule.ts`
- [Apply PRSC](https://github.com/bruju/prec/blob/master/src/prsc/index.ts): `src/prsc/index.ts`
- [Well-behaved check](https://github.com/bruju/prec/blob/master/src/prsc/well-behaved-check.ts): `src/prsc/well-behaved-check.ts`

### Reverse conversion

- [PREC-0 reversion](https://github.com/bruju/prec/blob/master/src/prec-0/prec-0-reversion.ts): `src/prec-0/prec-0-reversion.ts`
- [PRSC reversion](https://github.com/bruju/prec/blob/master/src/prsc/prsc-reversion.ts): `src/prsc/prsc-reversion.ts`
- [Cypher output](https://github.com/bruju/prec/blob/master/src/prec-0/from-cypher.js): `src/prec-0/from-cypher.js`
- [Gremlin output](https://github.com/bruju/prec/blob/master/src/prec-0/from-gremlin.js): `src/prec-0/from-gremlin.js`

### Other components

- **User**
- **Neo4j source**
- **Gremlin source**
- **Exported PG JSON**

## Connections

- User → CLI: runs commands (evidence: `README.md`)
- Neo4j source → CLI: provides graph (evidence: `README.md`)
- Gremlin source → CLI: provides graph (evidence: `README.md`)
- Exported PG JSON → CLI: provides export (evidence: `README.md`)
- CLI → Cypher adapter: loads Cypher data (evidence: `src/cli_.ts`)
- CLI → Gremlin adapter: loads Gremlin data (evidence: `src/cli_.ts`)
- CLI → PG graph builder: builds graph (evidence: `src/cli_.ts`)
- Cypher adapter → PREC-0 model: represents graph
- Gremlin adapter → PREC-0 model: represents graph
- PG graph builder → RDF dataset: builds dataset (evidence: `src/prec/graph-builder.ts`)
- PG graph builder → PREC-0 model: uses definitions (evidence: `src/prec/graph-builder.ts`)
- CLI → Apply context: applies context (evidence: `src/cli_.ts`)
- CLI → RDF parsing: parses RDF (evidence: `src/cli_.ts`)
- Apply context → PREC-C context: applies PREC-C (evidence: `src/prec/apply-context.ts`)
- Apply context → Apply PRSC: applies PRSC (evidence: `src/prec/apply-context.ts`)
- PREC-C context → PREC-C rule processing: configures rules (evidence: `src/prec-c/Context.ts`)
- PREC-C context → PREC-C mapping rules: uses rule stages (evidence: `src/prec-c/Context.ts`)
- Apply PRSC → PRSC context: builds context (evidence: `src/prsc/index.ts`)
- PRSC context → PRSC rules: uses rules (evidence: `src/prsc/PrscContext.ts`)
- PRSC context → RDF path utilities: follows graph paths (evidence: `src/prsc/PrscContext.ts`)
- PRSC rules → RDF-star utilities: characterizes triples (evidence: `src/prsc/PrscRule.ts`)
- Well-behaved check → PRSC rules: checks validity (evidence: `src/prsc/well-behaved-check.ts`)
- RDF dataset → RDF-star utilities: handles RDF-star (evidence: `src/dataset/index.ts`)
- CLI → PREC-0 reversion: reverts PREC-0 (evidence: `src/cli_.ts`)
- CLI → PRSC reversion: reverts PRSC (evidence: `src/cli_.ts`)
- PRSC reversion → Well-behaved check: checks context (evidence: `src/prsc/prsc-reversion.ts`)
- CLI → Cypher output: prints Cypher (evidence: `README.md`)
- CLI → Gremlin output: populates Gremlin (evidence: `README.md`)
- PREC vocabulary → PREC-0 model: defines terms
