How projectdiscovery/alterx works
Main Components
• CLI Layer: Represented by the main command in cmd/alterx/main.go. This is the entry point that captures user input, command-line flags, and parameters.
• Input Processing Module: Files like inputs.go and inputs_test.go indicate parsing and validation of input (including file input, STDIN or comma-separated values).
• Permutation Engine: Core logic is spread among files like algo.go, mutator.go (and its test file), and internal components in internal/runner (e.g., banner.go, config.go, runner.go). These modules work together to apply patterns, perform variable replacements, and generate permutations.
• Configuration & Static Assets: The config.go file at the root and the static folder (containing config.yaml and domains.txt) show where the tool loads its defaults. The permutations.yaml file at the root is the default pattern configuration that can be overridden — it’s a central part of how patterns are managed.
• Utility & Helpers: The util.go and replacer.go modules likely provide supportive functionality (e.g., string manipulation, variable replacement) to be used by the permutation engine.
Relationships and Interactions
• The CLI Layer passes the user’s input (such as lists of subdomains, custom patterns, and payload data) to the Input Processing Module.
• Input Processing feeds validated data into the Permutation Engine that uses defined patterns loaded from configuration files (either the static config or external permutation YAML) to generate the subdomain permutations.
• Utility modules (mutator, replacer, and other helpers) are called by the Permutation Engine to process variables (e.g., {{sub}}, {{suffix}}, etc.) and apply transformations.
• Output is then directed back to the CLI layer to be printed to STDOUT or written to a file, as well as possibly piped to further tools like dnsx.
• Additionally, if enrichment of inputs or updates is requested, the engine might also interact with external or pre-loaded data sources (as described in the DSL usage).
Architectural Patterns and Design Principles
• Separation of Concerns: Clear demarcation exists between the presentation (CLI), processing (input parsing and permutation generation), and configuration layers.
• Modular Design: By separating the business logic into internal packages (e.g., internal/runner) and distinct helper files (mutator.go, replacer.go, etc.), the project exhibits modularity.
Diagramming Conventions
• Use clear labels for each component (e.g., “CLI Layer”, “Input Parser”, “Permutation Engine”, “Configuration Loader”, “Utilities”).
• Optionally, include notes or legends to separate runtime components (CLI/Engine) from the developmental/infrastructure elements (CI/CD workflows, Docker).