# acdeveloper-sci/forti4d architecture

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

- Interactive diagram: https://gitdiagram.com/acdeveloper-sci/forti4d
- Repository: https://github.com/acdeveloper-sci/forti4d

## Overview

#### Purpose and Entry Points
Forti4D is a Python static-analysis toolkit for mixed F77/F90/F95 source trees, designed around regex and logical-line processing rather than a full Fortran parser. The CLI/package orchestration entry point is `forti4d/pipeline.py`; runtime paths and environment overrides are centralized in `forti4d/config.py`.

#### Pipeline Orchestration
`forti4d/pipeline.py` runs a dependency-ordered 19-stage batch pipeline, supports selecting/resuming stages, and materializes reports under the configured output directory. Stages communicate primarily through CSV/text artifacts rather than an in-memory shared model. Logging is initialized through `forti4d/lib/logging_setup.py`; parallel execution support is in `forti4d/lib/parallel.py`.

#### Source Normalization and Parsing Boundary
The core parsing boundary is the custom logical-line reader in `forti4d/lib/reader_logical.py`, which normalizes F77 fixed-form and F90 free-form continuation behavior. Regex grammars in `forti4d/lib/patterns_v1.py` and `forti4d/lib/patterns_v2.py`, plus statement classification in `forti4d/lib/kinds.py`, replace external parser dependencies. This scope intentionally supports F77–F95 but not Fortran 2003+ or C-preprocessor expansion.

#### Corpus Inventory and Dependency Graph
Inventory establishes program-unit identities, types, and line ranges in `forti4d/analyzers/inventory.py`. Dependency extraction then resolves CALL/USE/function relationships, ambiguities, external references, includes, and file-level relationships in `forti4d/analyzers/dependencies.py`. These outputs form the graph and unit identity foundation used by structural and reachability analyses.

#### Line-Level Audit and Scope Attribution
`forti4d/analyzers/profiler.py` produces per-file audit CSVs that classify logical lines and density metrics. Multiple analyzers consume this audit layer: `forti4d/analyzers/complexity.py`, `forti4d/analyzers/common_blocks.py`, and scope-management analyzers. Attribution relies on inventory line ranges, assigning statements to the innermost containing program unit.

#### Structural, Risk, and Modernization Analysis
Topology and migration interpretation are layered over inventory, dependency, and audit outputs: `forti4d/analyzers/block_analysis.py` models block topology; `forti4d/analyzers/structure_analysis.py` identifies graph roles such as hubs and entry points; `forti4d/analyzers/cross_analysis.py` derives migration strategy. Entry points include explicit `PROGRAM` units and implicit main programs.

#### Symbol and Legacy-Feature Scope Layer
The E4 ScopeManager layer extracts declarations and legacy semantics within unit boundaries: `forti4d/analyzers/symbols.py`, `forti4d/analyzers/derived_types.py`, and `forti4d/analyzers/equivalences.py`. It captures variables, signatures, IMPLICIT rules, derived types, and EQUIVALENCE alias groups; it complements graph-level analysis rather than resolving modern OOP or procedure-pointer semantics.

#### Consolidation and Deliverables
Late stages derive reachability/dead-code status, SLOC, clone relationships, graph render inputs, and ranked migration risk through `forti4d/analyzers/reachability.py`, `forti4d/analyzers/consolidate.py`, and `forti4d/analyzers/prioritization.py`. `forti4d/analyzers/html_report.py` creates a self-contained report, while `forti4d/analyzers/visual_graph.py` emits Graphviz DOT; Graphviz is optional and only needed to render those files. The only stated Python third-party runtime dependency is Loguru.

Main entry points: [`forti4d/analyzers/inventory.py`](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/inventory.py) (Corpus Inventory), [`forti4d/analyzers/dependencies.py`](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/dependencies.py) (Dependency Extraction), [`forti4d/analyzers/consolidate.py`](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/consolidate.py) (Consolidated Analysis), [`forti4d/lib/reader_logical.py`](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/reader_logical.py) (Logical-Line Reader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime &amp; Pipeline"]
  node_config["Runtime Configuration<br/>[config.py]"]
  node_pipeline["19-Stage Pipeline<br/>orchestrator<br/>[pipeline.py]"]
  node_logging["Logging Setup<br/>runtime support<br/>[logging_setup.py]"]
  node_parallel["Parallel Execution<br/>runtime support<br/>[parallel.py]"]
end

subgraph group_parsing["Normalization Boundary"]
  node_logical_reader["Logical-Line Reader<br/>source normalizer<br/>[reader_logical.py]"]
  node_patterns_v1["Regex Grammar v1<br/>[patterns_v1.py]"]
  node_patterns_v2["Regex Grammar v2<br/>[patterns_v2.py]"]
  node_kinds["Statement Classification<br/>classifier<br/>[kinds.py]"]
end

subgraph group_core["Core Analysis"]
  node_inventory["Corpus Inventory<br/>analyzer<br/>[inventory.py]"]
  node_dependencies["Dependency Extraction<br/>analyzer<br/>[dependencies.py]"]
  node_profiler["Line Audit &amp; Metrics<br/>analyzer<br/>[profiler.py]"]
  node_structural["Structural Analysis<br/>analysis layer"]
end

subgraph group_scope["Scope &amp; Legacy Semantics"]
  node_symbols["Symbols &amp; Declarations<br/>scope analyzer<br/>[symbols.py]"]
  node_derived_types["Derived Types<br/>scope analyzer<br/>[derived_types.py]"]
  node_equivalences["EQUIVALENCE Aliases<br/>scope analyzer<br/>[equivalences.py]"]
end

subgraph group_delivery["Consolidation &amp; Deliverables"]
  node_reachability["Reachability &amp; Dead Code<br/>analyzer<br/>[reachability.py]"]
  node_consolidate["Consolidated Analysis<br/>analyzer<br/>[consolidate.py]"]
  node_prioritization["Migration Prioritization<br/>analyzer<br/>[prioritization.py]"]
  node_html_report["HTML Report<br/>deliverable<br/>[html_report.py]"]
  node_visual_graph["Graphviz DOT Output<br/>deliverable<br/>[visual_graph.py]"]
end

node_config -->|"configures"| node_pipeline
node_logging -->|"logs pipeline"| node_pipeline
node_parallel -->|"parallel stages"| node_pipeline
node_pipeline -->|"reads source"| node_logical_reader
node_patterns_v1 -->|"grammar rules"| node_kinds
node_patterns_v2 -->|"grammar rules"| node_kinds
node_logical_reader -->|"logical lines"| node_inventory
node_logical_reader -->|"logical lines"| node_profiler
node_kinds -->|"classifies lines"| node_profiler
node_inventory -->|"unit identities and ranges"| node_dependencies
node_logical_reader -->|"normalized source"| node_dependencies
node_inventory -->|"unit graph foundation"| node_structural
node_dependencies -->|"dependency graph"| node_structural
node_profiler -->|"audit attribution"| node_symbols
node_inventory -->|"unit boundaries"| node_symbols
node_inventory -->|"unit boundaries"| node_derived_types
node_inventory -->|"unit boundaries"| node_equivalences
node_dependencies -->|"call/use graph"| node_reachability
node_structural -->|"entry points"| node_reachability
node_profiler -->|"audit metrics"| node_consolidate
node_reachability -->|"dead-code status"| node_consolidate
node_symbols -->|"scope results"| node_consolidate
node_consolidate -->|"combined findings"| node_prioritization
node_prioritization -->|"ranked results"| node_html_report
node_consolidate -->|"analysis artifacts"| node_html_report
node_dependencies -->|"graph data"| node_visual_graph
node_structural -->|"topology roles"| node_visual_graph

click node_config "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/config.py"
click node_pipeline "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/pipeline.py"
click node_logging "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/logging_setup.py"
click node_parallel "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/parallel.py"
click node_logical_reader "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/reader_logical.py"
click node_patterns_v1 "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/patterns_v1.py"
click node_patterns_v2 "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/patterns_v2.py"
click node_kinds "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/kinds.py"
click node_inventory "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/inventory.py"
click node_dependencies "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/dependencies.py"
click node_profiler "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/profiler.py"
click node_structural "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/structure_analysis.py"
click node_symbols "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/symbols.py"
click node_derived_types "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/derived_types.py"
click node_equivalences "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/equivalences.py"
click node_reachability "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/reachability.py"
click node_consolidate "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/consolidate.py"
click node_prioritization "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/prioritization.py"
click node_html_report "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/html_report.py"
click node_visual_graph "https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/visual_graph.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_config,node_pipeline,node_logging,node_parallel toneBlue
class node_logical_reader,node_patterns_v1,node_patterns_v2,node_kinds toneAmber
class node_inventory,node_dependencies,node_profiler,node_structural toneMint
class node_symbols,node_derived_types,node_equivalences toneRose
class node_reachability,node_consolidate,node_prioritization,node_html_report,node_visual_graph toneIndigo
```

## Components

### Runtime & Pipeline

- [Runtime Configuration](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/config.py): configuration · Centralizes paths and environment overrides. · `forti4d/config.py`
- [19-Stage Pipeline](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/pipeline.py): orchestrator · Runs selected or resumed batch stages through CSV/text artifacts. · `forti4d/pipeline.py`
- [Logging Setup](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/logging_setup.py): runtime support · `forti4d/lib/logging_setup.py`
- [Parallel Execution](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/parallel.py): runtime support · `forti4d/lib/parallel.py`

### Normalization Boundary

- [Logical-Line Reader](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/reader_logical.py): source normalizer · Normalizes fixed-form and free-form continuation rules. · `forti4d/lib/reader_logical.py`
- [Regex Grammar v1](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/patterns_v1.py): regex grammar · `forti4d/lib/patterns_v1.py`
- [Regex Grammar v2](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/patterns_v2.py): regex grammar · `forti4d/lib/patterns_v2.py`
- [Statement Classification](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/lib/kinds.py): classifier · `forti4d/lib/kinds.py`

### Core Analysis

- [Corpus Inventory](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/inventory.py): analyzer · Establishes program-unit identities, types, and line ranges. · `forti4d/analyzers/inventory.py`
- [Dependency Extraction](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/dependencies.py): analyzer · Resolves calls, uses, functions, includes, and external references. · `forti4d/analyzers/dependencies.py`
- [Line Audit & Metrics](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/profiler.py): analyzer · Produces per-file logical-line audit CSVs and density metrics. · `forti4d/analyzers/profiler.py`
- [Structural Analysis](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/structure_analysis.py): analysis layer · Derives block topology, graph roles, and entry points. · `forti4d/analyzers/structure_analysis.py`

### Scope & Legacy Semantics

- [Symbols & Declarations](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/symbols.py): scope analyzer · Extracts variables, signatures, and IMPLICIT rules by unit. · `forti4d/analyzers/symbols.py`
- [Derived Types](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/derived_types.py): scope analyzer · `forti4d/analyzers/derived_types.py`
- [EQUIVALENCE Aliases](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/equivalences.py): scope analyzer · `forti4d/analyzers/equivalences.py`

### Consolidation & Deliverables

- [Reachability & Dead Code](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/reachability.py): analyzer · `forti4d/analyzers/reachability.py`
- [Consolidated Analysis](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/consolidate.py): analyzer · Combines late-stage results including SLOC and clone relationships. · `forti4d/analyzers/consolidate.py`
- [Migration Prioritization](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/prioritization.py): analyzer · Ranks modernization risk and migration work. · `forti4d/analyzers/prioritization.py`
- [HTML Report](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/html_report.py): deliverable · Creates a self-contained report. · `forti4d/analyzers/html_report.py`
- [Graphviz DOT Output](https://github.com/acdeveloper-sci/forti4d/blob/main/forti4d/analyzers/visual_graph.py): deliverable · Emits DOT render inputs; Graphviz rendering is optional. · `forti4d/analyzers/visual_graph.py`

## Connections

- Runtime Configuration → 19-Stage Pipeline: configures
- Logging Setup → 19-Stage Pipeline: logs pipeline
- Parallel Execution → 19-Stage Pipeline: parallel stages
- 19-Stage Pipeline → Logical-Line Reader: reads source
- Regex Grammar v1 → Statement Classification: grammar rules
- Regex Grammar v2 → Statement Classification: grammar rules
- Logical-Line Reader → Corpus Inventory: logical lines
- Logical-Line Reader → Line Audit & Metrics: logical lines
- Statement Classification → Line Audit & Metrics: classifies lines
- Corpus Inventory → Dependency Extraction: unit identities and ranges
- Logical-Line Reader → Dependency Extraction: normalized source
- Corpus Inventory → Structural Analysis: unit graph foundation
- Dependency Extraction → Structural Analysis: dependency graph
- Line Audit & Metrics → Symbols & Declarations: audit attribution
- Corpus Inventory → Symbols & Declarations: unit boundaries
- Corpus Inventory → Derived Types: unit boundaries
- Corpus Inventory → EQUIVALENCE Aliases: unit boundaries
- Dependency Extraction → Reachability & Dead Code: call/use graph
- Structural Analysis → Reachability & Dead Code: entry points
- Line Audit & Metrics → Consolidated Analysis: audit metrics
- Reachability & Dead Code → Consolidated Analysis: dead-code status
- Symbols & Declarations → Consolidated Analysis: scope results
- Consolidated Analysis → Migration Prioritization: combined findings
- Migration Prioritization → HTML Report: ranked results
- Consolidated Analysis → HTML Report: analysis artifacts
- Dependency Extraction → Graphviz DOT Output: graph data
- Structural Analysis → Graphviz DOT Output: topology roles
