Skip to main content
Version: v1.4.0

How the code fits together

Who this is for: contributors who want to find their way around the code.

What you will know after reading: which module does what during a run, and where to start for a change.

The path of one run​

Text
inventag_cli.py
-> inventag/cli/main.py parse flags, validate, set up logging
-> templating/runner.py only with --template: load templates,
apply a config template to the flags
-> core/cloud_bom_generator.py CloudBOMGenerator
1. sessions per account profiles, keys or sts:AssumeRole
2. discovery per account discovery/inventory.py and friends
3. consolidation one list of resource dictionaries
4. documents reporting/bom_processor.py, then
reporting/converter.py (default) or
templating/render_excel.py and
render_word.py (with --template)
5. state state/ snapshots and changelog

Packages​

PackageResponsibilityStart with
inventag/cli/Flags, configuration validation, loggingmain.py, config_validator.py
inventag/core/Multi-account orchestration and credentialscloud_bom_generator.py
inventag/discovery/Finding resources: per-service API calls, the Tagging API, Cost Explorerinventory.py, comprehensive_discovery.py
inventag/reporting/Normalising resources and writing the default Excel and Word filesbom_processor.py, converter.py
inventag/templating/Template loading, validation, inheritance, tag-policy checks and template-driven Excel and Word outputschema.py, registry.py, runner.py
inventag/state/Snapshots, differences and changelogsstate_manager.py
inventag/compliance/Library classes for tag checks and safety. The tag-policy path uses checker.py; the other classes are not used by the CLIchecker.py
inventag/security/The read-only guard, IAM policy list, log redaction, safe output filesread_only_guard.py, iam_policy.py

Shared modules​

Each of these is the one place that decides its topic. Change the behaviour there, not in a copy.

ModuleDecides
inventag/exit_codes.pyThe exit codes (0 to 6)
inventag/security/secret_values.pyWhich field values are secret and become ***REDACTED***
inventag/discovery/regions.pyWhich regions a run scans, and the home region of each partition
inventag/discovery/aws_clients.pyRetry settings of the AWS clients
inventag/discovery/coverage.pyHow each listing call ended, per service and region
inventag/reporting/settings_loader.pyHow settings files are read and checked
inventag/reporting/safe_save.pyWriting a report to a temporary file and moving it into place
inventag/state/partial_results.pySaving and reusing finished accounts for --resume

The resource dictionary​

Everything between discovery and output passes around plain dictionaries, one per resource. The fields that templates and reports rely on are listed in the Template reference. Keep them stable: renaming one breaks people's templates.

How templates hook in​

templating/runner.py defines TemplatedCloudBOMGenerator, a subclass of CloudBOMGenerator that replaces only the document step. The rest of a run, including discovery, credentials and state, is unchanged. Without --template, the original classes are used.

Known gaps worth fixing​

The user-facing limits are on Feature status. These are the code-side gaps. Each is a good first contribution:

  • discovery/arn_utils.py is the single place that builds and compares ARNs (build_arn, normalize_arn, ResourceArnIndex). inventory.py and comprehensive_discovery.py both use it. Tags from the Resource Groups Tagging API match by normalised ARN, then by service, region and ID.
  • Global services (IAM, S3 list, CloudFront, Route 53, WAF for CloudFront, CloudFront's ACM certificates) run once per account from the partition's home region and carry the region global.
  • discovery/inventory.py still has a static list of fourteen regions, used only when a library caller passes no regions.
  • --enable-cost-analysis calls Cost Explorer even with --no-billing-validation.
  • One failed account does not change the exit code unless you pass --fail-on-account-error (exit 5).
  • The network and security analysis runs twice in one run (in the BOM processor and in the converter), so its AWS calls are made twice.
  • These modules are not called by the CLI: reporting/template_framework.py, branding_system.py, word_builder.py, excel_builder.py, document_generator.py and configuration_manager.py, as well as discovery/enhanced_readonly_discovery.py. reporting/template_framework.py and reporting/document_generator.py are imported when the CLI starts.
  • Planned for removal in a later release: the modules reporting/configuration_manager.py, reporting/branding_system.py, reporting/excel_branding_applicator.py, reporting/word_branding_applicator.py, reporting/template_framework.py and discovery/enhanced_readonly_discovery.py; the jsonschema dependency, which only configuration_manager.py uses; and these functions, which nothing in the package calls: StateManager.get_state_comparison_data, export_state, validate_state_integrity and get_storage_stats, get_all_aws_regions in cli/main.py, and CloudBOMGenerator.from_interactive_prompt.

Older design notes were removed from the repository. Use the pages on this site.