Generate architecture diagrams from Terraform, Kubernetes, and Docker Compose files
Project description
infra-diagram
Generate architecture diagrams from Terraform, Kubernetes, and Docker Compose files.
infra-diagram scans your Infrastructure-as-Code files, identifies every resource and its relationships, and generates beautiful Mermaid diagrams, interactive HTML reports, and JSON exports — all from a single CLI command.
Features
| Feature | Description |
|---|---|
| Multi-Source Parsing | Terraform (.tf), Kubernetes YAML, Docker Compose |
| Auto-Detection | Automatically identifies IaC type from file contents |
| 60+ Terraform Resources | AWS, Azure, and GCP resource mapping |
| 20+ Kubernetes Kinds | Deployments, Services, Ingress, ConfigMaps, RBAC, and more |
| 30+ Docker Images | Auto-infers component types from image names |
| Mermaid Diagrams | Copy-pasteable Mermaid syntax for docs and PRs |
| Interactive HTML Reports | Dark-themed dashboards with live Mermaid rendering |
| JSON Export | Machine-readable output for CI/CD pipelines |
| Smart Edge Detection | Infers connections from selectors, depends_on, subnets |
| Resource Grouping | Groups by provider, namespace, or Docker services |
| Rich Terminal Output | Colorful tables with icons for every component type |
| Demo Mode | Built-in sample infrastructure for instant previews |
Installation
pip install infra-diagram-cli
Requirements: Python 3.10+
Quick Start
# Scan current directory (auto-detects IaC type)
infra-diagram generate .
# Generate HTML report
infra-diagram generate ./terraform --html architecture.html
# Export Mermaid diagram
infra-diagram generate ./k8s --type kubernetes -m diagram.md
# Export JSON
infra-diagram generate . --json-output infra.json
# Change diagram direction
infra-diagram generate . --direction TB
# Run demo with sample infrastructure
infra-diagram demo
# Demo specific type
infra-diagram demo --type terraform --html demo-report.html
Commands
generate
Scan IaC files and produce architecture diagrams.
infra-diagram generate PATH [OPTIONS]
| Option | Description |
|---|---|
--type |
Source type: auto, terraform, kubernetes, compose |
--html FILE |
Export HTML report with interactive Mermaid diagram |
--json-output FILE |
Export JSON data |
--mermaid FILE |
Export Mermaid .md file |
--direction |
Diagram flow: TB, LR, BT, RL (default: LR) |
demo
Run a demo with built-in sample IaC files.
infra-diagram demo [OPTIONS]
| Option | Description |
|---|---|
--type |
Demo type: all, terraform, kubernetes, compose |
--html FILE |
Export HTML report for the last demo |
--direction |
Diagram direction |
Supported Resources
Terraform (60+ resource types)
AWS: VPC, Subnet, EC2, ECS, EKS, Lambda, S3, RDS, ElastiCache, DynamoDB, SQS, SNS, ALB, CloudFront, Route53, IAM, ACM, KMS, CloudWatch, API Gateway, NAT Gateway, Security Groups
Azure: Resource Group, Virtual Network, VMs, AKS, Functions, Storage, SQL, CosmosDB, Redis, Key Vault, Application Gateway, DNS, Load Balancer
GCP: Compute Instance, GKE, Cloud Run, Cloud Functions, Storage, Cloud SQL, Redis, VPC, Firewall, DNS, KMS, Pub/Sub
Kubernetes (20+ kinds)
Deployment, StatefulSet, DaemonSet, ReplicaSet, Pod, Service, Ingress, ConfigMap, Secret, PVC, PV, Namespace, ServiceAccount, Role, RoleBinding, ClusterRole, ClusterRoleBinding, NetworkPolicy, HPA, CronJob, Job
Docker Compose
Services with auto-type inference from images: PostgreSQL, MySQL, MongoDB, Redis, Memcached, RabbitMQ, Kafka, Nginx, Traefik, HAProxy, Elasticsearch, Grafana, Prometheus, MinIO, Vault, Consul, and more
Output Formats
Mermaid Diagram
Generated Mermaid code can be pasted into:
- GitHub/GitLab READMEs and PRs (native rendering)
- mermaid.live for interactive editing
- Notion, Confluence, and other documentation tools
HTML Report
Dark-themed interactive dashboard featuring:
- Summary cards (components, connections, groups, providers)
- Live Mermaid diagram (rendered via CDN)
- Components table with type badges
- Connections table
- Copyable Mermaid source code
JSON Export
{
"title": "Terraform Infrastructure",
"source_type": "terraform",
"node_count": 14,
"edge_count": 22,
"nodes": [...],
"edges": [...],
"groups": [...]
}
Examples
Terraform → Architecture Diagram
infra-diagram generate ./infrastructure --html infra.html
┌─────────────────────────────────────────────────┐
│ infra-diagram — Infrastructure Diagram Generator│
│ Source: terraform Components: 14 Connections: 22│
└─────────────────────────────────────────────────┘
# │ │ Name │ Type │ Provider │ Source
1 │ 🌐│ main-vpc │ network │ aws │ main.tf
2 │ 🔗│ public │ subnet │ aws │ main.tf
3 │ ⚖️│ web-alb │ load_balancer │ aws │ main.tf
4 │ 🐳│ app-cluster │ container │ aws │ main.tf
5 │ 🗄️│ db │ database │ aws │ main.tf
...
Docker Compose → Diagram
infra-diagram generate . --type compose --direction TB
Kubernetes → Export All Formats
infra-diagram generate ./k8s \
--type kubernetes \
--html k8s-arch.html \
--mermaid k8s-diagram.md \
--json-output k8s-data.json
Programmatic Usage
from infra_diagram.parsers.terraform import parse_terraform
from infra_diagram.renderers.mermaid import render_mermaid
from infra_diagram.output.html_report import export_html
# Parse
diagram = parse_terraform("./infrastructure")
# Render Mermaid
mermaid_code = render_mermaid(diagram, direction="LR")
print(mermaid_code)
# Export HTML
export_html(diagram, "architecture.html")
Development
git clone https://github.com/SanjaySundarMurthy/infra-diagram-generator.git
cd infra-diagram-generator
pip install -e ".[dev]"
pytest tests/ -v
ruff check .
License
MIT — see LICENSE for details.
Author
Sanjay S — GitHub
🏗️ infra-diagram — See your infrastructure before you deploy it
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infra_diagram_cli-1.0.0.tar.gz.
File metadata
- Download URL: infra_diagram_cli-1.0.0.tar.gz
- Upload date:
- Size: 25.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7215583415f5cf7e5410d73b4f372ce66cabb441b1cabff13f77f3caf0caf04c
|
|
| MD5 |
e527f38e7777ed308bb35c7813fdf2e7
|
|
| BLAKE2b-256 |
d55aff17565986eae09557387c44cfc87843bf8a1c75b4275ebf3666bb895a3b
|
File details
Details for the file infra_diagram_cli-1.0.0-py3-none-any.whl.
File metadata
- Download URL: infra_diagram_cli-1.0.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c83b564154917b0ac868a07e4e923c28ae2a498765132bf1b9c585ea53c43aeb
|
|
| MD5 |
26c6bd4940e84a851db66e23ed49a01c
|
|
| BLAKE2b-256 |
23c4b143d8d4fbaed7015e2b0723d0edfa40fad9e76e9c752b162bafb1cd9ba5
|