secdiagram 0.5.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. secdiagram-0.5.0/LICENSE +21 -0
  2. secdiagram-0.5.0/PKG-INFO +316 -0
  3. secdiagram-0.5.0/README.md +285 -0
  4. secdiagram-0.5.0/pyproject.toml +79 -0
  5. secdiagram-0.5.0/secdiagram.egg-info/PKG-INFO +316 -0
  6. secdiagram-0.5.0/secdiagram.egg-info/SOURCES.txt +173 -0
  7. secdiagram-0.5.0/secdiagram.egg-info/dependency_links.txt +1 -0
  8. secdiagram-0.5.0/secdiagram.egg-info/entry_points.txt +4 -0
  9. secdiagram-0.5.0/secdiagram.egg-info/requires.txt +13 -0
  10. secdiagram-0.5.0/secdiagram.egg-info/top_level.txt +1 -0
  11. secdiagram-0.5.0/secdiagram_core/__init__.py +186 -0
  12. secdiagram-0.5.0/secdiagram_core/advisories.py +311 -0
  13. secdiagram-0.5.0/secdiagram_core/agentic.py +599 -0
  14. secdiagram-0.5.0/secdiagram_core/analyzer.py +652 -0
  15. secdiagram-0.5.0/secdiagram_core/application_context.py +186 -0
  16. secdiagram-0.5.0/secdiagram_core/architecture_scorecard.py +1014 -0
  17. secdiagram-0.5.0/secdiagram_core/artifacts.py +180 -0
  18. secdiagram-0.5.0/secdiagram_core/assessment.py +264 -0
  19. secdiagram-0.5.0/secdiagram_core/ast_index.py +658 -0
  20. secdiagram-0.5.0/secdiagram_core/backlog.py +296 -0
  21. secdiagram-0.5.0/secdiagram_core/baseline.py +232 -0
  22. secdiagram-0.5.0/secdiagram_core/cache.py +173 -0
  23. secdiagram-0.5.0/secdiagram_core/cargo_manifest.py +80 -0
  24. secdiagram-0.5.0/secdiagram_core/cli.py +797 -0
  25. secdiagram-0.5.0/secdiagram_core/cli_commands.py +442 -0
  26. secdiagram-0.5.0/secdiagram_core/cli_doctor.py +36 -0
  27. secdiagram-0.5.0/secdiagram_core/cli_parser.py +558 -0
  28. secdiagram-0.5.0/secdiagram_core/cli_schema.py +72 -0
  29. secdiagram-0.5.0/secdiagram_core/cli_setup.py +103 -0
  30. secdiagram-0.5.0/secdiagram_core/cli_workspace.py +199 -0
  31. secdiagram-0.5.0/secdiagram_core/confidence.py +97 -0
  32. secdiagram-0.5.0/secdiagram_core/config.py +214 -0
  33. secdiagram-0.5.0/secdiagram_core/credentials.py +49 -0
  34. secdiagram-0.5.0/secdiagram_core/dart_declarations.py +354 -0
  35. secdiagram-0.5.0/secdiagram_core/dast_reports.py +951 -0
  36. secdiagram-0.5.0/secdiagram_core/dependency_bundle.py +105 -0
  37. secdiagram-0.5.0/secdiagram_core/dependency_correlation.py +166 -0
  38. secdiagram-0.5.0/secdiagram_core/dependency_gate.py +61 -0
  39. secdiagram-0.5.0/secdiagram_core/dependency_graph.py +25 -0
  40. secdiagram-0.5.0/secdiagram_core/dependency_inventory.py +117 -0
  41. secdiagram-0.5.0/secdiagram_core/dependency_remediation.py +27 -0
  42. secdiagram-0.5.0/secdiagram_core/dependency_reports.py +269 -0
  43. secdiagram-0.5.0/secdiagram_core/dependency_versions.py +146 -0
  44. secdiagram-0.5.0/secdiagram_core/diagram_edit.py +238 -0
  45. secdiagram-0.5.0/secdiagram_core/diagram_model.py +340 -0
  46. secdiagram-0.5.0/secdiagram_core/diagram_quality.py +297 -0
  47. secdiagram-0.5.0/secdiagram_core/discover.py +346 -0
  48. secdiagram-0.5.0/secdiagram_core/doctor.py +212 -0
  49. secdiagram-0.5.0/secdiagram_core/evidence_model.py +898 -0
  50. secdiagram-0.5.0/secdiagram_core/exploitability.py +653 -0
  51. secdiagram-0.5.0/secdiagram_core/exposure.py +136 -0
  52. secdiagram-0.5.0/secdiagram_core/external_reports.py +474 -0
  53. secdiagram-0.5.0/secdiagram_core/external_setup.py +285 -0
  54. secdiagram-0.5.0/secdiagram_core/features.py +98 -0
  55. secdiagram-0.5.0/secdiagram_core/frameworks.py +284 -0
  56. secdiagram-0.5.0/secdiagram_core/graph_builder.py +350 -0
  57. secdiagram-0.5.0/secdiagram_core/health.py +34 -0
  58. secdiagram-0.5.0/secdiagram_core/high_level.py +1595 -0
  59. secdiagram-0.5.0/secdiagram_core/iac.py +1168 -0
  60. secdiagram-0.5.0/secdiagram_core/investigation.py +285 -0
  61. secdiagram-0.5.0/secdiagram_core/java_index.py +1459 -0
  62. secdiagram-0.5.0/secdiagram_core/limits.py +158 -0
  63. secdiagram-0.5.0/secdiagram_core/llm.py +776 -0
  64. secdiagram-0.5.0/secdiagram_core/misconfig.py +316 -0
  65. secdiagram-0.5.0/secdiagram_core/model.py +629 -0
  66. secdiagram-0.5.0/secdiagram_core/path_safety.py +73 -0
  67. secdiagram-0.5.0/secdiagram_core/policy.py +439 -0
  68. secdiagram-0.5.0/secdiagram_core/polyglot_index.py +544 -0
  69. secdiagram-0.5.0/secdiagram_core/polyglot_lexer.py +560 -0
  70. secdiagram-0.5.0/secdiagram_core/polyglot_parsers_native.py +690 -0
  71. secdiagram-0.5.0/secdiagram_core/polyglot_parsers_web.py +932 -0
  72. secdiagram-0.5.0/secdiagram_core/polyglot_rules.py +343 -0
  73. secdiagram-0.5.0/secdiagram_core/polyglot_security.py +929 -0
  74. secdiagram-0.5.0/secdiagram_core/protocols.py +131 -0
  75. secdiagram-0.5.0/secdiagram_core/reachability.py +152 -0
  76. secdiagram-0.5.0/secdiagram_core/redaction.py +220 -0
  77. secdiagram-0.5.0/secdiagram_core/render_html.py +1460 -0
  78. secdiagram-0.5.0/secdiagram_core/render_image.py +387 -0
  79. secdiagram-0.5.0/secdiagram_core/render_json.py +32 -0
  80. secdiagram-0.5.0/secdiagram_core/render_markdown.py +535 -0
  81. secdiagram-0.5.0/secdiagram_core/render_mermaid.py +411 -0
  82. secdiagram-0.5.0/secdiagram_core/render_sarif.py +467 -0
  83. secdiagram-0.5.0/secdiagram_core/render_security.py +1426 -0
  84. secdiagram-0.5.0/secdiagram_core/render_vex.py +187 -0
  85. secdiagram-0.5.0/secdiagram_core/resolver.py +580 -0
  86. secdiagram-0.5.0/secdiagram_core/risk.py +257 -0
  87. secdiagram-0.5.0/secdiagram_core/sca.py +140 -0
  88. secdiagram-0.5.0/secdiagram_core/schemas.py +522 -0
  89. secdiagram-0.5.0/secdiagram_core/security.py +1358 -0
  90. secdiagram-0.5.0/secdiagram_core/security_report.py +636 -0
  91. secdiagram-0.5.0/secdiagram_core/server.py +441 -0
  92. secdiagram-0.5.0/secdiagram_core/server_routes.py +907 -0
  93. secdiagram-0.5.0/secdiagram_core/server_state.py +547 -0
  94. secdiagram-0.5.0/secdiagram_core/studio.py +621 -0
  95. secdiagram-0.5.0/secdiagram_core/studio_diagram.py +156 -0
  96. secdiagram-0.5.0/secdiagram_core/studio_ui/app.css +306 -0
  97. secdiagram-0.5.0/secdiagram_core/studio_ui/app.js +1218 -0
  98. secdiagram-0.5.0/secdiagram_core/studio_ui/index.html +269 -0
  99. secdiagram-0.5.0/secdiagram_core/studio_ui.py +46 -0
  100. secdiagram-0.5.0/secdiagram_core/swift_ios.py +245 -0
  101. secdiagram-0.5.0/secdiagram_core/taint_flows.py +398 -0
  102. secdiagram-0.5.0/secdiagram_core/threat_model.py +672 -0
  103. secdiagram-0.5.0/secdiagram_core/threat_review.py +664 -0
  104. secdiagram-0.5.0/secdiagram_core/workspace.py +1053 -0
  105. secdiagram-0.5.0/secdiagram_core/yaml_lite.py +163 -0
  106. secdiagram-0.5.0/setup.cfg +4 -0
  107. secdiagram-0.5.0/tests/test_agentic.py +195 -0
  108. secdiagram-0.5.0/tests/test_analysis_trust.py +120 -0
  109. secdiagram-0.5.0/tests/test_application_context.py +97 -0
  110. secdiagram-0.5.0/tests/test_architecture_scorecard.py +228 -0
  111. secdiagram-0.5.0/tests/test_artifacts.py +204 -0
  112. secdiagram-0.5.0/tests/test_assessment.py +166 -0
  113. secdiagram-0.5.0/tests/test_attack.py +322 -0
  114. secdiagram-0.5.0/tests/test_backlog.py +272 -0
  115. secdiagram-0.5.0/tests/test_baseline.py +251 -0
  116. secdiagram-0.5.0/tests/test_benchmark_sast.py +341 -0
  117. secdiagram-0.5.0/tests/test_cache_serialization.py +59 -0
  118. secdiagram-0.5.0/tests/test_cli.py +385 -0
  119. secdiagram-0.5.0/tests/test_config.py +133 -0
  120. secdiagram-0.5.0/tests/test_contract.py +161 -0
  121. secdiagram-0.5.0/tests/test_dart.py +400 -0
  122. secdiagram-0.5.0/tests/test_dast_reports.py +358 -0
  123. secdiagram-0.5.0/tests/test_dependency_bundle.py +71 -0
  124. secdiagram-0.5.0/tests/test_dependency_correlation.py +96 -0
  125. secdiagram-0.5.0/tests/test_dependency_inventory.py +343 -0
  126. secdiagram-0.5.0/tests/test_dependency_versions.py +42 -0
  127. secdiagram-0.5.0/tests/test_diagram_determinism.py +112 -0
  128. secdiagram-0.5.0/tests/test_diagram_edit.py +136 -0
  129. secdiagram-0.5.0/tests/test_diagram_quality.py +277 -0
  130. secdiagram-0.5.0/tests/test_diagram_review.py +169 -0
  131. secdiagram-0.5.0/tests/test_discover.py +138 -0
  132. secdiagram-0.5.0/tests/test_doctor.py +63 -0
  133. secdiagram-0.5.0/tests/test_evidence_model.py +188 -0
  134. secdiagram-0.5.0/tests/test_exploitability.py +225 -0
  135. secdiagram-0.5.0/tests/test_external_reports.py +299 -0
  136. secdiagram-0.5.0/tests/test_external_setup.py +146 -0
  137. secdiagram-0.5.0/tests/test_flutter.py +95 -0
  138. secdiagram-0.5.0/tests/test_framework_registry.py +167 -0
  139. secdiagram-0.5.0/tests/test_graph.py +152 -0
  140. secdiagram-0.5.0/tests/test_high_level.py +202 -0
  141. secdiagram-0.5.0/tests/test_html.py +241 -0
  142. secdiagram-0.5.0/tests/test_iac.py +629 -0
  143. secdiagram-0.5.0/tests/test_image.py +239 -0
  144. secdiagram-0.5.0/tests/test_java.py +191 -0
  145. secdiagram-0.5.0/tests/test_limits.py +98 -0
  146. secdiagram-0.5.0/tests/test_llm.py +362 -0
  147. secdiagram-0.5.0/tests/test_misconfig.py +97 -0
  148. secdiagram-0.5.0/tests/test_offline_cli.py +179 -0
  149. secdiagram-0.5.0/tests/test_output_contracts.py +133 -0
  150. secdiagram-0.5.0/tests/test_path_safety.py +135 -0
  151. secdiagram-0.5.0/tests/test_policy.py +559 -0
  152. secdiagram-0.5.0/tests/test_polyglot.py +459 -0
  153. secdiagram-0.5.0/tests/test_protocols.py +293 -0
  154. secdiagram-0.5.0/tests/test_python_index.py +161 -0
  155. secdiagram-0.5.0/tests/test_reachability_query.py +75 -0
  156. secdiagram-0.5.0/tests/test_redaction.py +232 -0
  157. secdiagram-0.5.0/tests/test_render.py +129 -0
  158. secdiagram-0.5.0/tests/test_risk.py +194 -0
  159. secdiagram-0.5.0/tests/test_rust.py +454 -0
  160. secdiagram-0.5.0/tests/test_scale.py +234 -0
  161. secdiagram-0.5.0/tests/test_security.py +249 -0
  162. secdiagram-0.5.0/tests/test_security_relevance.py +242 -0
  163. secdiagram-0.5.0/tests/test_security_report.py +306 -0
  164. secdiagram-0.5.0/tests/test_server.py +630 -0
  165. secdiagram-0.5.0/tests/test_studio_diagram.py +42 -0
  166. secdiagram-0.5.0/tests/test_studio_installer.py +219 -0
  167. secdiagram-0.5.0/tests/test_studio_server.py +456 -0
  168. secdiagram-0.5.0/tests/test_studio_ui_accessibility.py +176 -0
  169. secdiagram-0.5.0/tests/test_supply_chain.py +256 -0
  170. secdiagram-0.5.0/tests/test_swift_ios.py +171 -0
  171. secdiagram-0.5.0/tests/test_taskctl.py +310 -0
  172. secdiagram-0.5.0/tests/test_threat_review.py +634 -0
  173. secdiagram-0.5.0/tests/test_vex.py +90 -0
  174. secdiagram-0.5.0/tests/test_workspace.py +750 -0
  175. secdiagram-0.5.0/tests/test_yaml_lite.py +96 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 vichhaiyserey
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,316 @@
1
+ Metadata-Version: 2.4
2
+ Name: secdiagram
3
+ Version: 0.5.0
4
+ Summary: Deterministic architecture, relationship, and security analysis for polyglot repositories.
5
+ Author: secdiagram maintainers
6
+ License: MIT
7
+ Classifier: Development Status :: 4 - Beta
8
+ Classifier: Intended Audience :: Developers
9
+ Classifier: License :: OSI Approved :: MIT License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
15
+ Classifier: Programming Language :: Python :: 3.14
16
+ Classifier: Programming Language :: Python :: 3.15
17
+ Classifier: Topic :: Software Development :: Documentation
18
+ Classifier: Topic :: Security
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Provides-Extra: dev
23
+ Requires-Dist: bandit[toml]==1.9.4; extra == "dev"
24
+ Requires-Dist: build==1.6.1; extra == "dev"
25
+ Requires-Dist: coverage[toml]==7.16.0; python_version < "3.11" and extra == "dev"
26
+ Requires-Dist: coverage[toml]==7.17.1; python_version >= "3.11" and extra == "dev"
27
+ Requires-Dist: mypy==2.4.1; extra == "dev"
28
+ Requires-Dist: pip-audit==2.10.1; extra == "dev"
29
+ Requires-Dist: ruff==0.17.5; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ <div align="center">
33
+
34
+ # โšก secdiagram
35
+
36
+ ### *Small but Gold* โ€” Deterministic Architecture Diagrams, Polyglot System Mapping, and Security Intelligence.
37
+
38
+ [![Python](https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14%20%7C%203.15-blue.svg?style=flat-square&logo=python&logoColor=white)](https://python.org)
39
+ [![Zero Dependencies](https://img.shields.io/badge/Dependencies-Standard%20Library%20Only-success.svg?style=flat-square)](pyproject.toml)
40
+ [![Tests](https://github.com/vichhaiyserey/secdiagram/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/vichhaiyserey/secdiagram/actions/workflows/ci.yml?query=branch%3Adevelop)
41
+ [![Docker](https://img.shields.io/badge/Docker-Ready-2496ED.svg?style=flat-square&logo=docker&logoColor=white)](Dockerfile)
42
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
43
+ [![Cross Platform](https://img.shields.io/badge/Platform-macOS%20%7C%20Ubuntu%20%7C%20RHEL%20%7C%20Windows-blueviolet.svg?style=flat-square)](docs/CONTAINER_AND_COMPOSE.md)
44
+
45
+ <p align="center">
46
+ <b>Transform codebases into clear, human-friendly system architecture diagrams, publication-quality images, security threat models, and AI reviews.</b><br>
47
+ <i>100% offline-first. Zero external Python runtime dependencies. Polyglot architecture and security analysis across <b>.NET (C#)</b>, <b>Java / Spring Boot</b>, <b>Node.js / TypeScript</b>, <b>PHP</b>, <b>Go</b>, <b>Rust</b>, <b>Dart / Flutter</b>, <b>Python</b>, and <b>Docker / Kubernetes / Terraform</b>.</i>
48
+ </p>
49
+
50
+ ---
51
+
52
+ </div>
53
+
54
+ ## ๐ŸŒŸ Key Highlights
55
+
56
+ - **Pure Python Standard Library (`zero dependencies`)**: Core analysis requires no third-party Python packages. Optional renderers and developer tools have separate pinned dependencies.
57
+ - **High-Level C4 System Diagrams**: Automatically compiles clean C4 tier diagrams (`diagram-highlevel.mmd` & `diagram-highlevel.png`) showing Ingress, Gateways, Core Services, Databases, Caches, Brokers, and External APIs.
58
+ - **Multi-Format Image Rendering**: Export diagrams directly to **PNG**, **SVG**, or **PDF** offline via bundled Mermaid CLI (`mmdc`) or zero-dependency HTTP fallbacks (Kroki, mermaid.ink).
59
+ - **Security & IaC SAST Overlay**: Discovers entrypoints, traces taint dataflows **across functions and files** (controller โ†’ service โ†’ repository) to dangerous sinks (CWE-78, CWE-89, CWE-502), draws them as an attack-path diagram, catches hardcoded secrets, and audits Dockerfile, Kubernetes, Terraform, and GitHub Actions configurations.
60
+ - **Runtime DAST Evidence Correlation**: Import OWASP ZAP Traditional JSON and Nuclei JSONL/JSON reports and deterministically match observed requests (HTTP method + templated path) to static endpoint nodes. Matched endpoints gain `runtime_observed` metadata, runtime-only endpoints are reported instead of invented, and runtime-confirmed critical/high findings can satisfy the strict policy reachability gate -- all without launching a scanner or making network calls.
61
+ - **Local Dependency Risk Correlation**: Builds a bounded offline Pub/Flutter inventory from `pubspec.yaml`, `pubspec.lock`, and `.dart_tool/package_config.json`, then correlates local Trivy and CycloneDX reports by scoped package and exact resolved version. Static imports and qualified package call paths supply reachability evidence, while a policy-owned reviewed symbol gate is required before a dependency finding can fail CI. Optional SHA-256 evidence bundles add reproducibility and freshness checks, and remediation details flow into Markdown, HTML, JSON, SARIF, and VEX. See [Dependency risk correlation](docs/DEPENDENCY_RISK_CORRELATION.md).
62
+ - **Web/API Misconfiguration Checks**: Flags broken JWT validation (`alg=none`, signature/expiry checks off), CORS that trusts any origin **with credentials**, disabled CSRF protection, cookies without `HttpOnly`/`Secure`, XXE-prone XML parsers, non-cryptographic RNGs used for tokens, and JS prototype pollution across C#, JS/TS, PHP, Go, and Java.
63
+ - **Risk-Ranked "Fix First" List**: Scores every finding 0โ€“10 by impact ร— exposure (anonymous, authenticated, or internal entry point, detected from framework auth markers) ร— evidence ร— confidence ร— CISA KEV, and groups them P0โ€“P3 in reports, SARIF, and diagrams.
64
+ - **STRIDE Threat Model**: Generates `THREAT_MODEL.md` and `threat-model.json` with affected components, assets, source evidence, static flows, severity/confidence, and verification steps. Facts and assessments are separated; `secdiagram threat-diff` compares saved versions offline. See [Threat modeling](docs/THREAT_MODELING.md).
65
+ - **Architecture Security Scorecard**: The standalone security review opens with a defensible verdict (`pass`, `conditional pass`, `fail`, or `insufficient evidence`), architecture and control posture, evidence-backed critical attack paths, design risks, and explicit coverage confidence. Facts and judgments are separate, and missing evidence is never reported as a pass.
66
+ - **MITRE ATT&CK Audit Gate**: `secdiagram audit <dir>` maps the parsed architecture to ATT&CK techniques (T1190 Exploit Public-Facing Application, T1040 Network Sniffing, T1552 Unsecured Credentials, โ€ฆ) with evidence and missing mitigations, and **fails CI/CD with exit code 1** when findings violate `policy.yaml` thresholds.
67
+ - **CycloneDX 1.6 VEX & SARIF Export**: Generates industry-standard `security.sarif` and CycloneDX 1.6 VEX documents (`vex.json`) with automated reachability justifications (`code_not_reachable`) for dead/internal code.
68
+ - **AI Architectural & Threat Modeling Reviews**: Integrates with local/containerized **Ollama (Qwen, LLaMA, DeepSeek)** or OpenAI endpoints to generate evidence-grounded architectural reviews citing exact `path:line` with zero hallucinations.
69
+ - **Agentic Studio & Portable AI Skill**: User-level installer with a private venv, portable launchers, and an agent skill manifest. The hardened Studio SPA adds interactive diagram overrides, a five-phase discover/model/secure/review/handoff state machine with evidence gates, executable handoff artifacts, and local-Ollama or OpenAI reviews -- all without adding a runtime dependency. See [Agentic Studio](docs/STUDIO.md).
70
+ - **100% Deterministic & Air-Gapped**: Byte-for-byte reproducible outputs across runs. Fully functional in offline, isolated, or air-gapped environments.
71
+
72
+ ---
73
+
74
+ ## ๐Ÿš€ Quick Start
75
+
76
+ New to secdiagram? Start with the [beginner guide](docs/BEGINNER_GUIDE.md) or
77
+ download the [printable PDF](docs/BEGINNER_GUIDE.pdf).
78
+
79
+ ### 1. Install and run (Python 3.10+)
80
+
81
+ Install the CLI in a virtual environment or run it directly from a source checkout.
82
+
83
+ ```bash
84
+ python -m pip install secdiagram
85
+ secdiagram --dir . --offline
86
+ ```
87
+
88
+ From a source checkout, the CLI requires only the Python standard library.
89
+
90
+ See [runtime prerequisites and evidence coverage](docs/RUNTIME_PREREQUISITES.md)
91
+ for operating permissions, optional renderers and AI providers, and current
92
+ vulnerability evidence.
93
+
94
+ ```bash
95
+ # Analyze current repository and generate detailed architecture diagrams:
96
+ python secdiagram.py --dir="."
97
+
98
+ # Generate both detailed and high-level C4 system diagrams with PNG images:
99
+ python secdiagram.py --dir="." --image
100
+
101
+ # Generate high-level system overview as primary diagram:
102
+ python secdiagram.py --dir="." --high-level --image
103
+
104
+ # Correlate local Trivy/CycloneDX evidence with the Pub inventory (offline):
105
+ python secdiagram.py --dir="." --offline --trivy-report trivy.json --sbom inventory.cdx.json --format json,sarif,vex
106
+
107
+ # ATT&CK audit gate for CI/CD - exits 1 on policy violations:
108
+ python secdiagram.py audit . --policy policy.yaml --json audit-result.json
109
+
110
+ # Strict audit against a SHA-256 verified evidence bundle:
111
+ python secdiagram.py audit . --offline --evidence-bundle evidence.json --require-evidence --json audit-result.json
112
+ ```
113
+
114
+ ### 2. Standalone Container Execution (Docker / Podman)
115
+
116
+ Run using the pre-built, hardened non-root container with bundled Chromium and Mermaid CLI:
117
+
118
+ ```bash
119
+ # Linux / macOS:
120
+ docker run --rm -v "$(pwd):/repo" secdiagram:local --image
121
+
122
+ # Windows PowerShell:
123
+ docker run --rm -v "${PWD}:/repo" secdiagram:local --image
124
+
125
+ # RHEL / Fedora (SELinux mode):
126
+ docker run --rm -v "$(pwd):/repo:z" secdiagram:local --image
127
+ ```
128
+
129
+ ### 3. Agentic Studio & Portable AI Skill
130
+
131
+ ```bash
132
+ # Install the user-level Studio home, launchers, and agent skill:
133
+ python secdiagram.py studio install
134
+
135
+ # Serve the Studio on loopback with authentication:
136
+ python secdiagram.py studio serve --dir . --user analyst --password 'change-me'
137
+ ```
138
+
139
+ Open `http://127.0.0.1:8080/studio` to edit diagrams, drive the SDLC phases, request local AI
140
+ reviews, investigate findings, and generate handoff artifacts. The installer is CLI-only; the Studio reuses the
141
+ hardened platform server. See the [Agentic Studio guide](docs/STUDIO.md).
142
+
143
+ ### 4. Python Public Facade
144
+
145
+ Integrate directly into custom automation scripts or DevSecOps pipelines:
146
+
147
+ ```python
148
+ from secdiagram_core import analyze, render_mermaid, AnalysisConfig
149
+
150
+ result = analyze(AnalysisConfig(root=".", security=True))
151
+ print(f"Discovered {len(result.graph.nodes)} nodes and {len(result.graph.findings)} findings.")
152
+
153
+ # Native taint and package reachability query:
154
+ if result.has_taint_at("app/api.py", line=42):
155
+ print("Tainted dataflow detected at line 42!")
156
+
157
+ # Correlate runtime DAST evidence with the static endpoint graph:
158
+ runtime = analyze(
159
+ AnalysisConfig(root=".", zap_report="zap.json", nuclei_report="nuclei.jsonl")
160
+ )
161
+ print(runtime.graph.meta["runtime_analysis"]["matched_requests"], "runtime requests matched")
162
+
163
+ # Correlate local Pub inventory with Trivy and CycloneDX evidence:
164
+ deps = analyze(
165
+ AnalysisConfig(root=".", trivy_report="trivy.json", sbom="inventory.cdx.json")
166
+ )
167
+ print(deps.graph.meta["dependency_reports"])
168
+ ```
169
+
170
+ ---
171
+
172
+ ## ๐Ÿ”€ Supported Ecosystems
173
+
174
+ | Ecosystem | Manifests Inspected | Architectural & Security Elements Detected |
175
+ | :--- | :--- | :--- |
176
+ | **.NET (C#)** | `*.sln`, `*.csproj`, `*.fsproj`, `*.cs` | Project metadata and C# source indexing for ASP.NET Core, EF Core, and MediatR. Selected taint and configuration checks. |
177
+ | **Node.js / TypeScript** | `package.json`, workspaces, `schema.prisma`, `*.js`/`*.ts` | Express, Fastify, Koa, Hono, NestJS, Next.js routes & auth middleware; Prisma, TypeORM, Mongoose; interprocedural taint to SQL/NoSQL, `child_process`, `eval`, XSS, path, SSRF sinks; prototype pollution; JWT/CORS/cookie checks |
178
+ | **PHP** | `composer.json`, `*.php` | Laravel routes & middleware, Symfony `#[Route]`/`#[IsGranted]`, Slim, legacy page scripts; constructor DI; taint to SQL, `system`/`exec`, `include`, `unserialize`, XSS, path, SSRF; CSRF/CORS/cookie/XXE checks |
179
+ | **Go** | `go.mod`, `*.go` | `net/http` (incl. Go 1.22 `"GET /path"`), Gin, Echo, Chi routes & auth middleware; structs, receiver methods, `NewX` injection; taint to SQL, `exec.Command`, path, SSRF, XSS; JWT/CORS/cookie/TLS checks |
180
+ | **Dart / Flutter** | `pubspec.yaml`, `pubspec.lock`, `.dart_tool/package_config.json`, `*.dart` | Flutter widgets, services, repositories, GoRouter/Shelf routes; Pub direct/dev/transitive inventory with resolved versions and scopes; interprocedural taint to SQLite, `Process.run`, WebView JS/HTML, filesystem and HTTP sinks; TLS and weak-crypto checks; Trivy/CycloneDX advisory correlation. |
181
+ | **Rust** | `Cargo.toml`, `*.rs` | Structs/enums/traits, `impl` methods, Axum router and Actix attribute routes; request-to-SQLx, shell-command, filesystem and HTTP sink evidence; TLS/CORS and selected non-cryptographic RNG checks. Lexical coverage and limits: [Rust support](docs/RUST_SUPPORT.md). |
182
+ | **Swift / iOS** | `*.swift`, Xcode projects, SwiftPM manifests and pins, CocoaPods manifests and locks, plists and localization resources | SwiftUI app and view structure, MVVM relationships, SwiftData models, framework imports, dependencies, and selected iOS release-configuration findings. [Swift support](docs/SWIFT_SUPPORT.md). |
183
+ | **Java / Spring Boot** | `pom.xml`, `build.gradle(.kts)` | Stereotypes (`@RestController`, `@Service`, `@Repository`), DI (`@Autowired`), injection/call edges, `@PreAuthorize`/`@PermitAll`; SQLi, command injection, deserialization, SSRF, XSS, XXE; JWT/CORS/CSRF/cookie checks |
184
+ | **Python** | `pyproject.toml`, `requirements.txt`, `*.py` AST | FastAPI, Flask, Django, Celery; SQLAlchemy, Tortoise-ORM, asyncpg, pymongo; AST taint tracking from sources to dangerous execution sinks |
185
+ | **Infrastructure & IaC** | `docker-compose.yml`, `Dockerfile`, K8s, Terraform | Compose service ports & links; Dockerfile unpinned tags & root user; Kubernetes capabilities & security contexts; Terraform public ACLs |
186
+
187
+ ---
188
+
189
+ ## ๐Ÿ“ฆ Generated Artifacts
190
+
191
+ Preview a scan without writing files, or capture a structured CI summary:
192
+
193
+ ```bash
194
+ secdiagram --dir . --offline --dry-run --verbose
195
+ secdiagram --dir . --offline --output json --format json,sarif > scan-summary.json
196
+ ```
197
+
198
+ Progress stages appear on stderr. The summary reports parsed files, detected languages,
199
+ components, unresolved references and skipped paths. Use `--verbose` for diagnostic
200
+ details, and check `health.complete` in CI to detect partial coverage.
201
+ Image rendering defaults to local `mmdc`; HTTP rendering requires an explicit provider.
202
+ For large repositories, combine repeatable `--include`/`--exclude` filters with the
203
+ incremental cache and configurable input limits. See the [CLI reference](docs/CLI_REFERENCE.md).
204
+
205
+ The default formats are `json,md,mermaid`. Artifacts go to `<repo>/.secdiagram/` unless
206
+ `--out` is supplied. Select additional outputs using `--format` or the corresponding flags.
207
+
208
+ - `diagram-highlevel.mmd` / `.png` โ€” High-level C4 system tier diagram (`secdiagram.com` style).
209
+ - `diagram.mmd` / `.png` โ€” Detailed architecture flowchart and component relationships (taint paths highlighted in red).
210
+ - `diagram-taint.mmd` / `.png` โ€” Attack-path diagram: untrusted input โ†’ entry points โ†’ every function on the path โ†’ vulnerable sink.
211
+ - `ARCHITECTURE.md` โ€” Complete markdown architecture report with embedded diagrams and a risk-ranked "Fix first" table.
212
+ - `THREAT_MODEL.md` โ€” STRIDE threat model per trust boundary, backed by findings and their risk priority.
213
+ - `threat-model.json` โ€” Versioned source-backed observations and coverage context; compare versions with `secdiagram threat-diff before/threat-model.json after/threat-model.json`.
214
+ - `audit-result.json` โ€” Machine-readable ATT&CK audit result (`secdiagram audit --json`): policy, per-technique status/evidence, violations, evidence freshness, dependency report summaries/findings, and reviewed dependency violations.
215
+ - `graph.json` โ€” Machine-readable graph schema (nodes, edges, confidence, features, findings with hop-by-hop `metadata.flow` and `metadata.risk`); Pub inventory nodes and structured `dependency` details for Trivy/CycloneDX findings.
216
+ - `security.sarif` โ€” OASIS SARIF v2.1.0 code-scanning report with taint `codeFlows`; `rank` and `riskScore`/`riskPriority` follow the risk model, and dependency provenance is exposed in `properties.dependency`.
217
+ - `vex.json` โ€” CycloneDX 1.6 VEX document with automated reachability justifications, dependency components, in-triage/resolved states, and remediation properties.
218
+ - `report.html` โ€” Zero-dependency interactive HTML report with dark mode, filtering, and an "Attack paths" view.
219
+ - `SECURITY_REVIEW.md` / `security-report.html` โ€” Standalone security review (`--security-report md|html|both`) with an architecture security scorecard and facts-versus-judgments breakdown.
220
+ - `NARRATIVE.md` โ€” Optional evidence-grounded AI review (`--llm` / `--ollama`).
221
+ - `security.baseline.json` โ€” Accepted-findings baseline (`--create-baseline`, then `--baseline`).
222
+ - `backlog.json` / `BACKLOG.md` โ€” Correlated remediation backlog with owner, deterministic due date, risk decision, ticket, fix commit, and verification result (`--backlog`; requires `--backlog-as-of`).
223
+ - `jira-issues.json` / `gitlab-issues.json` / `github-issues.json` โ€” Offline import-ready tracker payloads.
224
+ - `evidence-snapshots/<snapshot_id>.json` โ€” Immutable, content-addressed evidence snapshot with report SHA-256 hashes (`--evidence-snapshot`).
225
+
226
+ ### Analysis coverage and evidence
227
+
228
+ `graph.json` records per-language source coverage in `meta.analysis.coverage`.
229
+ The denominator is recognized source files admitted by discovery. `indexed` counts
230
+ files with a built-in index, including partial indexes listed in `partial`.
231
+ `unindexed` lists admitted source files with no index. Discovery skips and parse
232
+ errors are tracked separately. `security_supported` indicates built-in heuristic
233
+ rule availability for a language. The scan-wide `security_enabled` flag records
234
+ whether those rules were enabled.
235
+
236
+ Graph schema version 1 remains readable by existing consumers. Check
237
+ `schema_features` for additive fields. `Graph.validation_errors()` checks graph
238
+ integrity, and the JSON CLI summary exposes diagnostics under `health`.
239
+
240
+ Finding provenance in graph JSON and SARIF records the detector, origin,
241
+ evidence locations, trace, and report name and external ID when available.
242
+ Validation starts at `unverified`. `advisory_corroborated` means a supplied
243
+ advisory matched the finding. `runtime_observed` means a supplied runtime
244
+ scanner reported the finding. These statuses describe the evidence
245
+ available to the scan.
246
+
247
+ Run `python -m tests.test_analysis_trust` for corpus precision and recall.
248
+ The metrics cover labeled fixture files and count unique category, path, and
249
+ primary line matches. See [corpus scope](tests/fixtures/security_corpus/README.md).
250
+
251
+ ### Application context and risk
252
+
253
+ `graph.json` and `threat-model.json` include an application inventory. API
254
+ records identify each method, route, handler, authentication marker, and source
255
+ location. A matched runtime report can mark a route as observed. Unknown auth
256
+ means the analyzer found no explicit marker.
257
+
258
+ The inventory records entry boundaries, evidenced graph relationships to data
259
+ or messaging assets, external code calls, and Compose dependencies on data
260
+ or messaging services. Compose relationships describe declared deployment
261
+ dependencies. Finding context links to inventory records, cites affected files,
262
+ and keeps recorded data-flow hops alongside any matching static call evidence.
263
+ The risk score lists its numeric factors and any advisory floor. A partial flow
264
+ receives less weight than a trace with both source and sink.
265
+
266
+ ---
267
+
268
+ ## ๐Ÿ“š Documentation Index
269
+
270
+ For comprehensive guides, references, and deployment patterns, see:
271
+
272
+ | Guide | Description |
273
+ | :--- | :--- |
274
+ | [**Architecture Diagrams & Image Rendering**](docs/ARCHITECTURE_DIAGRAMS.md) | C4 high-level diagrams, visual tiering, detail modes, PNG/SVG/PDF rendering, and providers. |
275
+ | [**Container & Docker Compose Guide**](docs/CONTAINER_AND_COMPOSE.md) | Standalone Docker & Podman, Windows Git Bash tips, SELinux mode, and local Ollama Compose. |
276
+ | [**Security, IaC & Runtime Evidence**](docs/SECURITY_AND_IAC.md) | SAST and interprocedural taint rules per language, web/API misconfiguration checks, risk model, STRIDE threat model, MITRE ATT&CK audit gate, attack-path diagram, IaC checks, SonarQube/Xray import, ZAP/Nuclei runtime DAST correlation, CycloneDX VEX. |
277
+ | [**Dependency Risk Correlation**](docs/DEPENDENCY_RISK_CORRELATION.md) | Offline Pub/Flutter inventory, Trivy/CycloneDX ingestion, SHA-256 evidence bundles, reviewed symbol gate, Pub advisory ranges, and remediation exports. |
278
+ | [**Rust / Axum / Actix Support**](docs/RUST_SUPPORT.md) | Supported syntax, Cargo inventory, evidence-backed rules, offline examples and coverage limits. |
279
+ | [**Threat Modeling & Diffs**](docs/THREAT_MODELING.md) | Facts versus assessments, source-linked STRIDE observations and version comparison. |
280
+ | [**Hardened Platform Server & REST API**](docs/SERVER_API.md) | Daemon mode (`secdiagram serve`), authentication, rate limits, request caps, and config schema. |
281
+ | [**Agentic Studio & AI-Skill Installer**](docs/STUDIO.md) | User-level install, portable agent skill, Studio UI, diagram overrides, SDLC evidence gates, handoffs, and local AI reviews. |
282
+ | [**CLI Reference Manual**](docs/CLI_REFERENCE.md) | Complete command-line syntax, options breakdown table, and exit codes. |
283
+ | [**Python Public Facade & Developer API**](docs/PYTHON_API.md) | Stable facade (`secdiagram_core`), taint/reachability queries, SCA bridge, and cache serialization. |
284
+ | [**Task Tracking Guide**](docs/TASK_TRACKING.md) | GitHub Issues & Projects v2 task lifecycle tracking with `taskctl.py`. |
285
+ | [**Test Contracts & Validation**](docs/TEST_VALIDATION.md) | Meaningful test conditions, isolated fault checks, cross-platform verification and known gaps. |
286
+ | [**SAST Accuracy Benchmarks**](docs/SAST_BENCHMARK.md) | Score secdiagram against OWASP Benchmark (Python/Java), Juliet/SARD and SecBench.js with a stdlib harness, then publish reproducible per-CWE scorecards. |
287
+
288
+ ---
289
+
290
+ ## ๐Ÿงช Verification & Testing
291
+
292
+ `secdiagram` maintains behavior-focused tests covering the supported application languages, including Rust and Dart/Flutter, plus infrastructure-as-code, interprocedural taint, misconfiguration rules, risk scoring, the STRIDE threat model and MITRE ATT&CK audit gate, Pub dependency inventory and correlation, offline evidence verification, graph builders, image rendering, and deterministic CLI behaviors. Related conditions use named subtests; full-content checks and positive/negative controls take precedence over assertion counts. CI runs the suite on Ubuntu **and** Windows for every supported Python version. See [test contracts and validation](docs/TEST_VALIDATION.md) for the inventory, fault checks and coverage limits.
293
+
294
+ ```bash
295
+ # Run unit test suite:
296
+ python -m unittest discover -s tests -v
297
+ ```
298
+
299
+ Detection accuracy is measured, not assumed. `scripts/benchmark_sast.py` scores a
300
+ SARIF report against an OWASP-style answer key and reports TPR, FPR and Youden J
301
+ overall and per CWE. See [SAST accuracy benchmarks](docs/SAST_BENCHMARK.md) for
302
+ the protocol, datasets and publication checklist.
303
+
304
+ ```bash
305
+ python scripts/benchmark_sast.py --sarif out/security.sarif \
306
+ --expected expectedresults-0.1.csv \
307
+ --benchmark-name "OWASP Benchmark for Python" --benchmark-version v0.1 \
308
+ --out-dir benchmarks/scorecards/owasp-python-0.1
309
+ ```
310
+
311
+ ---
312
+
313
+ ## ๐Ÿค Contributing & License
314
+
315
+ - **Contributing**: Please review [`CONTRIBUTING.md`](CONTRIBUTING.md) and [`AGENTS.md`](AGENTS.md) for architectural guardrails and commit conventions.
316
+ - **License**: Distributed under the **MIT License**. See [`LICENSE`](LICENSE) for details.
@@ -0,0 +1,285 @@
1
+ <div align="center">
2
+
3
+ # โšก secdiagram
4
+
5
+ ### *Small but Gold* โ€” Deterministic Architecture Diagrams, Polyglot System Mapping, and Security Intelligence.
6
+
7
+ [![Python](https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14%20%7C%203.15-blue.svg?style=flat-square&logo=python&logoColor=white)](https://python.org)
8
+ [![Zero Dependencies](https://img.shields.io/badge/Dependencies-Standard%20Library%20Only-success.svg?style=flat-square)](pyproject.toml)
9
+ [![Tests](https://github.com/vichhaiyserey/secdiagram/actions/workflows/ci.yml/badge.svg?branch=develop)](https://github.com/vichhaiyserey/secdiagram/actions/workflows/ci.yml?query=branch%3Adevelop)
10
+ [![Docker](https://img.shields.io/badge/Docker-Ready-2496ED.svg?style=flat-square&logo=docker&logoColor=white)](Dockerfile)
11
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](LICENSE)
12
+ [![Cross Platform](https://img.shields.io/badge/Platform-macOS%20%7C%20Ubuntu%20%7C%20RHEL%20%7C%20Windows-blueviolet.svg?style=flat-square)](docs/CONTAINER_AND_COMPOSE.md)
13
+
14
+ <p align="center">
15
+ <b>Transform codebases into clear, human-friendly system architecture diagrams, publication-quality images, security threat models, and AI reviews.</b><br>
16
+ <i>100% offline-first. Zero external Python runtime dependencies. Polyglot architecture and security analysis across <b>.NET (C#)</b>, <b>Java / Spring Boot</b>, <b>Node.js / TypeScript</b>, <b>PHP</b>, <b>Go</b>, <b>Rust</b>, <b>Dart / Flutter</b>, <b>Python</b>, and <b>Docker / Kubernetes / Terraform</b>.</i>
17
+ </p>
18
+
19
+ ---
20
+
21
+ </div>
22
+
23
+ ## ๐ŸŒŸ Key Highlights
24
+
25
+ - **Pure Python Standard Library (`zero dependencies`)**: Core analysis requires no third-party Python packages. Optional renderers and developer tools have separate pinned dependencies.
26
+ - **High-Level C4 System Diagrams**: Automatically compiles clean C4 tier diagrams (`diagram-highlevel.mmd` & `diagram-highlevel.png`) showing Ingress, Gateways, Core Services, Databases, Caches, Brokers, and External APIs.
27
+ - **Multi-Format Image Rendering**: Export diagrams directly to **PNG**, **SVG**, or **PDF** offline via bundled Mermaid CLI (`mmdc`) or zero-dependency HTTP fallbacks (Kroki, mermaid.ink).
28
+ - **Security & IaC SAST Overlay**: Discovers entrypoints, traces taint dataflows **across functions and files** (controller โ†’ service โ†’ repository) to dangerous sinks (CWE-78, CWE-89, CWE-502), draws them as an attack-path diagram, catches hardcoded secrets, and audits Dockerfile, Kubernetes, Terraform, and GitHub Actions configurations.
29
+ - **Runtime DAST Evidence Correlation**: Import OWASP ZAP Traditional JSON and Nuclei JSONL/JSON reports and deterministically match observed requests (HTTP method + templated path) to static endpoint nodes. Matched endpoints gain `runtime_observed` metadata, runtime-only endpoints are reported instead of invented, and runtime-confirmed critical/high findings can satisfy the strict policy reachability gate -- all without launching a scanner or making network calls.
30
+ - **Local Dependency Risk Correlation**: Builds a bounded offline Pub/Flutter inventory from `pubspec.yaml`, `pubspec.lock`, and `.dart_tool/package_config.json`, then correlates local Trivy and CycloneDX reports by scoped package and exact resolved version. Static imports and qualified package call paths supply reachability evidence, while a policy-owned reviewed symbol gate is required before a dependency finding can fail CI. Optional SHA-256 evidence bundles add reproducibility and freshness checks, and remediation details flow into Markdown, HTML, JSON, SARIF, and VEX. See [Dependency risk correlation](docs/DEPENDENCY_RISK_CORRELATION.md).
31
+ - **Web/API Misconfiguration Checks**: Flags broken JWT validation (`alg=none`, signature/expiry checks off), CORS that trusts any origin **with credentials**, disabled CSRF protection, cookies without `HttpOnly`/`Secure`, XXE-prone XML parsers, non-cryptographic RNGs used for tokens, and JS prototype pollution across C#, JS/TS, PHP, Go, and Java.
32
+ - **Risk-Ranked "Fix First" List**: Scores every finding 0โ€“10 by impact ร— exposure (anonymous, authenticated, or internal entry point, detected from framework auth markers) ร— evidence ร— confidence ร— CISA KEV, and groups them P0โ€“P3 in reports, SARIF, and diagrams.
33
+ - **STRIDE Threat Model**: Generates `THREAT_MODEL.md` and `threat-model.json` with affected components, assets, source evidence, static flows, severity/confidence, and verification steps. Facts and assessments are separated; `secdiagram threat-diff` compares saved versions offline. See [Threat modeling](docs/THREAT_MODELING.md).
34
+ - **Architecture Security Scorecard**: The standalone security review opens with a defensible verdict (`pass`, `conditional pass`, `fail`, or `insufficient evidence`), architecture and control posture, evidence-backed critical attack paths, design risks, and explicit coverage confidence. Facts and judgments are separate, and missing evidence is never reported as a pass.
35
+ - **MITRE ATT&CK Audit Gate**: `secdiagram audit <dir>` maps the parsed architecture to ATT&CK techniques (T1190 Exploit Public-Facing Application, T1040 Network Sniffing, T1552 Unsecured Credentials, โ€ฆ) with evidence and missing mitigations, and **fails CI/CD with exit code 1** when findings violate `policy.yaml` thresholds.
36
+ - **CycloneDX 1.6 VEX & SARIF Export**: Generates industry-standard `security.sarif` and CycloneDX 1.6 VEX documents (`vex.json`) with automated reachability justifications (`code_not_reachable`) for dead/internal code.
37
+ - **AI Architectural & Threat Modeling Reviews**: Integrates with local/containerized **Ollama (Qwen, LLaMA, DeepSeek)** or OpenAI endpoints to generate evidence-grounded architectural reviews citing exact `path:line` with zero hallucinations.
38
+ - **Agentic Studio & Portable AI Skill**: User-level installer with a private venv, portable launchers, and an agent skill manifest. The hardened Studio SPA adds interactive diagram overrides, a five-phase discover/model/secure/review/handoff state machine with evidence gates, executable handoff artifacts, and local-Ollama or OpenAI reviews -- all without adding a runtime dependency. See [Agentic Studio](docs/STUDIO.md).
39
+ - **100% Deterministic & Air-Gapped**: Byte-for-byte reproducible outputs across runs. Fully functional in offline, isolated, or air-gapped environments.
40
+
41
+ ---
42
+
43
+ ## ๐Ÿš€ Quick Start
44
+
45
+ New to secdiagram? Start with the [beginner guide](docs/BEGINNER_GUIDE.md) or
46
+ download the [printable PDF](docs/BEGINNER_GUIDE.pdf).
47
+
48
+ ### 1. Install and run (Python 3.10+)
49
+
50
+ Install the CLI in a virtual environment or run it directly from a source checkout.
51
+
52
+ ```bash
53
+ python -m pip install secdiagram
54
+ secdiagram --dir . --offline
55
+ ```
56
+
57
+ From a source checkout, the CLI requires only the Python standard library.
58
+
59
+ See [runtime prerequisites and evidence coverage](docs/RUNTIME_PREREQUISITES.md)
60
+ for operating permissions, optional renderers and AI providers, and current
61
+ vulnerability evidence.
62
+
63
+ ```bash
64
+ # Analyze current repository and generate detailed architecture diagrams:
65
+ python secdiagram.py --dir="."
66
+
67
+ # Generate both detailed and high-level C4 system diagrams with PNG images:
68
+ python secdiagram.py --dir="." --image
69
+
70
+ # Generate high-level system overview as primary diagram:
71
+ python secdiagram.py --dir="." --high-level --image
72
+
73
+ # Correlate local Trivy/CycloneDX evidence with the Pub inventory (offline):
74
+ python secdiagram.py --dir="." --offline --trivy-report trivy.json --sbom inventory.cdx.json --format json,sarif,vex
75
+
76
+ # ATT&CK audit gate for CI/CD - exits 1 on policy violations:
77
+ python secdiagram.py audit . --policy policy.yaml --json audit-result.json
78
+
79
+ # Strict audit against a SHA-256 verified evidence bundle:
80
+ python secdiagram.py audit . --offline --evidence-bundle evidence.json --require-evidence --json audit-result.json
81
+ ```
82
+
83
+ ### 2. Standalone Container Execution (Docker / Podman)
84
+
85
+ Run using the pre-built, hardened non-root container with bundled Chromium and Mermaid CLI:
86
+
87
+ ```bash
88
+ # Linux / macOS:
89
+ docker run --rm -v "$(pwd):/repo" secdiagram:local --image
90
+
91
+ # Windows PowerShell:
92
+ docker run --rm -v "${PWD}:/repo" secdiagram:local --image
93
+
94
+ # RHEL / Fedora (SELinux mode):
95
+ docker run --rm -v "$(pwd):/repo:z" secdiagram:local --image
96
+ ```
97
+
98
+ ### 3. Agentic Studio & Portable AI Skill
99
+
100
+ ```bash
101
+ # Install the user-level Studio home, launchers, and agent skill:
102
+ python secdiagram.py studio install
103
+
104
+ # Serve the Studio on loopback with authentication:
105
+ python secdiagram.py studio serve --dir . --user analyst --password 'change-me'
106
+ ```
107
+
108
+ Open `http://127.0.0.1:8080/studio` to edit diagrams, drive the SDLC phases, request local AI
109
+ reviews, investigate findings, and generate handoff artifacts. The installer is CLI-only; the Studio reuses the
110
+ hardened platform server. See the [Agentic Studio guide](docs/STUDIO.md).
111
+
112
+ ### 4. Python Public Facade
113
+
114
+ Integrate directly into custom automation scripts or DevSecOps pipelines:
115
+
116
+ ```python
117
+ from secdiagram_core import analyze, render_mermaid, AnalysisConfig
118
+
119
+ result = analyze(AnalysisConfig(root=".", security=True))
120
+ print(f"Discovered {len(result.graph.nodes)} nodes and {len(result.graph.findings)} findings.")
121
+
122
+ # Native taint and package reachability query:
123
+ if result.has_taint_at("app/api.py", line=42):
124
+ print("Tainted dataflow detected at line 42!")
125
+
126
+ # Correlate runtime DAST evidence with the static endpoint graph:
127
+ runtime = analyze(
128
+ AnalysisConfig(root=".", zap_report="zap.json", nuclei_report="nuclei.jsonl")
129
+ )
130
+ print(runtime.graph.meta["runtime_analysis"]["matched_requests"], "runtime requests matched")
131
+
132
+ # Correlate local Pub inventory with Trivy and CycloneDX evidence:
133
+ deps = analyze(
134
+ AnalysisConfig(root=".", trivy_report="trivy.json", sbom="inventory.cdx.json")
135
+ )
136
+ print(deps.graph.meta["dependency_reports"])
137
+ ```
138
+
139
+ ---
140
+
141
+ ## ๐Ÿ”€ Supported Ecosystems
142
+
143
+ | Ecosystem | Manifests Inspected | Architectural & Security Elements Detected |
144
+ | :--- | :--- | :--- |
145
+ | **.NET (C#)** | `*.sln`, `*.csproj`, `*.fsproj`, `*.cs` | Project metadata and C# source indexing for ASP.NET Core, EF Core, and MediatR. Selected taint and configuration checks. |
146
+ | **Node.js / TypeScript** | `package.json`, workspaces, `schema.prisma`, `*.js`/`*.ts` | Express, Fastify, Koa, Hono, NestJS, Next.js routes & auth middleware; Prisma, TypeORM, Mongoose; interprocedural taint to SQL/NoSQL, `child_process`, `eval`, XSS, path, SSRF sinks; prototype pollution; JWT/CORS/cookie checks |
147
+ | **PHP** | `composer.json`, `*.php` | Laravel routes & middleware, Symfony `#[Route]`/`#[IsGranted]`, Slim, legacy page scripts; constructor DI; taint to SQL, `system`/`exec`, `include`, `unserialize`, XSS, path, SSRF; CSRF/CORS/cookie/XXE checks |
148
+ | **Go** | `go.mod`, `*.go` | `net/http` (incl. Go 1.22 `"GET /path"`), Gin, Echo, Chi routes & auth middleware; structs, receiver methods, `NewX` injection; taint to SQL, `exec.Command`, path, SSRF, XSS; JWT/CORS/cookie/TLS checks |
149
+ | **Dart / Flutter** | `pubspec.yaml`, `pubspec.lock`, `.dart_tool/package_config.json`, `*.dart` | Flutter widgets, services, repositories, GoRouter/Shelf routes; Pub direct/dev/transitive inventory with resolved versions and scopes; interprocedural taint to SQLite, `Process.run`, WebView JS/HTML, filesystem and HTTP sinks; TLS and weak-crypto checks; Trivy/CycloneDX advisory correlation. |
150
+ | **Rust** | `Cargo.toml`, `*.rs` | Structs/enums/traits, `impl` methods, Axum router and Actix attribute routes; request-to-SQLx, shell-command, filesystem and HTTP sink evidence; TLS/CORS and selected non-cryptographic RNG checks. Lexical coverage and limits: [Rust support](docs/RUST_SUPPORT.md). |
151
+ | **Swift / iOS** | `*.swift`, Xcode projects, SwiftPM manifests and pins, CocoaPods manifests and locks, plists and localization resources | SwiftUI app and view structure, MVVM relationships, SwiftData models, framework imports, dependencies, and selected iOS release-configuration findings. [Swift support](docs/SWIFT_SUPPORT.md). |
152
+ | **Java / Spring Boot** | `pom.xml`, `build.gradle(.kts)` | Stereotypes (`@RestController`, `@Service`, `@Repository`), DI (`@Autowired`), injection/call edges, `@PreAuthorize`/`@PermitAll`; SQLi, command injection, deserialization, SSRF, XSS, XXE; JWT/CORS/CSRF/cookie checks |
153
+ | **Python** | `pyproject.toml`, `requirements.txt`, `*.py` AST | FastAPI, Flask, Django, Celery; SQLAlchemy, Tortoise-ORM, asyncpg, pymongo; AST taint tracking from sources to dangerous execution sinks |
154
+ | **Infrastructure & IaC** | `docker-compose.yml`, `Dockerfile`, K8s, Terraform | Compose service ports & links; Dockerfile unpinned tags & root user; Kubernetes capabilities & security contexts; Terraform public ACLs |
155
+
156
+ ---
157
+
158
+ ## ๐Ÿ“ฆ Generated Artifacts
159
+
160
+ Preview a scan without writing files, or capture a structured CI summary:
161
+
162
+ ```bash
163
+ secdiagram --dir . --offline --dry-run --verbose
164
+ secdiagram --dir . --offline --output json --format json,sarif > scan-summary.json
165
+ ```
166
+
167
+ Progress stages appear on stderr. The summary reports parsed files, detected languages,
168
+ components, unresolved references and skipped paths. Use `--verbose` for diagnostic
169
+ details, and check `health.complete` in CI to detect partial coverage.
170
+ Image rendering defaults to local `mmdc`; HTTP rendering requires an explicit provider.
171
+ For large repositories, combine repeatable `--include`/`--exclude` filters with the
172
+ incremental cache and configurable input limits. See the [CLI reference](docs/CLI_REFERENCE.md).
173
+
174
+ The default formats are `json,md,mermaid`. Artifacts go to `<repo>/.secdiagram/` unless
175
+ `--out` is supplied. Select additional outputs using `--format` or the corresponding flags.
176
+
177
+ - `diagram-highlevel.mmd` / `.png` โ€” High-level C4 system tier diagram (`secdiagram.com` style).
178
+ - `diagram.mmd` / `.png` โ€” Detailed architecture flowchart and component relationships (taint paths highlighted in red).
179
+ - `diagram-taint.mmd` / `.png` โ€” Attack-path diagram: untrusted input โ†’ entry points โ†’ every function on the path โ†’ vulnerable sink.
180
+ - `ARCHITECTURE.md` โ€” Complete markdown architecture report with embedded diagrams and a risk-ranked "Fix first" table.
181
+ - `THREAT_MODEL.md` โ€” STRIDE threat model per trust boundary, backed by findings and their risk priority.
182
+ - `threat-model.json` โ€” Versioned source-backed observations and coverage context; compare versions with `secdiagram threat-diff before/threat-model.json after/threat-model.json`.
183
+ - `audit-result.json` โ€” Machine-readable ATT&CK audit result (`secdiagram audit --json`): policy, per-technique status/evidence, violations, evidence freshness, dependency report summaries/findings, and reviewed dependency violations.
184
+ - `graph.json` โ€” Machine-readable graph schema (nodes, edges, confidence, features, findings with hop-by-hop `metadata.flow` and `metadata.risk`); Pub inventory nodes and structured `dependency` details for Trivy/CycloneDX findings.
185
+ - `security.sarif` โ€” OASIS SARIF v2.1.0 code-scanning report with taint `codeFlows`; `rank` and `riskScore`/`riskPriority` follow the risk model, and dependency provenance is exposed in `properties.dependency`.
186
+ - `vex.json` โ€” CycloneDX 1.6 VEX document with automated reachability justifications, dependency components, in-triage/resolved states, and remediation properties.
187
+ - `report.html` โ€” Zero-dependency interactive HTML report with dark mode, filtering, and an "Attack paths" view.
188
+ - `SECURITY_REVIEW.md` / `security-report.html` โ€” Standalone security review (`--security-report md|html|both`) with an architecture security scorecard and facts-versus-judgments breakdown.
189
+ - `NARRATIVE.md` โ€” Optional evidence-grounded AI review (`--llm` / `--ollama`).
190
+ - `security.baseline.json` โ€” Accepted-findings baseline (`--create-baseline`, then `--baseline`).
191
+ - `backlog.json` / `BACKLOG.md` โ€” Correlated remediation backlog with owner, deterministic due date, risk decision, ticket, fix commit, and verification result (`--backlog`; requires `--backlog-as-of`).
192
+ - `jira-issues.json` / `gitlab-issues.json` / `github-issues.json` โ€” Offline import-ready tracker payloads.
193
+ - `evidence-snapshots/<snapshot_id>.json` โ€” Immutable, content-addressed evidence snapshot with report SHA-256 hashes (`--evidence-snapshot`).
194
+
195
+ ### Analysis coverage and evidence
196
+
197
+ `graph.json` records per-language source coverage in `meta.analysis.coverage`.
198
+ The denominator is recognized source files admitted by discovery. `indexed` counts
199
+ files with a built-in index, including partial indexes listed in `partial`.
200
+ `unindexed` lists admitted source files with no index. Discovery skips and parse
201
+ errors are tracked separately. `security_supported` indicates built-in heuristic
202
+ rule availability for a language. The scan-wide `security_enabled` flag records
203
+ whether those rules were enabled.
204
+
205
+ Graph schema version 1 remains readable by existing consumers. Check
206
+ `schema_features` for additive fields. `Graph.validation_errors()` checks graph
207
+ integrity, and the JSON CLI summary exposes diagnostics under `health`.
208
+
209
+ Finding provenance in graph JSON and SARIF records the detector, origin,
210
+ evidence locations, trace, and report name and external ID when available.
211
+ Validation starts at `unverified`. `advisory_corroborated` means a supplied
212
+ advisory matched the finding. `runtime_observed` means a supplied runtime
213
+ scanner reported the finding. These statuses describe the evidence
214
+ available to the scan.
215
+
216
+ Run `python -m tests.test_analysis_trust` for corpus precision and recall.
217
+ The metrics cover labeled fixture files and count unique category, path, and
218
+ primary line matches. See [corpus scope](tests/fixtures/security_corpus/README.md).
219
+
220
+ ### Application context and risk
221
+
222
+ `graph.json` and `threat-model.json` include an application inventory. API
223
+ records identify each method, route, handler, authentication marker, and source
224
+ location. A matched runtime report can mark a route as observed. Unknown auth
225
+ means the analyzer found no explicit marker.
226
+
227
+ The inventory records entry boundaries, evidenced graph relationships to data
228
+ or messaging assets, external code calls, and Compose dependencies on data
229
+ or messaging services. Compose relationships describe declared deployment
230
+ dependencies. Finding context links to inventory records, cites affected files,
231
+ and keeps recorded data-flow hops alongside any matching static call evidence.
232
+ The risk score lists its numeric factors and any advisory floor. A partial flow
233
+ receives less weight than a trace with both source and sink.
234
+
235
+ ---
236
+
237
+ ## ๐Ÿ“š Documentation Index
238
+
239
+ For comprehensive guides, references, and deployment patterns, see:
240
+
241
+ | Guide | Description |
242
+ | :--- | :--- |
243
+ | [**Architecture Diagrams & Image Rendering**](docs/ARCHITECTURE_DIAGRAMS.md) | C4 high-level diagrams, visual tiering, detail modes, PNG/SVG/PDF rendering, and providers. |
244
+ | [**Container & Docker Compose Guide**](docs/CONTAINER_AND_COMPOSE.md) | Standalone Docker & Podman, Windows Git Bash tips, SELinux mode, and local Ollama Compose. |
245
+ | [**Security, IaC & Runtime Evidence**](docs/SECURITY_AND_IAC.md) | SAST and interprocedural taint rules per language, web/API misconfiguration checks, risk model, STRIDE threat model, MITRE ATT&CK audit gate, attack-path diagram, IaC checks, SonarQube/Xray import, ZAP/Nuclei runtime DAST correlation, CycloneDX VEX. |
246
+ | [**Dependency Risk Correlation**](docs/DEPENDENCY_RISK_CORRELATION.md) | Offline Pub/Flutter inventory, Trivy/CycloneDX ingestion, SHA-256 evidence bundles, reviewed symbol gate, Pub advisory ranges, and remediation exports. |
247
+ | [**Rust / Axum / Actix Support**](docs/RUST_SUPPORT.md) | Supported syntax, Cargo inventory, evidence-backed rules, offline examples and coverage limits. |
248
+ | [**Threat Modeling & Diffs**](docs/THREAT_MODELING.md) | Facts versus assessments, source-linked STRIDE observations and version comparison. |
249
+ | [**Hardened Platform Server & REST API**](docs/SERVER_API.md) | Daemon mode (`secdiagram serve`), authentication, rate limits, request caps, and config schema. |
250
+ | [**Agentic Studio & AI-Skill Installer**](docs/STUDIO.md) | User-level install, portable agent skill, Studio UI, diagram overrides, SDLC evidence gates, handoffs, and local AI reviews. |
251
+ | [**CLI Reference Manual**](docs/CLI_REFERENCE.md) | Complete command-line syntax, options breakdown table, and exit codes. |
252
+ | [**Python Public Facade & Developer API**](docs/PYTHON_API.md) | Stable facade (`secdiagram_core`), taint/reachability queries, SCA bridge, and cache serialization. |
253
+ | [**Task Tracking Guide**](docs/TASK_TRACKING.md) | GitHub Issues & Projects v2 task lifecycle tracking with `taskctl.py`. |
254
+ | [**Test Contracts & Validation**](docs/TEST_VALIDATION.md) | Meaningful test conditions, isolated fault checks, cross-platform verification and known gaps. |
255
+ | [**SAST Accuracy Benchmarks**](docs/SAST_BENCHMARK.md) | Score secdiagram against OWASP Benchmark (Python/Java), Juliet/SARD and SecBench.js with a stdlib harness, then publish reproducible per-CWE scorecards. |
256
+
257
+ ---
258
+
259
+ ## ๐Ÿงช Verification & Testing
260
+
261
+ `secdiagram` maintains behavior-focused tests covering the supported application languages, including Rust and Dart/Flutter, plus infrastructure-as-code, interprocedural taint, misconfiguration rules, risk scoring, the STRIDE threat model and MITRE ATT&CK audit gate, Pub dependency inventory and correlation, offline evidence verification, graph builders, image rendering, and deterministic CLI behaviors. Related conditions use named subtests; full-content checks and positive/negative controls take precedence over assertion counts. CI runs the suite on Ubuntu **and** Windows for every supported Python version. See [test contracts and validation](docs/TEST_VALIDATION.md) for the inventory, fault checks and coverage limits.
262
+
263
+ ```bash
264
+ # Run unit test suite:
265
+ python -m unittest discover -s tests -v
266
+ ```
267
+
268
+ Detection accuracy is measured, not assumed. `scripts/benchmark_sast.py` scores a
269
+ SARIF report against an OWASP-style answer key and reports TPR, FPR and Youden J
270
+ overall and per CWE. See [SAST accuracy benchmarks](docs/SAST_BENCHMARK.md) for
271
+ the protocol, datasets and publication checklist.
272
+
273
+ ```bash
274
+ python scripts/benchmark_sast.py --sarif out/security.sarif \
275
+ --expected expectedresults-0.1.csv \
276
+ --benchmark-name "OWASP Benchmark for Python" --benchmark-version v0.1 \
277
+ --out-dir benchmarks/scorecards/owasp-python-0.1
278
+ ```
279
+
280
+ ---
281
+
282
+ ## ๐Ÿค Contributing & License
283
+
284
+ - **Contributing**: Please review [`CONTRIBUTING.md`](CONTRIBUTING.md) and [`AGENTS.md`](AGENTS.md) for architectural guardrails and commit conventions.
285
+ - **License**: Distributed under the **MIT License**. See [`LICENSE`](LICENSE) for details.