# arlav/graphtope architecture

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

- Interactive diagram: https://gitdiagram.com/arlav/graphtope
- Repository: https://github.com/arlav/graphtope

## Overview

#### Purpose and Entry Points
Graphtope is a Python library for generating, rewriting, validating, and reversing building space-adjacency graphs before attaching geometry. The Dom Narkomfin grammar is the primary reference domain. Main programmatic entry points are `StateGraph` and grammar-production modules; exploration is demonstrated through `notebooks/01_graphtope.ipynb`.  
Paths: `graphtope/__init__.py`, `graphtope/model.py`, `graphtope/grammar_dnf.py`.

#### Typed Graph State and Invariants
The core state represents architectural spaces as typed, attributed nodes and horizontal/vertical adjacencies as directed, weighted edges. It owns graph construction, axiom creation, and well-formedness checks, making it the primary consistency boundary for every rewrite. Label vocabularies and lower-level topology support are separated from the state model.  
Paths: `graphtope/model.py`, `graphtope/alphabet.py`, `graphtope/_topo.py`.

#### Reversible Rewrite Foundation
Graph evolution is built from reversible atomic edits, then elevated into split/merge and broader composition verbs. This layer is the mutation boundary: named grammar productions should operate through these primitives rather than directly changing graph internals.  
Paths: `graphtope/atomic.py`, `graphtope/composite.py`, `graphtope/bridge.py`.

#### Production Rules and Derivation Execution
Typed subgraph matching and DPO-style rule definitions provide the generic production mechanism. The Narkomfin module encodes domain-specific productions over that mechanism, while the engine applies, replays, and inverts derivations. Parameters and reusable grammar-unit definitions support controlled variation.  
Paths: `graphtope/rules.py`, `graphtope/engine.py`, `graphtope/grammar_dnf.py`.

#### Hierarchical and Modular Building Assembly
The system supports refinement of higher-level nodes into sub-grammars and abstraction back upward. Separate graph blocks can be composed and connected through bridges; cross-level relations address dependencies across hierarchical levels. This creates a boundary between local unit grammars and whole-building assembly.  
Paths: `graphtope/hierarchy.py`, `graphtope/compose.py`, `graphtope/crosslevel.py`.

#### Generation, Steering, and Analysis
Generation creates candidate graph variants; steering constrains or directs those variants. Validity, comparison, metrics, reference matching, and topological views evaluate generated states and support selecting or diagnosing alternatives.  
Paths: `graphtope/generate.py`, `graphtope/steer.py`, `graphtope/metrics.py`.

#### Geometry, Exchange, and Runtime Boundary
Graph-first results are serialized as JSON and can be realized into geometry through a shape-interface boundary and TopologicPy-oriented modules. OBJ assets and exported graph sidecars demonstrate interchange outputs. Blender scripts import generated geometry, create `.blend` variants, and validate them; Blender is an external batch/runtime integration, not the core grammar runtime. Python 3.10+ and NetworkX are stated requirements.  
Paths: `graphtope/serialize.py`, `graphtope/realise.py`, `graphtope/shape_iface.py`; `blender/import_graphtope.py`, `notebooks/exports/variants_3d/`.

Main entry points: [`graphtope/model.py`](https://github.com/arlav/graphtope/blob/main/graphtope/model.py) (StateGraph), [`graphtope/atomic.py`](https://github.com/arlav/graphtope/blob/main/graphtope/atomic.py) (Atomic edits), [`graphtope/rules.py`](https://github.com/arlav/graphtope/blob/main/graphtope/rules.py) (Rule definitions), [`graphtope/realise.py`](https://github.com/arlav/graphtope/blob/main/graphtope/realise.py) (Geometry realization)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_state["Graph State"]
  node_state_graph[("StateGraph<br/>typed graph state<br/>[model.py]")]
  node_alphabet["Label vocabularies<br/>type definitions<br/>[alphabet.py]"]
  node_topology["Topology support<br/>graph utilities<br/>[_topo.py]"]
end

subgraph group_rewrite["Rewrite System"]
  node_atomic["Atomic edits<br/>reversible mutations<br/>[atomic.py]"]
  node_composite["Composite verbs<br/>split/merge operations<br/>[composite.py]"]
  node_bridge["Bridging edits<br/>graph connection operations<br/>[bridge.py]"]
  node_rules["Rule definitions<br/>DPO rule system<br/>[rules.py]"]
  node_engine["Derivation engine<br/>rewrite executor<br/>[engine.py]"]
  node_narkomfin["Dom Narkomfin grammar<br/>domain productions<br/>[grammar_dnf.py]"]
end

subgraph group_assembly["Assembly &amp; Search"]
  node_hierarchy["Hierarchy refinement<br/>subgrammar assembly<br/>[hierarchy.py]"]
  node_compose["Block composition<br/>modular assembly<br/>[compose.py]"]
  node_crosslevel["Cross-level relations<br/>hierarchy dependencies<br/>[crosslevel.py]"]
  node_generation["Generation &amp; steering<br/>variant search<br/>[generate.py]"]
  node_metrics["Analysis &amp; validation<br/>evaluation<br/>[metrics.py]"]
end

subgraph group_exchange["Geometry &amp; Exchange"]
  node_serialization["JSON exchange<br/>graph serialization<br/>[serialize.py]"]
  node_realisation["Geometry realization<br/>shape adapter<br/>[realise.py]"]
  node_shape_interface["Shape interface<br/>geometry boundary<br/>[shape_iface.py]"]
  node_blender{{"Blender batch integration<br/>external runtime"}}
end

node_api["Library API<br/>Python package<br/>[__init__.py]"]
node_notebook["Exploration notebook<br/>interactive example<br/>[01_graphtope.ipynb]"]

node_api -->|"exports"| node_state_graph
node_notebook -->|"uses"| node_api
node_alphabet -->|"types nodes"| node_state_graph
node_topology -->|"supports"| node_state_graph
node_state_graph -->|"mutation target"| node_atomic
node_atomic -->|"builds"| node_composite
node_atomic -->|"builds"| node_bridge
node_composite -->|"used by productions"| node_rules
node_bridge -->|"connects blocks"| node_compose
node_rules -->|"generic mechanism for"| node_narkomfin
node_rules -->|"executed by"| node_engine
node_engine -->|"applies derivations"| node_state_graph
node_hierarchy -->|"assembles refined blocks"| node_compose
node_crosslevel -->|"links levels"| node_hierarchy
node_generation -->|"explores derivations"| node_engine
node_generation -->|"evaluates candidates"| node_metrics
node_state_graph -->|"evaluated as"| node_metrics
node_state_graph -->|"serializes"| node_serialization
node_serialization -->|"supplies graph results"| node_realisation
node_realisation -->|"uses"| node_shape_interface
node_realisation -.->|"exports geometry to"| node_blender

click node_api "https://github.com/arlav/graphtope/blob/main/graphtope/__init__.py"
click node_state_graph "https://github.com/arlav/graphtope/blob/main/graphtope/model.py"
click node_alphabet "https://github.com/arlav/graphtope/blob/main/graphtope/alphabet.py"
click node_topology "https://github.com/arlav/graphtope/blob/main/graphtope/_topo.py"
click node_atomic "https://github.com/arlav/graphtope/blob/main/graphtope/atomic.py"
click node_composite "https://github.com/arlav/graphtope/blob/main/graphtope/composite.py"
click node_bridge "https://github.com/arlav/graphtope/blob/main/graphtope/bridge.py"
click node_rules "https://github.com/arlav/graphtope/blob/main/graphtope/rules.py"
click node_engine "https://github.com/arlav/graphtope/blob/main/graphtope/engine.py"
click node_narkomfin "https://github.com/arlav/graphtope/blob/main/graphtope/grammar_dnf.py"
click node_hierarchy "https://github.com/arlav/graphtope/blob/main/graphtope/hierarchy.py"
click node_compose "https://github.com/arlav/graphtope/blob/main/graphtope/compose.py"
click node_crosslevel "https://github.com/arlav/graphtope/blob/main/graphtope/crosslevel.py"
click node_generation "https://github.com/arlav/graphtope/blob/main/graphtope/generate.py"
click node_metrics "https://github.com/arlav/graphtope/blob/main/graphtope/metrics.py"
click node_serialization "https://github.com/arlav/graphtope/blob/main/graphtope/serialize.py"
click node_realisation "https://github.com/arlav/graphtope/blob/main/graphtope/realise.py"
click node_shape_interface "https://github.com/arlav/graphtope/blob/main/graphtope/shape_iface.py"
click node_blender "https://github.com/arlav/graphtope/blob/main/blender/import_graphtope.py"
click node_notebook "https://github.com/arlav/graphtope/blob/main/notebooks/01_graphtope.ipynb"

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_state_graph,node_alphabet,node_topology toneBlue
class node_atomic,node_composite,node_bridge,node_rules,node_engine,node_narkomfin toneAmber
class node_hierarchy,node_compose,node_crosslevel,node_generation,node_metrics toneMint
class node_serialization,node_realisation,node_shape_interface,node_blender toneRose
class node_api,node_notebook toneNeutral
```

## Components

### Graph State

Typed architectural graph and invariant boundary.

- [StateGraph](https://github.com/arlav/graphtope/blob/main/graphtope/model.py): typed graph state · Owns axioms, construction, and well-formedness checks. · `graphtope/model.py`
- [Label vocabularies](https://github.com/arlav/graphtope/blob/main/graphtope/alphabet.py): type definitions · `graphtope/alphabet.py`
- [Topology support](https://github.com/arlav/graphtope/blob/main/graphtope/_topo.py): graph utilities · `graphtope/_topo.py`

### Rewrite System

Reversible edits and grammar execution.

- [Atomic edits](https://github.com/arlav/graphtope/blob/main/graphtope/atomic.py): reversible mutations · `graphtope/atomic.py`
- [Composite verbs](https://github.com/arlav/graphtope/blob/main/graphtope/composite.py): split/merge operations · `graphtope/composite.py`
- [Bridging edits](https://github.com/arlav/graphtope/blob/main/graphtope/bridge.py): graph connection operations · `graphtope/bridge.py`
- [Rule definitions](https://github.com/arlav/graphtope/blob/main/graphtope/rules.py): DPO rule system · Defines typed subgraph matches and productions. · `graphtope/rules.py`
- [Derivation engine](https://github.com/arlav/graphtope/blob/main/graphtope/engine.py): rewrite executor · Applies, replays, and inverts derivations. · `graphtope/engine.py`
- [Dom Narkomfin grammar](https://github.com/arlav/graphtope/blob/main/graphtope/grammar_dnf.py): domain productions · `graphtope/grammar_dnf.py`

### Assembly & Search

Hierarchical composition and candidate exploration.

- [Hierarchy refinement](https://github.com/arlav/graphtope/blob/main/graphtope/hierarchy.py): subgrammar assembly · Refines nodes into subgrammars and abstracts them back. · `graphtope/hierarchy.py`
- [Block composition](https://github.com/arlav/graphtope/blob/main/graphtope/compose.py): modular assembly · `graphtope/compose.py`
- [Cross-level relations](https://github.com/arlav/graphtope/blob/main/graphtope/crosslevel.py): hierarchy dependencies · `graphtope/crosslevel.py`
- [Generation & steering](https://github.com/arlav/graphtope/blob/main/graphtope/generate.py): variant search · Creates candidates and directs their evolution. · `graphtope/generate.py`
- [Analysis & validation](https://github.com/arlav/graphtope/blob/main/graphtope/metrics.py): evaluation · Compares, measures, validates, and diagnoses states. · `graphtope/metrics.py`

### Geometry & Exchange

Serialization and external geometry realization.

- [JSON exchange](https://github.com/arlav/graphtope/blob/main/graphtope/serialize.py): graph serialization · `graphtope/serialize.py`
- [Geometry realization](https://github.com/arlav/graphtope/blob/main/graphtope/realise.py): shape adapter · Converts graph-first results through a shape interface. · `graphtope/realise.py`
- [Shape interface](https://github.com/arlav/graphtope/blob/main/graphtope/shape_iface.py): geometry boundary · Decouples grammar runtime from TopologicPy-oriented geometry. · `graphtope/shape_iface.py`
- [Blender batch integration](https://github.com/arlav/graphtope/blob/main/blender/import_graphtope.py): external runtime · Imports generated geometry and validates .blend variants. · `blender/import_graphtope.py`

### Other components

- [Library API](https://github.com/arlav/graphtope/blob/main/graphtope/__init__.py): Python package · `graphtope/__init__.py`
- [Exploration notebook](https://github.com/arlav/graphtope/blob/main/notebooks/01_graphtope.ipynb): interactive example · `notebooks/01_graphtope.ipynb`

## Connections

- Library API → StateGraph: exports
- Exploration notebook → Library API: uses
- Label vocabularies → StateGraph: types nodes
- Topology support → StateGraph: supports
- StateGraph → Atomic edits: mutation target
- Atomic edits → Composite verbs: builds
- Atomic edits → Bridging edits: builds
- Composite verbs → Rule definitions: used by productions
- Bridging edits → Block composition: connects blocks
- Rule definitions → Dom Narkomfin grammar: generic mechanism for
- Rule definitions → Derivation engine: executed by
- Derivation engine → StateGraph: applies derivations
- Hierarchy refinement → Block composition: assembles refined blocks
- Cross-level relations → Hierarchy refinement: links levels
- Generation & steering → Derivation engine: explores derivations
- Generation & steering → Analysis & validation: evaluates candidates
- StateGraph → Analysis & validation: evaluated as
- StateGraph → JSON exchange: serializes
- JSON exchange → Geometry realization: supplies graph results
- Geometry realization → Shape interface: uses
- Geometry realization → Blender batch integration: exports geometry to
