architecture.py¶
clew/wiki/architecture.py
The Architecture tab: C4's four levels, derived from the index (round 5, P5.6).
architecture_html
str clew.wiki.architecture.architecture_html(str title, dict graph, list[Entry] entries)
The four levels' HTML.
Called by architecture_page
Tested by 7 tests
test_a_long_component_name_is_never_cut, test_a_main_is_named_by_its_file_not_main, test_code_level_links_down_to_the_map, test_components_are_the_blocks_declared_and_inferred_apart, test_containers_are_the_runnable_entry_points_said_to_be_derived, test_context_is_the_system_its_actors_and_its_external_systems, test_tooling_entry_points_are_listed_not_drawn_as_containers
Calls _code, _components, _containers, _context, _section
Source · 15 lines
def architecture_html(title: str, graph: dict, entries: list[Entry]) -> str:
"""@brief L1 → L4, a section each. @return HTML."""
comps = graph.get("components") or []
first = [c for c in comps if not c.get("vendor")]
vendor = [c for c in comps if c.get("vendor")]
return "".join(
(
_section(1, "Context", _context(title, entries, vendor)),
_section(2, "Containers", _containers(title, entries)),
_section(3, "Components", _components(first, graph.get("links") or [])),
_section(4, "Code", _code()),
)
)
Activity · 4 steps
Requirements
architecture_page
str clew.wiki.architecture.architecture_page(str title, dict graph, list[Entry] entries, Path source)
Write the Architecture page.
Source · 17 lines
def architecture_page(title: str, graph: dict, entries: list[Entry], source: Path) -> str:
"""@brief Write architecture.md. @return Page name."""
lines = [
"# Architecture",
"",
"The system at C4's four levels (S. Brown's C4 model), each drawn from the index. Anything "
"C4 asks for that the index cannot show is left out and named as missing, not guessed.",
"",
"```{raw} html",
architecture_html(title, graph, entries),
"```",
"",
]
(Path(source) / "architecture.md").write_text("\n".join(lines), encoding="utf-8")
return "architecture"