# simplyminimal/tailscale-network-topology-mapper architecture

> Architecture diagram of the GitHub repository simplyminimal/tailscale-network-topology-mapper, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-06-02). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/simplyminimal/tailscale-network-topology-mapper
- Repository: https://github.com/simplyminimal/tailscale-network-topology-mapper

## Overview

1. **Overall shape**
   - This repo is a **Python CLI app** that turns a Tailscale policy file into a **single self-contained interactive HTML topology map**.
   - The core runtime flow is: **policy input → parse/validate → build graph model → render HTML artifact**.

2. **Primary entry points**
   - `main.py` is the main command-line entry point for local use and packaged execution.
   - The project is also set up for distribution through PyPI and container execution, so the same core logic is reused whether you run it with `python3`, `uvx`, Docker, or automation.

3. **Policy ingestion boundary**
   - Input comes from either:
     - a **local `policy.hujson` / JSON file**, or
     - the **Tailscale API** when remote policy fetching is enabled.
   - `services/file_loader.py` handles local file access.
   - The readme and file layout indicate remote API support is a separate path, likely wrapped through service code rather than mixed into parsing logic.

4. **Validation boundary**
   - There are two validation modes:
     - **offline/local sanity validation** using repository code
     - **Tailscale API validation** using `TAILSCALE_API_KEY` and `TAILSCALE_TAILNET`
   - `services/policy_validator.py` is the validation boundary.
   - `security_utils.py` likely centralizes safe handling of secrets, API access, or policy-related checks.

5. **Parsing and policy normalization**
   - `policy_parser.py` is the key translation layer from HuJSON/JSON into internal structures.
   - The parser supports both **legacy ACL rules** and **modern Grant rules**, including protocol, via-routing, posture checks, and app-level controls.
   - `models/policy_data.py` is the canonical in-memory representation used after parsing; this is the main data contract between parsing, graph construction, and rendering.

6. **Graph construction**
   - `network_graph.py` appears to convert normalized policy data into the **network relationship graph** used for visualization.
   - This is where directional relationships, node types, and rule-derived metadata likely become graph nodes/edges.
   - The readme’s “shape-coded rule types” and “directional edges” are reflected here as the structural model feeding the UI.

7. **Rendering layer**
   - `renderer.py` produces the final HTML output, including the embedded interactive map.
   - The output artifact is `network_topology.html`, which is designed to be opened directly in a browser or hosted as a static file.
   - The renderer is responsible for turning graph data into the visual representation with search, highlighting, tooltips, and zoom behavior.

8. **Interactive UI behavior**
   - The generated HTML is not just a static image; it includes client-side interactions such as:
     - searchable/filterable nodes
     - hover tooltips with rule metadata
     - connected-node highlighting
     - zoom controls
     - draggable search UI
   - The tests (`test_renderer*`, `test_search_functionality.py`, `test_zoom_config.py`, `test_ui_bug_fixes.py`) suggest the UI behavior is a first-class part of the architecture, even though it is delivered as a generated artifact.

9. **Deployment and serving**
   - `Dockerfile`, `docker-compose.yml`, and `server/server.py` show two deployment modes:
     - generate the HTML locally and open it directly
     - run it in a container with a small server exposing the result on `localhost:8080`
   - The server component is a thin hosting boundary rather than the core application logic.

10. **Configuration and environment**
   - `config.py` holds repo-level settings such as the company domain default.
   - Environment variables are used for runtime configuration, especially for Tailscale API validation and remote policy retrieval.
   - This keeps the parsing/rendering pipeline independent from environment-specific credentials.

11. **Automation and CI**
   - `.github/workflows/tailscale.yml` is a sample automation path for regenerating the topology map when policy changes.
   - `.github/workflows/publish-pypi.yml` indicates the project is packaged and released as a Python distribution.
   - `scripts/validate-policy.sh` is a supporting operational script for policy checks.

12. **Quality and regression coverage**
   - The `tests/` directory is broad and feature-oriented, covering parser correctness, graph generation, renderer output, search behavior, zoom behavior, and regression fixes.
   - That test layout reflects the real subsystem boundaries: **input parsing**, **graph/model generation**, and **UI artifact correctness**.

13. **Useful diagram takeaway**
   - A good architecture diagram should show three main zones:
     - **Input/validation**: local file or Tailscale API, plus policy validation
     - **Core transformation pipeline**: parser → policy model → network graph
     - **Output/hosting**: HTML renderer, static artifact, optional container/server delivery
   - The most important external dependency is Tailscale itself, but only for optional validation and policy retrieval; the visualization pipeline is otherwise self-contained.

Main entry points: [`main.py`](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/main.py) (CLI Entry), [`services/policy_validator.py`](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/policy_validator.py) (Policy Validator), [`renderer.py`](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/renderer.py) (HTML Renderer), [`policy_parser.py`](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/policy_parser.py) (Policy Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_input["Input & Validation"]
  node_main["CLI Entry<br/>entrypoint<br/>[main.py]"]
  node_file_loader["File Loader<br/>io service<br/>[file_loader.py]"]
  node_policy_validator{{"Policy Validator<br/>validation service"}}
  node_security_utils{{"Security Utils<br/>security helpers<br/>[security_utils.py]"}}
  node_tailscale_api[("Tailscale API<br/>external api")]
  node_config["Config<br/>settings<br/>[config.py]"]
end

subgraph group_core["Core Pipeline"]
  node_policy_parser["Policy Parser<br/>[policy_parser.py]"]
  node_policy_data["Policy Model<br/>domain model<br/>[policy_data.py]"]
  node_network_graph{{"Graph Builder<br/>graph model<br/>[network_graph.py]"}}
  node_renderer["HTML Renderer<br/>[renderer.py]"]
end

subgraph group_output["Output & Serving"]
  node_network_topology["Topology HTML<br/>artifact"]
  node_server["Web Server<br/>hosting server<br/>[server.py]"]
end

subgraph group_ops["Automation & Delivery"]
  node_container["Container Wrapper<br/>deployment helper<br/>[container.py]"]
  node_dockerfile["Dockerfile<br/>container spec"]
  node_publish_workflow["PyPI Workflow<br/>ci workflow<br/>[publish-pypi.yml]"]
  node_tailscale_workflow["Topology Workflow<br/>ci workflow<br/>[tailscale.yml]"]
  node_validate_script["Validate Script<br/>ops script<br/>[validate-policy.sh]"]
end

subgraph group_quality["Quality & Regression"]
  node_tests["Test Suite<br/>tests"]
end

node_main -->|"load local policy"| node_file_loader
node_main -->|"validate policy"| node_policy_validator
node_main -->|"parse policy"| node_policy_parser
node_main -->|"render output"| node_renderer
node_main -->|"serve artifact"| node_server
node_file_loader -->|"raw policy"| node_policy_parser
node_policy_validator -->|"secure checks"| node_security_utils
node_policy_validator -->|"api validation"| node_tailscale_api
node_policy_parser -->|"normalize"| node_policy_data
node_policy_data -->|"policy model"| node_network_graph
node_network_graph -->|"graph data"| node_renderer
node_renderer -->|"generate html"| node_network_topology
node_server -->|"host html"| node_network_topology
node_container -->|"run server"| node_server
node_dockerfile -->|"build image"| node_container
node_publish_workflow -->|"package app"| node_main
node_tailscale_workflow -->|"validate policy"| node_policy_validator
node_tailscale_workflow -->|"regenerate map"| node_renderer
node_validate_script -->|"run checks"| node_policy_validator
node_tests -->|"parser tests"| node_policy_parser
node_tests -->|"graph tests"| node_network_graph
node_tests -->|"ui tests"| node_renderer
node_config -->|"runtime defaults"| node_main
node_config -->|"env config"| node_policy_validator

click node_main "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/main.py"
click node_file_loader "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/file_loader.py"
click node_policy_validator "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/policy_validator.py"
click node_security_utils "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/security_utils.py"
click node_policy_parser "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/policy_parser.py"
click node_policy_data "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/models/policy_data.py"
click node_network_graph "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/network_graph.py"
click node_renderer "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/renderer.py"
click node_network_topology "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/network_topology.html"
click node_server "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/server/server.py"
click node_container "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/container.py"
click node_dockerfile "https://github.com/simplyminimal/tailscale-network-topology-mapper/tree/main/Dockerfile"
click node_publish_workflow "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/.github/workflows/publish-pypi.yml"
click node_tailscale_workflow "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/.github/workflows/tailscale.yml"
click node_validate_script "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/scripts/validate-policy.sh"
click node_tests "https://github.com/simplyminimal/tailscale-network-topology-mapper/tree/main/tests"
click node_config "https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/config.py"

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_main,node_file_loader,node_policy_validator,node_security_utils,node_tailscale_api,node_config toneBlue
class node_policy_parser,node_policy_data,node_network_graph,node_renderer toneAmber
class node_network_topology,node_server toneMint
class node_container,node_dockerfile,node_publish_workflow,node_tailscale_workflow,node_validate_script toneRose
class node_tests toneIndigo
```

## Components

### Input & Validation

Policy ingestion, file access, and validation boundaries.

- [CLI Entry](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/main.py): entrypoint · Primary command-line entry point for local and packaged execution. · `main.py`
- [File Loader](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/file_loader.py): io service · Loads local policy files from disk. · `services/file_loader.py`
- [Policy Validator](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/policy_validator.py): validation service · Handles offline and API-backed policy validation. · `services/policy_validator.py`
- [Security Utils](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/security_utils.py): security helpers · Shared helpers for secret handling and policy-related safety checks. · `security_utils.py`
- **Tailscale API**: external api · Optional remote source for policy retrieval and validation.
- [Config](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/config.py): settings · Repository-level defaults and runtime configuration. · `config.py`

### Core Pipeline

Parsing, normalization, graph construction, and rendering.

- [Policy Parser](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/policy_parser.py): parser · Translates HuJSON/JSON policy into internal structures. · `policy_parser.py`
- [Policy Model](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/models/policy_data.py): domain model · Canonical in-memory policy representation shared across stages. · `models/policy_data.py`
- [Graph Builder](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/network_graph.py): graph model · Builds the topology graph from normalized policy data. · `network_graph.py`
- [HTML Renderer](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/renderer.py): renderer · Converts graph data into the interactive HTML artifact. · `renderer.py`

### Output & Serving

Generated HTML artifact and lightweight hosting.

- [Topology HTML](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/network_topology.html): artifact · Self-contained interactive topology map output. · `network_topology.html`
- [Web Server](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/server/server.py): hosting server · Thin local/container hosting layer for the generated HTML. · `server/server.py`

### Automation & Delivery

Packaging, containerization, and workflow automation.

- [Container Wrapper](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/services/container.py): deployment helper · Container execution and orchestration boundary. · `services/container.py`
- [Dockerfile](https://github.com/simplyminimal/tailscale-network-topology-mapper/tree/main/Dockerfile): container spec · Build recipe for containerized execution. · `Dockerfile`
- [PyPI Workflow](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/.github/workflows/publish-pypi.yml): ci workflow · Automated packaging and publishing pipeline. · `.github/workflows/publish-pypi.yml`
- [Topology Workflow](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/.github/workflows/tailscale.yml): ci workflow · Automation path for regenerating topology from policy changes. · `.github/workflows/tailscale.yml`
- [Validate Script](https://github.com/simplyminimal/tailscale-network-topology-mapper/blob/main/scripts/validate-policy.sh): ops script · Shell helper for policy validation runs. · `scripts/validate-policy.sh`

### Quality & Regression

Test coverage for parser, graph, renderer, and UI behavior.

- [Test Suite](https://github.com/simplyminimal/tailscale-network-topology-mapper/tree/main/tests): tests · Coverage for parsing, graph generation, rendering, and UI behavior. · `tests`

## Connections

- CLI Entry → File Loader: load local policy · Reads policy input from disk when using local mode.
- CLI Entry → Policy Validator: validate policy · Runs the validation boundary before transformation.
- CLI Entry → Policy Parser: parse policy · Invokes parsing and normalization for the selected policy source.
- CLI Entry → HTML Renderer: render output · Triggers generation of the interactive HTML artifact.
- CLI Entry → Web Server: serve artifact · Uses the hosting boundary when running as a local web app.
- File Loader → Policy Parser: raw policy · Supplies file contents to the parser.
- Policy Validator → Security Utils: secure checks · Shares safe handling and policy-related helper logic.
- Policy Validator → Tailscale API: api validation · Optional remote validation against Tailscale.
- Policy Parser → Policy Model: normalize · Produces the canonical in-memory policy contract.
- Policy Model → Graph Builder: policy model · Feeds the graph construction stage.
- Graph Builder → HTML Renderer: graph data · Provides the visual topology model to the renderer.
- HTML Renderer → Topology HTML: generate html · Writes the self-contained interactive artifact.
- Web Server → Topology HTML: host html · Serves the generated artifact directly.
- Container Wrapper → Web Server: run server · Containerized deployment hosts the app through the server boundary.
- Dockerfile → Container Wrapper: build image · Defines the container runtime packaging.
- PyPI Workflow → CLI Entry: package app · Automation path for build and release of the CLI application.
- Topology Workflow → Policy Validator: validate policy · Automates policy checks in CI.
- Topology Workflow → HTML Renderer: regenerate map · Refreshes the HTML artifact from updated policy input.
- Validate Script → Policy Validator: run checks · Operational script entry to validation logic.
- Test Suite → Policy Parser: parser tests · Exercises policy ingestion and normalization.
- Test Suite → Graph Builder: graph tests · Covers graph construction and directional relationships.
- Test Suite → HTML Renderer: ui tests · Covers HTML output and interactive behavior.
- Config → CLI Entry: runtime defaults · Provides repository-wide defaults used at startup.
- Config → Policy Validator: env config · Supports validation and remote access configuration.
