# p229279-cmyk/grem4 architecture

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

- Interactive diagram: https://gitdiagram.com/p229279-cmyk/grem4
- Repository: https://github.com/p229279-cmyk/grem4

## Overview

GREM 4 supports natural-language editing of OpenDRIVE road maps. A user’s intent is interpreted as a change request, grounded against map knowledge, and passed through planning, application, verification, and response; the system’s domain logic determines values and verdicts. The graph also preserves the map import/IR, geometry and relationship-query capabilities, and the separate model-run harness. The README documents the product workflow and major capabilities; some internal stage-to-stage calls are not shown in the excerpts, so those links are dashed and unevidenced.

Main entry points: [`ir`](https://github.com/p229279-cmyk/grem4/tree/main/ir) (Nine-shelf IR), [`harness/loop.py`](https://github.com/p229279-cmyk/grem4/blob/main/harness/loop.py) (Model harness), [`relations/engine.py`](https://github.com/p229279-cmyk/grem4/blob/main/relations/engine.py) (Relation engine), [`pipeline/understand`](https://github.com/p229279-cmyk/grem4/tree/main/pipeline/understand) (Intent understanding)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_map["Map knowledge"]
  node_opendrive["OpenDRIVE door"]
  node_facts["Fact rows<br/>[row.py]"]
  node_ir[("Nine-shelf IR")]
end

subgraph group_science["Map science"]
  node_geometry["Road geometry"]
  node_relations["Relation engine<br/>[engine.py]"]
  node_quantity["Quantity resolution<br/>[quantity.py]"]
  node_selection["Map selection<br/>[select.py]"]
  node_suites["Proof suites"]
end

subgraph group_workflow["Editing workflow"]
  node_capability["Change capability<br/>[capability.py]"]
  node_request["Change request<br/>[request.py]"]
  node_understand["Intent understanding"]
  node_ground["Request grounding<br/>[ground.py]"]
  node_plan["Change planning<br/>[plan.py]"]
  node_apply["Change application<br/>[apply.py]"]
  node_verify["Change verification<br/>[verify.py]"]
  node_respond["User response<br/>[respond.py]"]
end

subgraph group_assistant["Assistant runtime"]
  node_window["Map context tools<br/>[tools.py]"]
  node_harness["Model harness<br/>[loop.py]"]
end

subgraph group_legacy["Editing tools"]
  node_edit["Frozen edit tool<br/>[session.py]"]
end

node_user(("Map editor"))
node_provider["Model provider"]

node_user -->|"states intent"| node_understand
node_opendrive -->|"hands over facts"| node_facts
node_facts -->|"builds shelves"| node_ir
node_understand -.->|"forms request"| node_request
node_request -.->|"grounds intent"| node_ground
node_ground -.->|"plans change"| node_plan
node_plan -.->|"applies change"| node_apply
node_apply -.->|"checks result"| node_verify
node_verify -.->|"reports verdict"| node_respond
node_capability -.->|"defines vocabulary"| node_understand
node_ir -->|"answers questions"| node_relations
node_relations -.->|"resolves measures"| node_quantity
node_ir -.->|"supplies map context"| node_window
node_user -.->|"starts assistant run"| node_harness
node_harness -.->|"requests completion"| node_provider
node_harness -.->|"offers tools"| node_window
node_edit -->|"asks map query"| node_relations
node_ir -.->|"supports map science"| node_geometry

click node_opendrive "https://github.com/p229279-cmyk/grem4/tree/main/doors/opendrive"
click node_facts "https://github.com/p229279-cmyk/grem4/blob/main/contract/row.py"
click node_ir "https://github.com/p229279-cmyk/grem4/tree/main/ir"
click node_geometry "https://github.com/p229279-cmyk/grem4/tree/main/geometry"
click node_relations "https://github.com/p229279-cmyk/grem4/blob/main/relations/engine.py"
click node_capability "https://github.com/p229279-cmyk/grem4/blob/main/change/capability.py"
click node_request "https://github.com/p229279-cmyk/grem4/blob/main/change/request.py"
click node_understand "https://github.com/p229279-cmyk/grem4/tree/main/pipeline/understand"
click node_ground "https://github.com/p229279-cmyk/grem4/blob/main/pipeline/resolve/ground.py"
click node_plan "https://github.com/p229279-cmyk/grem4/blob/main/pipeline/plan/plan.py"
click node_apply "https://github.com/p229279-cmyk/grem4/blob/main/pipeline/apply/apply.py"
click node_verify "https://github.com/p229279-cmyk/grem4/blob/main/pipeline/verify/verify.py"
click node_respond "https://github.com/p229279-cmyk/grem4/blob/main/pipeline/respond/respond.py"
click node_quantity "https://github.com/p229279-cmyk/grem4/blob/main/shared/quantity.py"
click node_selection "https://github.com/p229279-cmyk/grem4/blob/main/shared/select.py"
click node_window "https://github.com/p229279-cmyk/grem4/blob/main/window/tools.py"
click node_harness "https://github.com/p229279-cmyk/grem4/blob/main/harness/loop.py"
click node_edit "https://github.com/p229279-cmyk/grem4/blob/main/edit/session.py"
click node_suites "https://github.com/p229279-cmyk/grem4/tree/main/suites"

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_opendrive,node_facts,node_ir toneBlue
class node_geometry,node_relations,node_quantity,node_selection,node_suites toneAmber
class node_capability,node_request,node_understand,node_ground,node_plan,node_apply,node_verify,node_respond toneMint
class node_window,node_harness toneRose
class node_edit,node_user,node_provider toneIndigo
```

## Components

### Map knowledge

- [OpenDRIVE door](https://github.com/p229279-cmyk/grem4/tree/main/doors/opendrive): `doors/opendrive`
- [Fact rows](https://github.com/p229279-cmyk/grem4/blob/main/contract/row.py): `contract/row.py`
- [Nine-shelf IR](https://github.com/p229279-cmyk/grem4/tree/main/ir): `ir`

### Map science

- [Road geometry](https://github.com/p229279-cmyk/grem4/tree/main/geometry): `geometry`
- [Relation engine](https://github.com/p229279-cmyk/grem4/blob/main/relations/engine.py): `relations/engine.py`
- [Quantity resolution](https://github.com/p229279-cmyk/grem4/blob/main/shared/quantity.py): `shared/quantity.py`
- [Map selection](https://github.com/p229279-cmyk/grem4/blob/main/shared/select.py): `shared/select.py`
- [Proof suites](https://github.com/p229279-cmyk/grem4/tree/main/suites): `suites`

### Editing workflow

- [Change capability](https://github.com/p229279-cmyk/grem4/blob/main/change/capability.py): `change/capability.py`
- [Change request](https://github.com/p229279-cmyk/grem4/blob/main/change/request.py): `change/request.py`
- [Intent understanding](https://github.com/p229279-cmyk/grem4/tree/main/pipeline/understand): `pipeline/understand`
- [Request grounding](https://github.com/p229279-cmyk/grem4/blob/main/pipeline/resolve/ground.py): `pipeline/resolve/ground.py`
- [Change planning](https://github.com/p229279-cmyk/grem4/blob/main/pipeline/plan/plan.py): `pipeline/plan/plan.py`
- [Change application](https://github.com/p229279-cmyk/grem4/blob/main/pipeline/apply/apply.py): `pipeline/apply/apply.py`
- [Change verification](https://github.com/p229279-cmyk/grem4/blob/main/pipeline/verify/verify.py): `pipeline/verify/verify.py`
- [User response](https://github.com/p229279-cmyk/grem4/blob/main/pipeline/respond/respond.py): `pipeline/respond/respond.py`

### Assistant runtime

- [Map context tools](https://github.com/p229279-cmyk/grem4/blob/main/window/tools.py): `window/tools.py`
- [Model harness](https://github.com/p229279-cmyk/grem4/blob/main/harness/loop.py): `harness/loop.py`

### Editing tools

- [Frozen edit tool](https://github.com/p229279-cmyk/grem4/blob/main/edit/session.py): `edit/session.py`

### Other components

- **Map editor**
- **Model provider**

## Connections

- Map editor → Intent understanding: states intent (evidence: `README.md`)
- OpenDRIVE door → Fact rows: hands over facts (evidence: `contract/row.py`)
- Fact rows → Nine-shelf IR: builds shelves (evidence: `contract/row.py`)
- Intent understanding → Change request: forms request
- Change request → Request grounding: grounds intent
- Request grounding → Change planning: plans change
- Change planning → Change application: applies change
- Change application → Change verification: checks result
- Change verification → User response: reports verdict
- Change capability → Intent understanding: defines vocabulary
- Nine-shelf IR → Relation engine: answers questions (evidence: `relations/engine.py`)
- Relation engine → Quantity resolution: resolves measures
- Nine-shelf IR → Map context tools: supplies map context
- Map editor → Model harness: starts assistant run
- Model harness → Model provider: requests completion
- Model harness → Map context tools: offers tools
- Frozen edit tool → Relation engine: asks map query
- Nine-shelf IR → Road geometry: supports map science
