PyArchGraph Package guides

Package 02 / pyarchgraph.application

Application

Organises one analysis, from the request through collection and checks to the final report.

11 modules28 classesWalkthrough + class index

Its role

The application turns a caller's choices into an organised analysis run. Its incoming port is ProjectAnalyzer.analyse(request); AnalyseProject implements that workflow.

Accept a request

Validate source roots, options, and the selected gate before collection.

Coordinate the work

Collect sources through ports and call domain rules in the required order.

Assemble a report

Bring coverage, view results, and findings together for the caller.

Filesystem access, parsing, and graph-library operations arrive through injected collaborators. The application itself performs no external I/O. This allows the same workflow to run with real adapters or in-memory substitutes.

Follow a request

A caller supplies demo as the source root, its parent as the base directory, and the default analysis options.

The same two-file example in all three guides
# demo/orders.py
import inventory
# demo/inventory.py
import orders
  1. Validate and locate

    OptionValidator checks the request and options. ProjectAccess then locates the roots and base directory. Invalid requests stop before source discovery or metadata access.

  2. Collect a catalogue

    SourceCatalogBuilder asks SourceDiscovery for sources and ImportFactSource for drafts. It applies shared report paths and source IDs, reconciles bindings across roots, and asks the domain canonicaliser to assign fact IDs. The result is one SourceCatalog.

  3. Resolve and assess scope

    AnalyseProject combines discovered and configured targets, calls the import resolver, and gathers coverage diagnostics. LayoutDiagnosticService uses project observations to flag questionable root choices without changing the selected roots.

  4. Run registered views and checks

    The use case builds an AnalysisSnapshot. StrategyEngine normalises it, builds and validates each registered view, prepares its cycle analysis, and runs its selected checks. It attaches check IDs to findings, converts requested dependencies into readable ReportDependency values, and creates a ViewReport for each view.

  5. Return the assembled report

    The domain coverage policy determines completeness. AnalyseProject combines sources, coverage, and all view reports in an AnalysisReport. The configured analyser can be reused; each run keeps its observations separate.

The catalogue holds collected sources and facts. The snapshot supplies the analysis shared by views. The report holds the completed results. Each has a different job in the workflow.

Reports and failures

For the example, report.status is complete, while every built-in view contains a cycle error finding. The default gate is structural, and report.selected_view gives convenient access to that view's report.

What the caller receives
SituationApplication outcome
No error diagnostics or unacknowledged boundariesA complete report, which may still contain check findings.
A selected source cannot be read or parsedAn incomplete report with source diagnostics and any recovered results.
A referenced boundary is unacknowledgedAn incomplete report showing the missing implementation coverage.
Invalid request or analysis setupA validation error, such as AnalysisError or ValueError, rather than a report.
A registered view or check fails validation or raisesExtensionError identifies the failing extension; no report is returned.

AnalysisOptions.package_max_depth is an optional positive integer. The application validates it before project access, then configures immutable package strategies for that run. A supplied value overrides their constructor depth; omission keeps that configuration. Reusing the analyser does not retain a previous request's override.

StrategyRegistry names the available views and checks and selects checks per view. Custom strategies use the same workflow and result validation. An empty check selection leaves coverage requirements in place; cycle counts are still computed for the view.

The default registry includes three source views and their three package counterparts. ViewRegistration.report_dependencies defaults to false and is enabled for the package views. Their ViewReport.dependencies contains every inter-node relationship, even outside cycles, with original source endpoints, locations, statements and resolution kinds. The field is None when not requested and an empty tuple when requested but the graph has no dependencies. It is independent of cycle detail and selected checks.

The application returns Python values. The CLI adapter is responsible for JSON presentation and exit codes. Changing the gate selects which findings determine the CLI result; it does not reduce the coverage requirements.

Module map

Choose a module to jump to its classes below. Package initialisers are intentionally empty; callers import from the defining modules.

Where each responsibility lives
ModuleResponsibility
requests.pyThe roots and options supplied by a caller.
ports/analysis.pyThe incoming contract for requesting an analysis.
ports/project.pyContracts and observations for project locations and packaging clues.
ports/sources.pyContracts and observations for source discovery and import collection.
validation.pyRequest and option checks before project access.
catalog.pyCombining source observations into one catalogue.
scope.pyDiagnostics about roots that may not match the project layout.
strategies.pyNamed view/check registrations and their execution.
use_cases/analyse_project.pyThe workflow that coordinates a complete analysis run.
results.pyThe report and its coverage, views, and registered findings.
exceptions.pyFailures at the analysis and extension boundaries.

Every class

All 28 classes in this package, including value types, contracts, and internal helpers. Names link to the source file; descriptions match the role summaries in the code.

requests.py

The roots and options supplied by a caller.

AnalysisOptions
Selects the analysis scope, gate view and level of report detail.
AnalysisRequest
Describes the source roots and options for one project analysis.

ports/analysis.py

The incoming contract for requesting an analysis.

ProjectAnalyzer
Defines how callers request a project analysis and receive its report.

ports/project.py

Contracts and observations for project locations and packaging clues.

ProjectLocation
Identifies the import roots and shared base directory for an analysis.
ProjectMetadata
Carries packaging clues used to assess whether import roots match the project layout.
DirectoryLocation
Records the location and existence of a possible import root.
ProjectAccess
Provides project locations and layout observations to the analysis workflow.

ports/sources.py

Contracts and observations for source discovery and import collection.

ExcludedPath
Records a path left out of source discovery and the rule that excluded it.
DiscoveryResult
Collects the sources, possible import targets and scope observations found in one root.
FactCollection
Carries import drafts and diagnostics collected from source files.
SourceDiscovery
Defines how the application discovers sources and import targets within a root.
ImportFactSource
Defines how the application obtains import drafts from discovered sources.

validation.py

Request and option checks before project access.

OptionValidator
Checks that analysis requests and options are valid before project access begins.

catalog.py

Combining source observations into one catalogue.

SourceCatalog
Brings together sources, import facts and coverage observations from all roots.
SourceCatalogBuilder
Assembles one source catalogue and gives collected import drafts stable identities.

scope.py

Diagnostics about roots that may not match the project layout.

LayoutDiagnosticService
Reports evidence that the selected import roots do not match the project layout.

strategies.py

Named view/check registrations and their execution.

ViewRegistration
Gives a graph view strategy the name used to select it and report its results.
CheckRegistration
Names a check strategy and identifies the graph views it can evaluate.
StrategyRegistry
Defines the available graph views and checks, and which checks run for each view.
StrategyEngine
Runs registered graph views and checks, validates their results and assembles view reports.

use_cases/analyse_project.py

The workflow that coordinates a complete analysis run.

AnalyseProject
Coordinates source collection, import resolution and checks to produce an analysis report.

results.py

The report and its coverage, views, and registered findings.

RegisteredFinding
Connects a finding to the check that produced it and its severity.
ReportDependency
Describe a reported view dependency with readable original source evidence.
ViewReport
Present nodes, counts, findings and optional full dependencies for one view.
Coverage
Describes the analysed scope, exclusions, diagnostics and limits of an analysis.
AnalysisReport
Presents analysis coverage and findings for every graph view.

exceptions.py

Failures at the analysis and extension boundaries.

AnalysisError
Invalid analysis configuration; source failures instead return a report.
ExtensionError
A registered strategy raised or returned an invalid result.