How simplyminimal/tailscale-network-topology-mapper works
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 CLI Entry · policy_validator.py Policy Validator · renderer.py HTML Renderer · policy_parser.py Policy Parser
Components 18
Input & Validation
Policy ingestion, file access, and validation boundaries.
- CLI Entry · Primary command-line entry point for local and packaged execution.
main.py - File Loader · Loads local policy files from disk.
services/file_loader.py - Policy Validator · Handles offline and API-backed policy validation.
services/policy_validator.py - Security Utils · Shared helpers for secret handling and policy-related safety checks.
security_utils.py - Tailscale API · Optional remote source for policy retrieval and validation.
- Config · Repository-level defaults and runtime configuration.
config.py
Core Pipeline
Parsing, normalization, graph construction, and rendering.
- Policy Parser · Translates HuJSON/JSON policy into internal structures.
policy_parser.py - Policy Model · Canonical in-memory policy representation shared across stages.
models/policy_data.py - Graph Builder · Builds the topology graph from normalized policy data.
network_graph.py - HTML Renderer · Converts graph data into the interactive HTML artifact.
renderer.py
Output & Serving
Generated HTML artifact and lightweight hosting.
- Topology HTML · Self-contained interactive topology map output.
network_topology.html - Web Server · Thin local/container hosting layer for the generated HTML.
server/server.py
Automation & Delivery
Packaging, containerization, and workflow automation.
- Container Wrapper · Container execution and orchestration boundary.
services/container.py - Dockerfile · Build recipe for containerized execution.
Dockerfile - PyPI Workflow · Automated packaging and publishing pipeline.
.github/workflows/publish-pypi.yml - Topology Workflow · Automation path for regenerating topology from policy changes.
.github/workflows/tailscale.yml - Validate Script · Shell helper for policy validation runs.
scripts/validate-policy.sh
Quality & Regression
Test coverage for parser, graph, renderer, and UI behavior.
- Test Suite · Coverage for parsing, graph generation, rendering, and UI behavior.
tests
Connections 24
- 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.