-
Notifications
You must be signed in to change notification settings - Fork 0
FILE_GUIDE
Matthew A. Davis edited this page May 8, 2026
·
1 revision
This guide focuses on architecture-defining files in the AttackMap core repo.
- Returning maintainer: read CLI, analyzer contracts/loaders, scanner, translation, and threat-model sections first.
- New contributor: use this with Module Map and Analyzer Ecosystem.
- Security engineer: focus on analysis, threat-model, and reporting sections.
Repository root referenced below:
/Volumes/Dev/repos/GitLab/matthewd.xyzAI/attackmap
- Purpose:
- Main CLI entrypoint and top-level pipeline orchestration.
- Key functions:
analyze(...)modules(...)
- Important inputs/outputs:
- Inputs: repo path, output dir, requested module names.
- Outputs: triggers full analysis and report writing.
- Dependencies:
-
analyzers.py,graph.py,recon_to_analysis.py,analyzer.py,defensive_review.py,report.py.
-
- Why this file exists:
- Central place for user-facing flow and command UX.
- What breaks if changed carelessly:
- End-to-end execution order, module selection/install behavior, output artifact generation and paths.
- Purpose:
- Canonical analyzer contract and metadata model.
- Key classes/functions:
AnalyzerMetadataAnalyzerProtocolAnalyzerRepositoryModule-
AnalyzerResultalias normalize_analyzer_metadata(...)
- Important inputs/outputs:
- Normalizes metadata from built-ins/plugins.
- Dependencies:
-
recon_models.ScanResult.
-
- Why this file exists:
- Stable contract for built-in and plugin analyzers.
- Careless-change risk:
- Plugin loading failures, metadata incompatibility, broken analyzer registry behavior.
- Purpose:
- SDK-style re-export surface used by external analyzer packages.
- Key exports:
- Contracts + result/recon models.
- Transitional/compat note:
- Mostly wrappers around core models/contracts for import stability.
- Careless-change risk:
- External analyzer packages break at import-time.
- Purpose:
- Analyzer registry, discovery, selection, installation, execution, and merge.
- Key classes/functions:
- Built-ins:
BuiltinPythonWebAnalyzer,BuiltinJavaScriptWebAnalyzer,DefaultAnalyzer - Discovery/loading:
discover_installed_analyzers(...),_load_discovered_analyzer(...) - Selection/install:
select_requested_analyzers(...),install_analyzer_module(...) - Execution/merge:
analyze_repository(...),resolve_run_analyzers(...),merge_analyzer_results(...) - Metadata listing:
get_available_modules(...),get_available_repository_modules(...)
- Built-ins:
- Important inputs/outputs:
- Input: analyzer objects (built-in + entry points), repo path.
- Output: merged
ScanResult.
- Dependencies:
-
analyzer_contracts/sdk,scanner.py,subprocess,importlib.metadata.entry_points.
-
- Why this file exists:
- Owns analyzer lifecycle and makes plugin architecture usable.
- Transitional/compat note:
- Contains legacy file-level analyzer helpers (
AnalyzerSignals,RouteAnalyzer, etc.) alongside repo-level analyzers.
- Contains legacy file-level analyzer helpers (
- Careless-change risk:
- Duplicate/invalid analyzer loading, install path regressions, merge dedupe regressions, module CLI breakage.
- Purpose:
- Generic heuristic code scanning for routes/calls/db/auth/secrets.
- Key functions:
scan_repo(...)extract_routes(...)-
should_scan(...),should_scan_with_suffixes(...)
- Important inputs/outputs:
- Input: repo root and optional suffix filter.
- Output:
ScanResultwith generic signals.
- Dependencies:
-
sdk.models, regex pattern constants.
-
- Why this file exists:
- Baseline analyzer behavior and built-in fallback coverage.
- Transitional/compat note:
- Explicitly constrained to generic-only behavior; ecosystem overlays moved out.
- Careless-change risk:
- Route extraction regressions, signal noise increase, baseline analyzer quality drop.
- Purpose:
- Core Pydantic models for recon signals and higher-level outputs.
- Key classes:
- Recon:
Route,ExternalCall,DatabaseHint,AuthHint,SecretHint - Migrated hint buckets:
ServiceHint,EdgeHint,EntrypointHint,ProtocolHint,FrameworkHint - Analysis:
AttackSurface,Finding,AttackPath - Aggregate:
ScanResult
- Recon:
- Why this file exists:
- Single source of truth for data shape.
- Transitional/compat note:
- Mid-migration away from
auth_hintsas generic hint bus.
- Mid-migration away from
- Careless-change risk:
- Broad cross-module breakage, schema/report/test failures.
- Purpose:
- Compatibility re-exports for recon/result models.
- Transitional/compat note:
- Migration layer; likely reducible when imports stabilize.
- Careless-change risk:
- Import path breakage across core and plugins.
- Purpose:
- Canonical recon-to-analysis translation gateway.
- Key functions:
translate_recon(scan)to_attack_surface(...)to_findings(...)to_attack_paths(...)_auth_filtered_scan(...)
- Important inputs/outputs:
- Input:
ScanResult - Output:
AnalysisOutputs(surfaces/findings/paths)
- Input:
- Dependencies:
-
analyzer.py,threat_model.py.
-
- Why this file exists:
- Formal translation boundary and stability point.
- Transitional/compat note:
- Heavy compatibility filtering for overloaded
auth_hints.
- Heavy compatibility filtering for overloaded
- Careless-change risk:
- Inconsistent surfaces/findings/path semantics and duplicated translation behavior.
- Purpose:
- Attack-surface classification and architecture/attack-surface markdown summaries.
- Key functions:
identify_attack_surfaces(...)summarize_architecture(...)summarize_attack_surface(...)
- Inputs/outputs:
- Input:
ScanResult(+ optional precomputed surfaces for summaries) - Output:
AttackSurface[]+ markdown strings
- Input:
- Dependencies:
-
models.py,networkxgraph output.
-
- Why this file exists:
- Human-readable architecture/attack-surface interpretation stage.
- Transitional/compat note:
- Uses broader supporting hint buckets for exposure heuristics but auth-focused display for
auth_signals.
- Uses broader supporting hint buckets for exposure heuristics but auth-focused display for
- Careless-change risk:
- Category/risk/exposure drift affecting findings, paths, reviews, and JSON artifacts.
- Purpose:
- Findings generation and attacker-path generation.
- Key functions:
generate_findings(...)generate_attack_paths(...)
- Key internal chain builders:
_build_service_chains(...)_build_atproto_chains(...)_build_probable_chains(...)- Helper extraction/inference functions (
_extract_prefixed_hints,_extract_edge_hints,_file_service_map, etc.)
- Inputs/outputs:
- Input:
ScanResultand optionally attack surfaces. - Output:
Finding[],AttackPath[]
- Input:
- Dependencies:
-
analyzer.identify_attack_surfaces.
-
- Why this file exists:
- Core attacker-perspective reasoning engine.
- Transitional/compat note:
- Reads both dedicated hint buckets and legacy
auth_hintsprefixes.
- Reads both dedicated hint buckets and legacy
- Careless-change risk:
- Major security-output regressions, noisy/implausible findings, broken chain narratives.
- Purpose:
- Coarse trust-boundary/system graph generation.
- Key function:
build_graph(scan)
- Why this file exists:
- Quick architecture visualization primitives used in summaries.
- Careless-change risk:
- Architecture summary trust-boundary sections lose coherence.
- Purpose:
- Defensive-review markdown synthesis with prioritization/ranking.
- Key function:
render_defensive_review(...)
- Important internals:
- scoring:
_surface_priority,_path_priority,_finding_priority - evidence/source-quality classification helpers
- scoring:
- Inputs/outputs:
- Input: scan + surfaces + findings + paths
- Output: defensive review markdown
- Why this file exists:
- Product-facing security triage narrative.
- Careless-change risk:
- Credibility/prioritization quality regressions.
- Purpose:
- Stable machine-readable defensive review artifact generation.
- Key function:
build_defensive_review_json(...)
- Inputs/outputs:
- Input: scan/surfaces/findings/paths
- Output: structured JSON dict
- Why this file exists:
- Source-of-truth payload for downstream LLM/eval/automation use.
- Careless-change risk:
- Schema and downstream consumer breakage.
- Purpose:
- Context pack builder for LLM review layer.
- Key function:
build_review_context_pack(...)
- Why this file exists:
- Packages review JSON + analyzer metadata + source-quality and domain hints.
- Careless-change risk:
- Loss of grounding/quality hints for model consumers.
- Purpose:
- Prompt template rendering for LLM defensive review generation.
- Key exports:
-
SYSTEM_PROMPT_TEMPLATE,USER_PROMPT_TEMPLATE -
render_system_prompt,render_user_prompt,render_review_prompts
-
- Why this file exists:
- Enforces evidence-first, defensive, non-inventive prompting constraints.
- Careless-change risk:
- Higher hallucination/off-policy output risk.
- Purpose:
- Write all output artifacts + console summary.
- Key functions:
write_reports(...)render_console_summary(...)
- Outputs:
architecture.mdattack-surface.mddefensive-review.mddefensive-review.jsonreview-context-pack.jsonattackmap-report.json
- Why this file exists:
- Single output writer boundary.
- Careless-change risk:
- Missing/invalid artifacts and broken CLI user expectations.
- Purpose:
- Lightweight local evaluation harness for review quality.
- Key functions:
evaluate_review_text(...)run_evaluation(...)run_evaluation_suite(...)
- Why this file exists:
- Regression checks for grounding, observed/inferred discipline, recommendation usefulness, false-positive control.
- Careless-change risk:
- Silent quality regressions and weaker product validation loop.
- Purpose:
- Contract checks for generated JSON artifacts.
- Careless-change risk:
- Mismatch between runtime artifact structure and contract validation.
- Defines scanner extraction expectations and generic-only behavior.
- Transitional signal:
- asserts scanner does not emit node-service/atproto overlays.
- Defines analyzer discovery/selection/install/metadata/merge behavior.
- Includes merge behavior for new hint buckets.
- Defines contract import stability across legacy + SDK paths.
- Defines canonical translation flow behavior and consistency.
- Covers auth filtering and path-generation expectations.
- Defines attack-surface classification behavior.
- Defines finding/path generation behavior and chain quality expectations.
- Define defensive review layer behavior, artifact semantics, and eval harness expectations.
- Defines schema conformance requirements for JSON outputs.
/Volumes/Dev/repos/GitLab/matthewd.xyzAI/attackmap/src/attackmap/recon_to_analysis.py
- Prefix-based auth filtering + migrated bucket suppression.
/Volumes/Dev/repos/GitLab/matthewd.xyzAI/attackmap/src/attackmap/threat_model.py
- Dual-read of legacy and new hint lanes.
/Volumes/Dev/repos/GitLab/matthewd.xyzAI/attackmap/src/attackmap/analyzer.py
- Mixed use of auth-only and supporting hints.
/Volumes/Dev/repos/GitLab/matthewd.xyzAI/attackmap/src/attackmap/recon_models.py
- Re-export compatibility surfaces.
/Volumes/Dev/repos/GitLab/matthewd.xyzAI/attackmap/src/attackmap/analyzers.py
- Combined old file-level helper classes with newer repo-level analyzer architecture.
Migrated from https://gitlab.com/matthewd.xyzAI/AttackMap/-/wikis/docs/FILE_GUIDE.