# bhuvansh855/pyrift architecture

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

- Interactive diagram: https://gitdiagram.com/bhuvansh855/pyrift
- Repository: https://github.com/bhuvansh855/pyrift

## Overview

PyRift is a Python static analyzer for compatibility and behavior differences across CPython versions and between CPython and PyPy. Its main workflow accepts a project or source string through the CLI or Python API, scans Python ASTs with compatibility rules, filters findings using project targets and compatibility guards, enriches findings with reviewed evidence metadata, and formats results for review. The graph also shows the shared AST-analysis layer and separate CPython/PyPy rule catalogs. Some subsystem links are based on the README or source-index references; unsampled implementation details are not inferred.

Main entry points: [`pyrift/scanner.py`](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/scanner.py) (AST scanner), [`pyrift/rules/cpython/cpy033_is_relative_to.py`](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/cpython/cpy033_is_relative_to.py) (Path compatibility rule), [`pyrift/base_rule.py`](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/base_rule.py) (Rule interface), [`pyrift/finding.py`](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/finding.py) (Finding model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["CLI commands<br/>[cli.py]"]
  node_api["Python API<br/>[__init__.py]"]
end

subgraph group_engine["Scan engine"]
  node_scanner["AST scanner<br/>[scanner.py]"]
  node_target["Target config<br/>[targets.py]"]
  node_guards["Compatibility guards<br/>[guards.py]"]
  node_imports["Import analysis<br/>[imports.py]"]
  node_symbols["Symbol analysis<br/>[symbols.py]"]
end

subgraph group_rules["Compatibility rules"]
  node_cpycatalog["CPython rules"]
  node_pypycatalog["PyPy rules"]
  node_forkrule["Fork behavior rule"]
  node_relative_rule["Path compatibility rule"]
  node_string_rule["String behavior rule"]
  node_base_rule["Rule interface<br/>[base_rule.py]"]
end

subgraph group_results["Findings and output"]
  node_finding["Finding model<br/>[finding.py]"]
  node_metadata["Evidence metadata<br/>[rule_metadata.py]"]
  node_reporter["Report formats<br/>[reporter.py]"]
  node_github["GitHub annotations<br/>[github.py]"]
end

node_user(("Engineer / CI"))

node_user -->|"invokes"| node_cli
node_user -->|"calls"| node_api
node_cli -->|"starts scans"| node_scanner
node_api -->|"exposes scans"| node_scanner
node_cli -->|"configures targets"| node_target
node_scanner -->|"uses targets"| node_target
node_scanner -->|"filters findings"| node_guards
node_scanner -->|"runs rules"| node_cpycatalog
node_scanner -->|"runs rules"| node_pypycatalog
node_scanner -->|"registers rule"| node_forkrule
node_scanner -->|"registers rule"| node_relative_rule
node_scanner -->|"registers rule"| node_string_rule
node_forkrule -->|"implements"| node_base_rule
node_relative_rule -->|"implements"| node_base_rule
node_string_rule -->|"implements"| node_base_rule
node_base_rule -->|"returns findings"| node_finding
node_relative_rule -->|"uses import analysis"| node_imports
node_relative_rule -.->|"uses symbol analysis"| node_symbols
node_finding -->|"enriches from"| node_metadata
node_scanner -->|"returns scan result"| node_reporter
node_reporter -->|"formats findings"| node_finding
node_github -->|"formats findings"| node_finding
node_github -->|"accepts scan result"| node_scanner

click node_cli "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/cli.py"
click node_api "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/__init__.py"
click node_scanner "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/scanner.py"
click node_target "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/targets.py"
click node_guards "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/analysis/guards.py"
click node_imports "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/analysis/imports.py"
click node_symbols "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/analysis/symbols.py"
click node_cpycatalog "https://github.com/bhuvansh855/pyrift/tree/main/pyrift/rules/cpython"
click node_pypycatalog "https://github.com/bhuvansh855/pyrift/tree/main/pyrift/rules/pypy"
click node_forkrule "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/cpython/cpy023_multiprocessing_fork.py"
click node_relative_rule "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/cpython/cpy033_is_relative_to.py"
click node_string_rule "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/pypy/ppy014_string_concat.py"
click node_base_rule "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/base_rule.py"
click node_finding "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/finding.py"
click node_metadata "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rule_metadata.py"
click node_reporter "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/reporter.py"
click node_github "https://github.com/bhuvansh855/pyrift/blob/main/pyrift/formatters/github.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_cli,node_api toneBlue
class node_scanner,node_target,node_guards,node_imports,node_symbols toneAmber
class node_cpycatalog,node_pypycatalog,node_forkrule,node_relative_rule,node_string_rule,node_base_rule toneMint
class node_finding,node_metadata,node_reporter,node_github toneRose
class node_user toneIndigo
```

## Components

### Entry points

- [CLI commands](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/cli.py): `pyrift/cli.py`
- [Python API](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/__init__.py): `pyrift/__init__.py`

### Scan engine

- [AST scanner](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/scanner.py): `pyrift/scanner.py`
- [Target config](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/targets.py): `pyrift/targets.py`
- [Compatibility guards](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/analysis/guards.py): `pyrift/analysis/guards.py`
- [Import analysis](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/analysis/imports.py): `pyrift/analysis/imports.py`
- [Symbol analysis](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/analysis/symbols.py): `pyrift/analysis/symbols.py`

### Compatibility rules

- [CPython rules](https://github.com/bhuvansh855/pyrift/tree/main/pyrift/rules/cpython): `pyrift/rules/cpython`
- [PyPy rules](https://github.com/bhuvansh855/pyrift/tree/main/pyrift/rules/pypy): `pyrift/rules/pypy`
- [Fork behavior rule](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/cpython/cpy023_multiprocessing_fork.py): `pyrift/rules/cpython/cpy023_multiprocessing_fork.py`
- [Path compatibility rule](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/cpython/cpy033_is_relative_to.py): `pyrift/rules/cpython/cpy033_is_relative_to.py`
- [String behavior rule](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rules/pypy/ppy014_string_concat.py): `pyrift/rules/pypy/ppy014_string_concat.py`
- [Rule interface](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/base_rule.py): `pyrift/base_rule.py`

### Findings and output

- [Finding model](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/finding.py): `pyrift/finding.py`
- [Evidence metadata](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/rule_metadata.py): `pyrift/rule_metadata.py`
- [Report formats](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/reporter.py): `pyrift/reporter.py`
- [GitHub annotations](https://github.com/bhuvansh855/pyrift/blob/main/pyrift/formatters/github.py): `pyrift/formatters/github.py`

### Other components

- **Engineer / CI**

## Connections

- Engineer / CI → CLI commands: invokes (evidence: `README.md`)
- Engineer / CI → Python API: calls (evidence: `README.md`)
- CLI commands → AST scanner: starts scans (evidence: `pyrift/cli.py`)
- Python API → AST scanner: exposes scans (evidence: `pyrift/__init__.py`)
- CLI commands → Target config: configures targets (evidence: `pyrift/cli.py`)
- AST scanner → Target config: uses targets (evidence: `pyrift/scanner.py`)
- AST scanner → Compatibility guards: filters findings (evidence: `pyrift/scanner.py`)
- AST scanner → CPython rules: runs rules (evidence: `pyrift/scanner.py`)
- AST scanner → PyPy rules: runs rules (evidence: `pyrift/scanner.py`)
- AST scanner → Fork behavior rule: registers rule (evidence: `pyrift/scanner.py`)
- AST scanner → Path compatibility rule: registers rule (evidence: `pyrift/scanner.py`)
- AST scanner → String behavior rule: registers rule (evidence: `pyrift/scanner.py`)
- Fork behavior rule → Rule interface: implements (evidence: `pyrift/rules/cpython/cpy023_multiprocessing_fork.py`)
- Path compatibility rule → Rule interface: implements (evidence: `pyrift/rules/cpython/cpy033_is_relative_to.py`)
- String behavior rule → Rule interface: implements (evidence: `pyrift/rules/pypy/ppy014_string_concat.py`)
- Rule interface → Finding model: returns findings (evidence: `pyrift/base_rule.py`)
- Path compatibility rule → Import analysis: uses import analysis (evidence: `pyrift/rules/cpython/cpy033_is_relative_to.py`)
- Path compatibility rule → Symbol analysis: uses symbol analysis
- Finding model → Evidence metadata: enriches from (evidence: `pyrift/finding.py`)
- AST scanner → Report formats: returns scan result (evidence: `pyrift/reporter.py`)
- Report formats → Finding model: formats findings (evidence: `pyrift/reporter.py`)
- GitHub annotations → Finding model: formats findings (evidence: `pyrift/formatters/github.py`)
- GitHub annotations → AST scanner: accepts scan result (evidence: `pyrift/formatters/github.py`)
