--- name: dfd description: DFD with trust boundaries + data classifications (Mermaid + optional Threat Dragon JSON). Source-of-truth for /threat-model. argument-hint: "[project-name | . | --scope-all] [--format=mermaid|dragon|all]" allowed-tools: Bash, Read, Grep, Glob, Write, AskUserQuestion --- # /dfd — Data Flow Diagram Extractor Read `.claude/rules/writing-standard.md`. Use the **controlled technical writing profile** for the DFD and accompanying explanation. Keep classifications and uncertainty explicit. Reads a codebase (or a portfolio of codebases for system-wide DFDs) and produces a Data Flow Diagram showing external actors, processes, data stores, data flows, trust boundaries, and per-element data classifications. The DFD is the **input to STRIDE threat modelling** and to GDPR cross-border / DPA-coverage analysis. This skill is the **canonical DFD producer** in the apexyard family. `/threat-model` and `/compliance-check` consume the DFD it writes instead of regenerating their own — see AgDR-0026 for the design rationale. | Skill | Role | |-------|------| | `/dfd` (this skill) | Produces the DFD — six-axis discovery + classifications + cross-repo trace | | `/threat-model` | Consumes the DFD — STRIDE walk over each trust-boundary crossing | | `/compliance-check` | Consumes the DFD's classifications — cross-border transfers + DPA coverage | | `/c4` | Static topology (different shape — system + containers, no data-flow semantics) | | `/process` (#256) | Dynamic control flow — BPMN, anchor-scoped multi-repo trace (shares the `_lib-multi-repo-trace.sh` helper) | ## Path resolution Read the registry path via `portfolio_registry`, the per-project docs dir via `portfolio_projects_dir`, and the workspace dir via `portfolio_workspace_dir` from `.claude/hooks/_lib-portfolio-paths.sh`. Cross-repo discovery uses the shared `_lib-multi-repo-trace.sh` helper. Source both at the top of any bash block: ```bash source "$(git rev-parse --show-toplevel)/.claude/hooks/_lib-read-config.sh" source "$(git rev-parse --show-toplevel)/.claude/hooks/_lib-portfolio-paths.sh" source "$(git rev-parse --show-toplevel)/.claude/hooks/_lib-multi-repo-trace.sh" projects_dir=$(portfolio_projects_dir) ``` Defaults match today's single-fork layout. Adopters in split-portfolio mode override the `portfolio.*` keys in `.claude/project-config.json` — the helper resolves whichever mode they're in. See `docs/multi-project.md`. ## Usage ``` /dfd # interactive — asks for scope (single service or system-wide) /dfd billing-api # registered project — single-service DFD /dfd . # treat cwd as the project root /dfd --scope-all # walk the whole registry — system-wide DFD with per-service sub-models /dfd billing-api --format=dragon # also emit Threat Dragon v2 JSON /dfd billing-api --format=all # Mermaid + Threat Dragon + (future) PlantUML ``` Re-running on the same scope OFFERS (default-no) to overwrite — same UX as `/extract-features` and `/c4`. Existing edits are preserved unless the operator explicitly accepts. ## Output location ``` projects//architecture/dfd.md ← Mermaid markdown (primary, source of truth) projects//architecture/dfd.json ← Threat Dragon v2 JSON (on --format=dragon) projects//architecture/dfd-source.yaml ← discovery report — supports "what changed since last run" ``` For `--scope-all`: ``` docs/architecture/system-dfd.md ← composed system-wide DFD docs/architecture/system-dfd-source.yaml ← per-service discovery reports concatenated ``` ## Process Use `AskUserQuestion` for every operator option menu in this skill. Follow `.claude/rules/reporting-style.md § Operator choices`. Keep single yes/no and ticket confirmation prompts as written. The prose menus below are fallbacks only when the harness lacks `AskUserQuestion`. ### 1. Resolve the target + scope - If the argument is `.` → use cwd as the target. - If the argument names a registered project → resolve to `workspace//`. If the workspace clone doesn't exist, stop and ask the operator to clone first (do not auto-clone — same convention as `/handover` and `/extract-features`). - If no argument and cwd is inside `workspace//` → use that project. - If no argument and cwd is the ops fork root → ask: *"Scope this DFD to one service, or the whole system?"* - If `--scope-all` → walk every registered project; each becomes a trust-boundary box in the composed system DFD. ### 2. Run the six-axis discovery (read-only) Discovery is anchored on the target and reachability-bounded. **No files written until the operator approves the candidate model.** | Axis | What | How | |------|------|-----| | **1. External actors** | Users, auth providers, third-party SaaS, admin consoles | HTTP route scope (anonymous / authenticated / admin); SDK imports (`stripe`, `@sendgrid/mail`, `@anthropic-ai/sdk`); auth provider imports (`@auth0`, `@clerk/`, Cognito); webhook signature handlers | | **2. Processes** | HTTP handlers, queue consumers, scheduled jobs, message-broker subscribers, gRPC methods | Framework signatures (Express / Fastify / NestJS / FastAPI / Flask / Django / Rails / Gin / Spring / Lambda); job-framework signatures (BullMQ, Celery, Sidekiq, Active Job, Temporal); cron / EventBridge schedules | | **3. Data stores** | RDBMSes, document stores, caches, object storage, file systems, data warehouses, search indexes | Schema files (`schema.prisma`, `models.py`, `*.rb` Active Record, `*.sql` migrations); SDK imports (`@aws-sdk/client-*`, `ioredis`, `mongoose`); connection-string env vars | | **4. Data flows** | What crosses what — payload + arrow direction | Reachability — handler reads/writes which store, calls which external API, enqueues to which worker. LSP-aware path uses call-graph; grep fallback uses imports + usage co-location | | **5. Trust boundaries** | Network / auth / org / classification boundaries | Inferred from code + env config: public ↔ backend (HTTP scope), backend ↔ data (DB credentials gating), user ↔ admin (route prefix), us ↔ third-party (external SDKs). **Note**: IaC reading is out of scope for v1 | | **6. Data classifications** | PII, PCI, secrets, internal, public — per detected element | Three pathways: code annotations (`@PII`, `// CLASSIFIED: