13. Garden Map
codeknife map runs the static suite and writes one self-contained HTML file that shows your modules, their import edges, per-file metrics, clone clusters and findings. Use it to browse a codebase visually, to show where layer violations and cycles sit, or to preview what a proposed arch.toml would fix or break.
Example
Section titled “Example”The demo repository has three Python modules. domain/orders.py imports infra/repo.py, and app/main.py imports both. Its arch.toml forbids domain/** from importing infra/**.
codeknife map --no-cache --format humannote: no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xmlnote: analyzed 1 commit(s) over the last 90 day(s)note: generated Garden Map at map-demo/codeknife-map.html (3 module(s), 3 edge(s), 1 red arrow(s))codeknife map: PASS (3 files, 0 errors, 0 warnings, 0 info, 16ms)The file is written to codeknife-map.html in the analysis root. Open it in a browser. The 1 red arrow(s) is the domain.orders -> infra.repo edge that breaks the deny rule.
| Flag | Default | Effect |
|---|---|---|
--out <OUT> |
codeknife-map.html |
Output path. A relative path is resolved against --path, not the current directory. Missing parent directories are created. An existing file is overwritten. |
--proposal <PROPOSAL> |
none | A second arch.toml to compare against the current one. A relative path is resolved against the current directory. See Comparing a proposed arch.toml. |
--changed, --since |
off | Scope the findings that feed the map. All files and modules still appear. |
--strict |
off | Stricter thresholds for the findings that feed the map. |
--no-cache |
off | Do not write .codeknife/ files. The map file is still written. |
--path, --format, --max-items |
Global flags. See CLI Reference. |
What is in the file
Section titled “What is in the file”Self-contained, no network
Section titled “Self-contained, no network”The HTML file is built from a template compiled into the binary. The template has one inline <style> block and one inline <script> block. It has no src or href attributes, no stylesheet imports and no fetch calls. The only absolute URL in it is the SVG namespace string http://www.w3.org/2000/svg, which the script passes to createElementNS and the browser does not fetch. Arrowheads are referenced with in-page url(#...) fragments. The analysis data is embedded in the script as a JSON object assigned to const DATA.
Before embedding, every </ in the JSON is replaced with <\/, so finding text that contains </script> cannot end the script block. The page inserts all data with textContent, so finding messages are shown as text, not parsed as HTML.
Header
Section titled “Header”The header shows the title CodeKnife Garden Map, the repository name (the analysis root’s directory name), and a row of KPI boxes:
| KPI | Value | Box class |
|---|---|---|
| Health | health_score with one decimal, and health_grade |
ok at 85 or more, warn at 70 or more, err below 70 |
| Files | total_files |
none |
| Functions | total_functions |
none |
| Errors | errors |
err when above 0, else ok |
| Warnings | warnings |
warn when above 0, else ok |
| Cycles | number of nodes with cycles: true |
err when above 0, else ok |
| Red Arrows | number of edges with a violated_rule or in_cycle: true |
err when above 0, else ok |
| Proposal Resolved | proposal.resolved_violations (only with --proposal) |
ok |
| Proposal New | proposal.new_violations (only with --proposal) |
err when above 0, else ok |
The err, warn and ok classes colour the value red (#f85149), yellow (#d29922) and green (#3fb950).
Toolbar
Section titled “Toolbar”- Three tabs: Module Graph, File Heatmap and Clone Clusters.
- A search box. It filters graph nodes by module id or label, heatmap tiles by file path or module id, and clone clusters by signature or location. Matching is case-insensitive substring matching.
- A Violations / Cycles only checkbox. In the graph it keeps nodes that are in a cycle or have findings, and edges that have a violated rule, are in a cycle, or have proposal status
new. In the heatmap it keeps files with at least one finding. It does not affect the clone table. - A heatmap metric selector, shown only on the heatmap tab, with five options: Max CRAP (
crap_max), Churn Commits (churn), Findings Count (findings_count), Suppressions (suppressions), Mutants Survived (mutants_survived).
Module Graph tab
Section titled “Module Graph tab”An SVG drawing in a 1000 by 700 view box. Each module is a circle, and each edge is a line with an arrowhead from the importing module to the imported one.
- Layout. Nodes are placed in order around an ellipse centred at (500, 350) with radii 380 and 250. With more than 16 visible nodes, every second node is placed on an inner ellipse at 65% of that size. The layout is computed from the node order, not from the edges.
- Node size. The radius is
10 + 0.8 × sqrt(loc), clamped between 12 and 34. A module with 0 lines uses 20 in place ofloc. - Node colour. A module in a cycle has a red outline. Otherwise, a module with findings has a yellow outline. Otherwise the outline is green. Layer violations do not change node colour.
- Edge colour. An edge whose
proposal_statusisresolvedis drawn as a green dashed line. An edge with aviolated_rule,in_cycle: true, orproposal_statusnewis drawn as a thicker red line. Other edges are grey. - Edge tooltip. Hovering an edge shows
from -> to (N imports), followed by| rulewhen the edge violates a rule. - Pan and zoom. Drag with the mouse to pan. The mouse wheel changes the zoom factor between 0.3 and 4.
- Legend. Healthy (green), Findings (yellow), Cycle / Violation (red), Proposal Resolved (green with a dashed border).
An edge is drawn only when both of its modules are visible after filtering.
File Heatmap tab
Section titled “File Heatmap tab”A grid of tiles, one per file, sorted by the selected metric, highest first. Each tile shows the path, line count, max CRAP (one decimal), churn commits and finding count. Its left border is:
- red when the selected metric is 20 or more, or the file has 5 or more findings
- yellow when the selected metric is above 0, or the file has any finding
- green otherwise
Clicking a tile opens the inspector for the file’s module.
Clone Clusters tab
Section titled “Clone Clusters tab”A table with columns Signature, Similarity (as a whole percentage), Copies (number of locations) and Locations. With no clusters, or none matching the search, it shows No clone clusters match the current filter. Clusters come from the Clones blade.
Inspector
Section titled “Inspector”The right-hand panel shows one module. It opens on the first module in the list when the page loads, and changes when you click a graph node or a heatmap tile. It shows:
- the module id, its directory, file count and whether it is in a cycle
- eight metric cards: LOC, Findings, Max CRAP, Churn, Depth Ratio, Suppressions, Mutants K/S, Clone Hits
- up to 15 top findings, each with severity, rule ID, file and line, message, and fix hint. Error findings have a red left border, info findings a blue one, and warnings a yellow one.
Payload reference
Section titled “Payload reference”The embedded DATA object has these fields. This excerpt is from the demo map generated with --proposal, trimmed to one node and one file:
{ "repo_name": "map-demo", "health_score": 78.7, "health_grade": "C+", "total_files": 3, "total_functions": 3, "errors": 1, "warnings": 0, "nodes": [ { "id": "domain.orders", "label": "orders", "dir_path": "domain", "loc": 6, "files": 1, "findings": 1, "max_crap": 0.0, "churn_commits": 1, "suppressions": 0, "mutants_killed": 0, "mutants_survived": 0, "clone_hits": 0, "depth_ratio": 1.0, "total_items": 1, "cycles": false, "top_findings": [ { "rule": "CK_ARCH_LAYER_VIOLATION", "severity": "error", "file": "domain/orders.py", "start_line": 1, "message": "forbidden dependency `domain/orders.py` -> `infra/repo.py` (domain must not import infrastructure)", "fix_hint": "Invert dependency or respect arch.toml rule (`domain/** -> infra/**`).", "impact_score": 85.0 } ] } ], "edges": [ { "from": "app.main", "to": "domain.orders", "count": 1, "violated_rule": null, "in_cycle": false, "proposal_status": "same" }, { "from": "app.main", "to": "infra.repo", "count": 1, "violated_rule": null, "in_cycle": false, "proposal_status": "new" }, { "from": "domain.orders", "to": "infra.repo", "count": 1, "violated_rule": "domain must not import infrastructure", "in_cycle": false, "proposal_status": "resolved" } ], "files": [ { "path": "domain/orders.py", "module": "domain.orders", "lines": 6, "crap_max": 0.0, "churn": 1, "suppressions": 0, "mutants_survived": 0, "findings_count": 1 } ], "clones": [], "proposal": { "resolved_violations": 1, "new_violations": 1 }}Top level
Section titled “Top level”| Field | Meaning |
|---|---|
repo_name |
Directory name of the analysis root, or repository if it has none. |
health_score, health_grade |
See Health score. |
total_files |
Files in the code model. |
total_functions |
Function records in the metrics IR. |
errors, warnings |
Error and warning findings from the static suite. The baseline is not applied. |
nodes |
One entry per module that contains at least one file, sorted by module id. |
edges |
One entry per pair of different modules with at least one import, sorted by from then to. |
files |
One tile per file in the code model. |
clones |
Clone clusters from the metrics IR. |
proposal |
null without --proposal; otherwise resolved_violations and new_violations. |
nodes[]
Section titled “nodes[]”| Field | Meaning |
|---|---|
id |
Module qualified name, for example domain.orders in Python or frontend/api in TypeScript. |
label |
The part of id after the last :, / or .. |
dir_path |
Directory of the module. |
loc |
Sum of total lines of the module’s files. |
files |
Number of files in the module. |
findings |
Number of findings located in the module’s files. |
max_crap |
Highest CRAP score of any function in the module, or 0 when none is available. |
churn_commits |
Highest commit count of any file in the module, from the Churn blade. |
suppressions |
Sum of suppression comments in the module’s files. |
mutants_killed, mutants_survived |
Always 0. See the caution below. |
clone_hits |
Number of clone-cluster locations that fall in the module’s files. |
depth_ratio |
Public items divided by all items in the module, or 0 when it has no items. |
total_items |
Number of items in the module. |
cycles |
Whether the module is part of any module dependency cycle. |
top_findings |
Up to 15 of the module’s findings, highest impact_score first, each with rule, severity, file, start_line, message, fix_hint and impact_score. |
edges[]
Section titled “edges[]”| Field | Meaning |
|---|---|
from, to |
Module ids. |
count |
Number of import records in the code model from from to to. |
violated_rule |
The reason text of the first rule in the current arch.toml that this edge breaks, or null. |
in_cycle |
true when both modules are in a module dependency cycle. They do not have to be in the same cycle. |
proposal_status |
null without --proposal; otherwise resolved, new or same. |
files[]
Section titled “files[]”| Field | Meaning |
|---|---|
path |
File path relative to the analysis root. |
module |
Module id of the file. |
lines |
Total lines. |
crap_max |
Highest CRAP score of any function in the file, or 0. |
churn |
Commits in the churn window that touched the file. |
suppressions |
Suppression comments in the file. |
mutants_survived |
Always 0. |
findings_count |
Findings located in the file. |
clones[]
Section titled “clones[]”Each entry has signature, similarity (0 to 1) and locations (strings whose part before the first : is a file path).
How edges and violations are computed
Section titled “How edges and violations are computed”Edges come from the import statements in the code model. Imports within one module are skipped. For each pair of modules, CodeKnife counts the imports and checks one representative file pair against arch.toml: the importing file of the first import seen, and the first file of the imported module. The edge’s violated_rule is the result of that one check, so a module pair whose imports come from several files is judged by its first import only.
The rules are the [[deny]], [[allow_only]] and private_internals rules described on Architecture. The current rules are read from arch.toml in the analysis root. The --layers flag of codeknife arch has no effect on the map.
Comparing a proposed arch.toml
Section titled “Comparing a proposed arch.toml”With --proposal, every edge is checked against both the current arch.toml and the proposed file:
| Current | Proposed | proposal_status |
Counted as |
|---|---|---|---|
| violates | passes | resolved |
resolved violation |
| passes | violates | new |
new violation |
| same result | same result | same |
not counted |
Without an arch.toml in the root, every edge passes under the current rules.
The demo’s proposal.toml drops the domain rule and forbids app/** from importing infra/**:
[[deny]]from = "app/**"to = "infra/**"reason = "app goes through the domain layer"codeknife map --no-cache --proposal proposal.toml --out out/proposal-map.html --format humannote: no coverage file found (running complexity-only mode); generate one with: pytest --cov --cov-report=xml:coverage.xmlnote: analyzed 1 commit(s) over the last 90 day(s)note: generated Garden Map at map-demo/out/proposal-map.html (3 module(s), 3 edge(s), 1 red arrow(s))note: proposal diff: -1 resolved violation(s), +1 new violation(s)codeknife map: PASS (3 files, 0 errors, 0 warnings, 0 info, 18ms)The red arrow count in the notes, like the Red Arrows KPI, counts only current violations and cycle edges. A new edge is drawn red in the graph but is not included in that count.
Comparison works on edges only. The proposal does not change which findings appear, and CK_ARCH_* findings in the map still come from the current arch.toml.
Health score
Section titled “Health score”The map computes its own score from the finding counts and total lines. It is separate from the Health Scorecard.
kloc = max(total lines / 1000, 1)pts = 14 × errors + 4.5 × warnings + 0.4 × infoscore = 100 − (pts / kloc × 1.2 + errors / sqrt(kloc) × 4.5)The score is clamped to 0 to 100 and rounded to one decimal. When there is at least one error, it is capped at 89.9. Grades:
| Score at least | Grade |
|---|---|
| 97 | A+ |
| 93 | A |
| 90 | A- |
| 87 | B+ |
| 83 | B |
| 80 | B- |
| 75 | C+ |
| 70 | C |
| 60 | D |
| below 60 | F |
In the demo, 1 error in 18 lines gives 100 − (14 × 1.2 + 1 × 4.5) = 78.7, grade C+.
File size
Section titled “File size”The template is 19,766 bytes. The JSON payload is added on a single line, so the output has the same number of lines as the template. There is no size limit in the code.
| Repository | Files | Modules | Edges | Output size |
|---|---|---|---|---|
| three-module demo | 3 | 3 | 3 | 21,803 bytes |
| CodeKnife’s own source at v0.2.0 | 156 | 156 | 309 | 149,103 bytes |
The CodeKnife run took 0.93 seconds of wall time, including the full static suite.
The map from check --tier full
Section titled “The map from check --tier full”codeknife check --tier full also writes a map after mutation testing:
- With
--map-out <PATH>, it writes there. A relative path is resolved against--path. - Without
--map-out, it writes.codeknife/map.html. - With
--no-cacheand no--map-out, it writes nothing and adds the note--no-cache skipped default .codeknife/map.html write.
The note on success reads, for example:
NOTE wrote interactive map map-demo/.codeknife/map.html (3 nodes, 3 edges, 1 red arrows)This map never has a proposal. Because it is generated after mutation testing, its findings include CK_MUTATE_* findings. See The Check Gate and Mutation Testing.
The map blade emits no rule IDs. It shows findings from the other blades.
Errors and exit codes
Section titled “Errors and exit codes”| Code | Meaning |
|---|---|
0 |
The map was written. This is the result whatever the findings are. |
2 |
The command failed. |
Examples of failures that exit with 2:
codeknife error: reading proposal.toml: No such file or directory (os error 2)codeknife error: parsing arch.toml: TOML parse error at line 1, column 8 |1 | deny = 3 | ^invalid type: integer `3`, expected a sequenceThe second message came from an invalid --proposal file named bad.toml. The error says arch.toml for any proposal file.
Also available via
Section titled “Also available via”There is no MCP tool for the map. codeknife check --tier full writes one as described above.