# harshithreddy01/redos-analyzer architecture

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

- Interactive diagram: https://gitdiagram.com/harshithreddy01/redos-analyzer
- Repository: https://github.com/harshithreddy01/redos-analyzer

## Overview

redos-analyzer is a Python ReDoS static-analysis tool with an API, a PyPI package-scanning workflow, and a report-driven fix generator. The main user workflow parses regexes and analyzes their `sre_parse` AST, classifies warning severity and exploitability, then suggests atomic-group fixes and verifies them. The package scanner downloads source distributions, extracts regex calls and context, and writes findings and summaries; the fixer consumes the findings report and writes verified fix results. The analyzer is a monolithic module, so its distinct analysis and repair responsibilities share a source path. Unsampled implementation details are omitted.

Main entry points: [`scan_pypi.py`](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py) (Package Scan), [`generate_fixes.py`](https://github.com/harshithreddy01/redos-analyzer/blob/master/generate_fixes.py) (Fix Runner), [`redos_analyzer.py`](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py) (Analyze Patterns), [`redos_report.csv`](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_report.csv) (Findings CSV)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_analysis["Pattern Analysis"]
  node_analysis_api["Analyze Patterns<br/>[redos_analyzer.py]"]
  node_ast_detection["AST Detection<br/>[redos_analyzer.py]"]
  node_risk_context["Exploitability Classifier<br/>[redos_analyzer.py]"]
  node_fix_builder["Atomic Fix Builder<br/>[redos_analyzer.py]"]
  node_fix_verifier["Fix Verification<br/>[redos_analyzer.py]"]
end

subgraph group_scanner["Package Scanner"]
  node_package_fetch["Package Fetch<br/>[scan_pypi.py]"]
  node_source_extract["Source Extraction<br/>[scan_pypi.py]"]
  node_regex_extraction["Regex Call Extraction<br/>[scan_pypi.py]"]
  node_package_scan["Package Scan<br/>[scan_pypi.py]"]
  node_result_aggregation["Finding Aggregation<br/>[scan_pypi.py]"]
end

subgraph group_repair["Fix Generation"]
  node_fix_runner["Fix Runner<br/>[generate_fixes.py]"]
end

subgraph group_reports["Reports"]
  node_finding_report["Findings CSV<br/>[redos_report.csv]"]
  node_fix_report["Fixes CSV<br/>[redos_fixes.csv]"]
  node_scan_summary["Scan Summary<br/>[scan_summary.txt]"]
end

node_developer(("Developer"))
node_pypi{{"PyPI"}}

node_developer -->|"analyzes pattern"| node_analysis_api
node_analysis_api -->|"parses AST"| node_ast_detection
node_developer -->|"scans packages"| node_package_scan
node_package_scan -->|"downloads source"| node_package_fetch
node_package_fetch -->|"requests releases"| node_pypi
node_package_scan -->|"reads archive"| node_source_extract
node_package_scan -->|"extracts calls"| node_regex_extraction
node_package_scan -->|"analyzes patterns"| node_analysis_api
node_package_scan -->|"classifies context"| node_risk_context
node_package_scan -->|"collects findings"| node_result_aggregation
node_result_aggregation -->|"writes findings"| node_finding_report
node_result_aggregation -->|"writes summary"| node_scan_summary
node_developer -->|"generates fixes"| node_fix_runner
node_fix_runner -->|"reads findings"| node_finding_report
node_fix_runner -->|"reanalyzes patterns"| node_analysis_api
node_fix_runner -->|"requests fix"| node_fix_builder
node_fix_runner -->|"verifies fix"| node_fix_verifier
node_fix_builder -->|"checks warnings"| node_analysis_api
node_fix_runner -->|"writes fixes"| node_fix_report

click node_analysis_api "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py"
click node_ast_detection "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py"
click node_risk_context "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py"
click node_fix_builder "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py"
click node_fix_verifier "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py"
click node_package_fetch "https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py"
click node_source_extract "https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py"
click node_regex_extraction "https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py"
click node_package_scan "https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py"
click node_result_aggregation "https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py"
click node_fix_runner "https://github.com/harshithreddy01/redos-analyzer/blob/master/generate_fixes.py"
click node_finding_report "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_report.csv"
click node_fix_report "https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_fixes.csv"
click node_scan_summary "https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_summary.txt"

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_analysis_api,node_ast_detection,node_risk_context,node_fix_builder,node_fix_verifier toneBlue
class node_package_fetch,node_source_extract,node_regex_extraction,node_package_scan,node_result_aggregation toneAmber
class node_fix_runner toneMint
class node_finding_report,node_fix_report,node_scan_summary toneRose
class node_developer,node_pypi toneIndigo
```

## Components

### Pattern Analysis

- [Analyze Patterns](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py): `redos_analyzer.py`
- [AST Detection](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py): `redos_analyzer.py`
- [Exploitability Classifier](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py): `redos_analyzer.py`
- [Atomic Fix Builder](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py): `redos_analyzer.py`
- [Fix Verification](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_analyzer.py): `redos_analyzer.py`

### Package Scanner

- [Package Fetch](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py): `scan_pypi.py`
- [Source Extraction](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py): `scan_pypi.py`
- [Regex Call Extraction](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py): `scan_pypi.py`
- [Package Scan](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py): `scan_pypi.py`
- [Finding Aggregation](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_pypi.py): `scan_pypi.py`

### Fix Generation

- [Fix Runner](https://github.com/harshithreddy01/redos-analyzer/blob/master/generate_fixes.py): `generate_fixes.py`

### Reports

- [Findings CSV](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_report.csv): `redos_report.csv`
- [Fixes CSV](https://github.com/harshithreddy01/redos-analyzer/blob/master/redos_fixes.csv): `redos_fixes.csv`
- [Scan Summary](https://github.com/harshithreddy01/redos-analyzer/blob/master/scan_summary.txt): `scan_summary.txt`

### Other components

- **Developer**
- **PyPI**

## Connections

- Developer → Analyze Patterns: analyzes pattern (evidence: `README.md`)
- Analyze Patterns → AST Detection: parses AST (evidence: `README.md`)
- Developer → Package Scan: scans packages (evidence: `README.md`)
- Package Scan → Package Fetch: downloads source (evidence: `scan_pypi.py`)
- Package Fetch → PyPI: requests releases (evidence: `scan_pypi.py`)
- Package Scan → Source Extraction: reads archive (evidence: `scan_pypi.py`)
- Package Scan → Regex Call Extraction: extracts calls (evidence: `scan_pypi.py`)
- Package Scan → Analyze Patterns: analyzes patterns (evidence: `scan_pypi.py`)
- Package Scan → Exploitability Classifier: classifies context (evidence: `scan_pypi.py`)
- Package Scan → Finding Aggregation: collects findings (evidence: `scan_pypi.py`)
- Finding Aggregation → Findings CSV: writes findings (evidence: `README.md`)
- Finding Aggregation → Scan Summary: writes summary (evidence: `README.md`)
- Developer → Fix Runner: generates fixes (evidence: `generate_fixes.py`)
- Fix Runner → Findings CSV: reads findings (evidence: `generate_fixes.py`)
- Fix Runner → Analyze Patterns: reanalyzes patterns (evidence: `generate_fixes.py`)
- Fix Runner → Atomic Fix Builder: requests fix (evidence: `generate_fixes.py`)
- Fix Runner → Fix Verification: verifies fix (evidence: `generate_fixes.py`)
- Atomic Fix Builder → Analyze Patterns: checks warnings (evidence: `redos_analyzer.py`)
- Fix Runner → Fixes CSV: writes fixes (evidence: `generate_fixes.py`)
