Canonical Model as Single Source of Truth

When a system must produce multiple visual representations of the same architecture, build a single normalized graph model and derive all outputs from it. Renderers that read the same model cannot drift from each other; renderers that maintain their own state always will.

Tags

Canonical Model as Single Source of Truth

The Lesson

When a system must produce multiple visual representations of the same architecture, build a single normalized graph model and derive all outputs from it. Renderers that read the same model cannot drift from each other; renderers that maintain their own state always will.

Context

An architecture visualization platform needed to produce Mermaid diagrams (for markdown embedding), Graphviz DOT (for dense dependency graphs), and React Flow interactive views — all depicting the same enterprise system with 83 entities and 83 relationships across 21 entity types. The system also needed to support regeneration as source documents evolved, meaning outputs could never be hand-edited.

What Happened

  1. Phase 1 built a Pydantic-based canonical knowledge model: Entity (with typed IDs, properties, tags), Relationship (with typed edges and metadata), and KnowledgeGraph (with add/remove/query helpers). This was the foundation — no rendering existed yet.
  2. Phase 2 populated the model with a real-world enterprise architecture (six-layer GTM system) as YAML files. The model was validated by loading it through the schema and running 37 graph-query tests.
  3. Phase 3 built a Mermaid renderer. It consumed KnowledgeGraph + DiagramConfig and emitted Mermaid syntax. The renderer never touched storage directly.
  4. Phase 6 added a Graphviz renderer and React Flow frontend. Both consumed the same KnowledgeGraph through the same Renderer ABC and filter_graph helper. The Graphviz renderer was written in under an hour because the model, filtering, and grouping logic already existed.
  5. Adding the format query parameter to the API was a 30-line change — the endpoint just picked a different renderer instance. No data transformation was needed.

Key Insights

Applicability

This pattern applies to any system that produces multiple representations of the same data: documentation generators, API schema tools (OpenAPI → client SDKs → docs), dashboard systems, or reporting pipelines. It does NOT apply when the representations are fundamentally different data (e.g., a user profile page vs. an analytics dashboard — those are different views of different models, not the same model rendered differently).

Related Lessons

Related Lessons