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
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
| Package | Responsibility | Start with |
|---|---|---|
inventag/cli/ | Flags, configuration validation, logging | main.py, config_validator.py |
inventag/core/ | Multi-account orchestration and credentials | cloud_bom_generator.py |
inventag/discovery/ | Finding resources: per-service API calls, the Tagging API, Cost Explorer | inventory.py, comprehensive_discovery.py |
inventag/reporting/ | Normalising resources and writing the default Excel and Word files | bom_processor.py, converter.py |
inventag/templating/ | Template loading, validation, inheritance, tag-policy checks and template-driven Excel and Word output | schema.py, registry.py, runner.py |
inventag/state/ | Snapshots, differences and changelogs | state_manager.py |
inventag/compliance/ | Library classes for tag checks and safety; mostly not used by the CLI today | checker.py |
inventag/security/ | The read-only guard, IAM policy list, log redaction, safe output files | read_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.
| Module | Decides |
|---|---|
inventag/exit_codes.py | The exit codes (0 to 6) |
inventag/security/secret_values.py | Which field values are secret and become ***REDACTED*** |
inventag/discovery/regions.py | Which regions a run scans, and the home region of each partition |
inventag/discovery/aws_clients.py | Retry settings of the AWS clients |
inventag/discovery/coverage.py | How each listing call ended, per service and region |
inventag/reporting/settings_loader.py | How settings files are read and checked |
inventag/reporting/safe_save.py | Writing a report to a temporary file and moving it into place |
inventag/state/partial_results.py | Saving 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 and the output is exactly as
before.
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.pyis the single place that builds and compares ARNs (build_arn,normalize_arn,ResourceArnIndex).inventory.pyandcomprehensive_discovery.pyboth 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.pystill has a static list of fourteen regions, used only when a library caller passes no regions.--enable-cost-analysiscalls 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 on the CLI path:
reporting/template_framework.py,branding_system.py,word_builder.py,excel_builder.py,document_generator.pyandconfiguration_manager.py, as well asdiscovery/enhanced_readonly_discovery.pyand unreachable methods indiscovery/inventory.py.
Older design notes were removed from the repository. Use the pages on this site.