# azure/counterfit architecture

> Architecture diagram of the GitHub repository azure/counterfit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure/counterfit
- Repository: https://github.com/azure/counterfit

## Overview

Counterfit is a machine-learning security assessment tool that provides a common interface to adversarial attack frameworks. The principal workflow is to create or select a target, build and run an attack against it, then inspect attack results and reports. Framework integrations include ART, AugLy, and TextAttack; target examples cover image, text, tabular, and reinforcement-learning workloads. The graph reflects documented workflow and source-index references; unsampled implementation details are not inferred as definite call paths.

Main entry points: [`counterfit/core/targets.py`](https://github.com/azure/counterfit/blob/main/counterfit/core/targets.py) (Target Interface), [`counterfit/core/core.py`](https://github.com/azure/counterfit/blob/main/counterfit/core/core.py) (Assessment Orchestrator), [`counterfit/core/attacks.py`](https://github.com/azure/counterfit/blob/main/counterfit/core/attacks.py) (Attack Run State), [`counterfit/core/reporting.py`](https://github.com/azure/counterfit/blob/main/counterfit/core/reporting.py) (Report Aggregation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Assessment Core"]
  node_counterfit["Assessment Orchestrator<br/>[core.py]"]
  node_attack["Attack Run State<br/>[attacks.py]"]
  node_options["Attack Options<br/>[options.py]"]
  node_framework_base["Framework Contract<br/>[frameworks.py]"]
  node_logger["Query Logger<br/>[logger.py]"]
  node_optimizer["Parameter Optimizer<br/>[optimize.py]"]
end

subgraph group_frameworks["Attack Frameworks"]
  node_art["ART Integration<br/>[art.py]"]
  node_augly["AugLy Integration<br/>[augly.py]"]
  node_textattack["TextAttack Integration<br/>[textattack.py]"]
end

subgraph group_targets["Model Targets"]
  node_target_api["Target Interface<br/>[targets.py]"]
  node_image_targets["Image Targets<br/>[digits_keras.py]"]
  node_text_target["Review Target<br/>[movie_reviews.py]"]
  node_tabular_targets["Tabular Targets<br/>[creditfraud.py]"]
  node_cartpole_target["Cart-Pole Target<br/>[cart_pole.py]"]
end

subgraph group_results["Results and Reporting"]
  node_reporting_core["Report Aggregation<br/>[reporting.py]"]
  node_image_reporting["Image Reports<br/>[image.py]"]
  node_tabular_reporting["Tabular Reports<br/>[tabular.py]"]
  node_text_reporting["Text Reports<br/>[text.py]"]
  node_output["Console Output<br/>[output.py]"]
end

node_user(("Engineer"))

node_user -->|"starts assessment"| node_counterfit
node_counterfit -->|"builds target"| node_target_api
node_counterfit -->|"builds attack"| node_attack
node_counterfit -->|"discovers frameworks"| node_framework_base
node_counterfit -->|"configures attack"| node_options
node_counterfit -->|"runs framework"| node_attack
node_attack -->|"gets samples"| node_target_api
node_attack -->|"gets labels"| node_target_api
node_attack -->|"reads options"| node_options
node_attack -->|"creates logger"| node_logger
node_art -->|"wraps target"| node_target_api
node_augly -->|"uses target"| node_target_api
node_textattack -.->|"implements contract"| node_framework_base
node_image_targets -->|"implements target"| node_target_api
node_text_target -->|"implements target"| node_target_api
node_tabular_targets -->|"implements target"| node_target_api
node_cartpole_target -->|"implements target"| node_target_api
node_image_reporting -->|"extends reports"| node_reporting_core
node_tabular_reporting -->|"extends reports"| node_reporting_core
node_text_reporting -->|"extends reports"| node_reporting_core
node_reporting_core -->|"prints summaries"| node_output
node_image_reporting -->|"prints results"| node_output
node_counterfit -.->|"optimizes parameters"| node_optimizer

click node_counterfit "https://github.com/azure/counterfit/blob/main/counterfit/core/core.py"
click node_attack "https://github.com/azure/counterfit/blob/main/counterfit/core/attacks.py"
click node_options "https://github.com/azure/counterfit/blob/main/counterfit/core/options.py"
click node_framework_base "https://github.com/azure/counterfit/blob/main/counterfit/core/frameworks.py"
click node_logger "https://github.com/azure/counterfit/blob/main/counterfit/core/logger.py"
click node_optimizer "https://github.com/azure/counterfit/blob/main/counterfit/core/optimize.py"
click node_art "https://github.com/azure/counterfit/blob/main/counterfit/frameworks/art/art.py"
click node_augly "https://github.com/azure/counterfit/blob/main/counterfit/frameworks/augly/augly.py"
click node_textattack "https://github.com/azure/counterfit/blob/main/counterfit/frameworks/textattack/textattack.py"
click node_target_api "https://github.com/azure/counterfit/blob/main/counterfit/core/targets.py"
click node_image_targets "https://github.com/azure/counterfit/blob/main/counterfit/targets/digits_keras.py"
click node_text_target "https://github.com/azure/counterfit/blob/main/counterfit/targets/movie_reviews.py"
click node_tabular_targets "https://github.com/azure/counterfit/blob/main/counterfit/targets/creditfraud.py"
click node_cartpole_target "https://github.com/azure/counterfit/blob/main/counterfit/targets/cart_pole/cart_pole.py"
click node_reporting_core "https://github.com/azure/counterfit/blob/main/counterfit/core/reporting.py"
click node_image_reporting "https://github.com/azure/counterfit/blob/main/counterfit/reporting/image.py"
click node_tabular_reporting "https://github.com/azure/counterfit/blob/main/counterfit/reporting/tabular.py"
click node_text_reporting "https://github.com/azure/counterfit/blob/main/counterfit/reporting/text.py"
click node_output "https://github.com/azure/counterfit/blob/main/counterfit/core/output.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_counterfit,node_attack,node_options,node_framework_base,node_logger,node_optimizer toneBlue
class node_art,node_augly,node_textattack toneAmber
class node_target_api,node_image_targets,node_text_target,node_tabular_targets,node_cartpole_target toneMint
class node_reporting_core,node_image_reporting,node_tabular_reporting,node_text_reporting,node_output toneRose
class node_user toneIndigo
```

## Components

### Assessment Core

- [Assessment Orchestrator](https://github.com/azure/counterfit/blob/main/counterfit/core/core.py): `counterfit/core/core.py`
- [Attack Run State](https://github.com/azure/counterfit/blob/main/counterfit/core/attacks.py): `counterfit/core/attacks.py`
- [Attack Options](https://github.com/azure/counterfit/blob/main/counterfit/core/options.py): `counterfit/core/options.py`
- [Framework Contract](https://github.com/azure/counterfit/blob/main/counterfit/core/frameworks.py): `counterfit/core/frameworks.py`
- [Query Logger](https://github.com/azure/counterfit/blob/main/counterfit/core/logger.py): `counterfit/core/logger.py`
- [Parameter Optimizer](https://github.com/azure/counterfit/blob/main/counterfit/core/optimize.py): `counterfit/core/optimize.py`

### Attack Frameworks

- [ART Integration](https://github.com/azure/counterfit/blob/main/counterfit/frameworks/art/art.py): `counterfit/frameworks/art/art.py`
- [AugLy Integration](https://github.com/azure/counterfit/blob/main/counterfit/frameworks/augly/augly.py): `counterfit/frameworks/augly/augly.py`
- [TextAttack Integration](https://github.com/azure/counterfit/blob/main/counterfit/frameworks/textattack/textattack.py): `counterfit/frameworks/textattack/textattack.py`

### Model Targets

- [Target Interface](https://github.com/azure/counterfit/blob/main/counterfit/core/targets.py): `counterfit/core/targets.py`
- [Image Targets](https://github.com/azure/counterfit/blob/main/counterfit/targets/digits_keras.py): `counterfit/targets/digits_keras.py`
- [Review Target](https://github.com/azure/counterfit/blob/main/counterfit/targets/movie_reviews.py): `counterfit/targets/movie_reviews.py`
- [Tabular Targets](https://github.com/azure/counterfit/blob/main/counterfit/targets/creditfraud.py): `counterfit/targets/creditfraud.py`
- [Cart-Pole Target](https://github.com/azure/counterfit/blob/main/counterfit/targets/cart_pole/cart_pole.py): `counterfit/targets/cart_pole/cart_pole.py`

### Results and Reporting

- [Report Aggregation](https://github.com/azure/counterfit/blob/main/counterfit/core/reporting.py): `counterfit/core/reporting.py`
- [Image Reports](https://github.com/azure/counterfit/blob/main/counterfit/reporting/image.py): `counterfit/reporting/image.py`
- [Tabular Reports](https://github.com/azure/counterfit/blob/main/counterfit/reporting/tabular.py): `counterfit/reporting/tabular.py`
- [Text Reports](https://github.com/azure/counterfit/blob/main/counterfit/reporting/text.py): `counterfit/reporting/text.py`
- [Console Output](https://github.com/azure/counterfit/blob/main/counterfit/core/output.py): `counterfit/core/output.py`

### Other components

- **Engineer**

## Connections

- Engineer → Assessment Orchestrator: starts assessment
- Assessment Orchestrator → Target Interface: builds target (evidence: `counterfit/core/core.py`)
- Assessment Orchestrator → Attack Run State: builds attack (evidence: `counterfit/core/core.py`)
- Assessment Orchestrator → Framework Contract: discovers frameworks (evidence: `counterfit/core/core.py`)
- Assessment Orchestrator → Attack Options: configures attack (evidence: `counterfit/core/core.py`)
- Assessment Orchestrator → Attack Run State: runs framework (evidence: `counterfit/core/core.py`)
- Attack Run State → Target Interface: gets samples (evidence: `counterfit/core/attacks.py`)
- Attack Run State → Target Interface: gets labels (evidence: `counterfit/core/attacks.py`)
- Attack Run State → Attack Options: reads options (evidence: `counterfit/core/attacks.py`)
- Attack Run State → Query Logger: creates logger (evidence: `counterfit/core/attacks.py`)
- ART Integration → Target Interface: wraps target (evidence: `counterfit/frameworks/art/art.py`)
- AugLy Integration → Target Interface: uses target (evidence: `counterfit/frameworks/augly/augly.py`)
- TextAttack Integration → Framework Contract: implements contract (evidence: `counterfit/frameworks/textattack/textattack.py`)
- Image Targets → Target Interface: implements target (evidence: `counterfit/targets/digits_keras.py`)
- Review Target → Target Interface: implements target (evidence: `counterfit/targets/movie_reviews.py`)
- Tabular Targets → Target Interface: implements target (evidence: `counterfit/targets/creditfraud.py`)
- Cart-Pole Target → Target Interface: implements target (evidence: `counterfit/targets/cart_pole/cart_pole.py`)
- Image Reports → Report Aggregation: extends reports (evidence: `counterfit/reporting/image.py`)
- Tabular Reports → Report Aggregation: extends reports (evidence: `counterfit/reporting/tabular.py`)
- Text Reports → Report Aggregation: extends reports (evidence: `counterfit/reporting/text.py`)
- Report Aggregation → Console Output: prints summaries (evidence: `counterfit/core/reporting.py`)
- Image Reports → Console Output: prints results (evidence: `counterfit/reporting/image.py`)
- Assessment Orchestrator → Parameter Optimizer: optimizes parameters
