Docs / Diagram examples

Concept map of how git stores a project, drawn from Python

This page is for anyone who explains how things connect, such as the parts of a data model. Its concept map, drawn from a 34-line Python script, shows how git, a tool that keeps the history of a project's files, stores a project.

Updated

How git stores a project

How git stores a project. Drawn by open-diagram 0.6.2 from examples/concept_map.py: 0 layout problems. Source

The picture as text
How git stores a project

Blocks, left to right:
- Objects and how they connect (Each object is named by a hash of its contents): map: Branch points to Commit; Tag points to Commit; Commit follows Parent commit; Commit saves Tree; Tree lists file Blob; Tree lists folder Subfolder tree. example 'Example: one commit': Snapshot Tree 9c1e4a; Parent Commit 52f0b7; Message Fix sign-in on phones; Branch main points here

What does this concept map show?

Seven objects and six labelled lines, from branch to commit to tree. Git calls a file a blob, and a subfolder is a tree too. Each object is named by a hash of its contents, a short code worked out from the contents themselves. The card on the right is a worked example: one commit, with made-up values.

Which building blocks draw it?

"""A map of how git stores a project: its objects and how they point to each other, with one worked example.
Run: python3 examples/concept_map.py"""
import os

from open_diagram import Card, Diagram, Graph, Panel, Row

HERE = os.path.dirname(os.path.abspath(__file__))

MAP = Graph(
    nodes={"branch": "Branch", "tag": "Tag", "commit": "Commit", "parent": "Parent commit", "tree": "Tree",
           "blob": "Blob", "subtree": "Subfolder tree"},
    links=[("branch", "commit", "points to"), ("tag", "commit", "points to"), ("commit", "parent", "follows"),
           ("commit", "tree", "saves"), ("tree", "blob", "lists file"), ("tree", "subtree", "lists folder")],
    at={"branch": (0, 0), "commit": (1.5, 0), "tree": (3, 0), "blob": (4.5, 0), "tag": (0, 2),
        "parent": (1.5, 2), "subtree": (4.5, 2)},
)

EXAMPLE = Card("Example: one commit", [
    ("Snapshot", "Tree 9c1e4a"),
    ("Parent", "Commit 52f0b7"),
    ("Message", "Fix sign-in on phones"),
    ("Branch", "main points here"),
], intro="One commit, as git stores it:")


def build() -> Diagram:
    d = Diagram("How git stores a project", tag="EXAMPLE")
    d.add(Panel("Objects and how they connect", Row(MAP, EXAMPLE),
                sub="Each object is named by a hash of its contents"))
    return d


if __name__ == "__main__":
    build().save(os.path.join(HERE, "..", "docs", "images", "concept_map"))
  • Graph(nodes, links, at) draws the map. nodes gives each object a key and a label. links lists pairs, each with an optional label.
  • at places each node on a grid as (column, row). Columns are 132 px apart and rows 58 px, and fractions are allowed: 1.5 is halfway between columns 1 and 2.
  • Card(title, rows, intro=) draws the worked example as rows of names and values.
  • Row(MAP, EXAMPLE) puts the map and the card side by side in one Panel.

Lines in a Graph have no arrowheads, so the labels carry the meaning.

Can I write a concept map in JSON?

Yes. A panel's sections can contain a graph, a card and a row, with the same parts as in Python:

{
  "title": "How a library lends a book",
  "columns": [[{
    "title": "Things and how they connect",
    "sections": [{"row": [
      {"graph": {
        "nodes": {"member": "Member", "loan": "Loan", "copy": "Copy", "book": "Book"},
        "links": [["member", "loan", "takes out"], ["loan", "copy", "covers"], ["copy", "book", "is a copy of"]],
        "at": {"member": [0, 0], "loan": [1.5, 0], "copy": [1.5, 2], "book": [3, 2]}
      }},
      {"card": {"title": "Example: loan 3317", "rows": [["Member", "Card 0042"], ["Copy", "Shelf B, copy 2"], ["Due", "In 21 days"]]}}
    ]}]
  }]]
}
How a library lends a book

The check: 0 layout problems

What if two nodes are too close?

The check names the label and each node it touches. Move Loan from column 1.5 to 0.8 and "takes out" has no room:

{
  "title": "How a library lends a book",
  "columns": [[{
    "title": "Things and how they connect",
    "sections": [{"graph": {
      "nodes": {"member": "Member", "loan": "Loan", "copy": "Copy", "book": "Book"},
      "links": [["member", "loan", "takes out"], ["loan", "copy", "covers"], ["copy", "book", "is a copy of"]],
      "at": {"member": [0, 0], "loan": [0.8, 0], "copy": [1.5, 2], "book": [3, 2]}
    }}]
  }]]
}
How a library lends a book

The check: 2 layout problem(s)

graph: the label 'takes out' touches the node 'Member'
graph: the label 'takes out' touches the node 'Loan'

Spread the nodes in at, or shorten the label.

How do I make my own?

Copy examples/concept_map.py, or the JSON above, under your own name. Write your nodes and links, and give each node a place in at. Then install open-diagram with pip install open-diagram and run open-diagram check and open-diagram draw on the file.

See also