Metadata-Version: 2.4
Name: infra-diagram-cli
Version: 1.0.0
Summary: Generate architecture diagrams from Terraform, Kubernetes, and Docker Compose files
Project-URL: Homepage, https://github.com/SanjaySundarMurthy/infra-diagram-generator
Project-URL: Repository, https://github.com/SanjaySundarMurthy/infra-diagram-generator
Project-URL: Issues, https://github.com/SanjaySundarMurthy/infra-diagram-generator/issues
Author-email: Sanjay S <sanjaysundarmurthy@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: architecture,cli,devops,diagram,docker,infrastructure,kubernetes,mermaid,terraform,visualization
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Documentation
Classifier: Topic :: System :: Systems Administration
Requires-Python: >=3.10
Requires-Dist: click>=8.0
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.0
Provides-Extra: dev
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.4; extra == 'dev'
Description-Content-Type: text/markdown

# infra-diagram

**Generate architecture diagrams from Terraform, Kubernetes, and Docker Compose files.**

[![PyPI version](https://img.shields.io/pypi/v/infra-diagram-cli.svg)](https://pypi.org/project/infra-diagram-cli/)
[![Python](https://img.shields.io/pypi/pyversions/infra-diagram-cli.svg)](https://pypi.org/project/infra-diagram-cli/)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)

`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

```bash
pip install infra-diagram-cli
```

**Requirements:** Python 3.10+

---

## Quick Start

```bash
# 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.

```bash
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.

```bash
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](https://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

```json
{
  "title": "Terraform Infrastructure",
  "source_type": "terraform",
  "node_count": 14,
  "edge_count": 22,
  "nodes": [...],
  "edges": [...],
  "groups": [...]
}
```

---

## Examples

### Terraform → Architecture Diagram

```bash
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

```bash
infra-diagram generate . --type compose --direction TB
```

### Kubernetes → Export All Formats

```bash
infra-diagram generate ./k8s \
  --type kubernetes \
  --html k8s-arch.html \
  --mermaid k8s-diagram.md \
  --json-output k8s-data.json
```

---

## Programmatic Usage

```python
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

```bash
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](LICENSE) for details.

---

## Author

**Sanjay S** — [GitHub](https://github.com/SanjaySundarMurthy)

---

<p align="center">
  <b>🏗️ infra-diagram</b> — See your infrastructure before you deploy it
</p>
