# hahwul/dalfox architecture

> Architecture diagram of the GitHub repository hahwul/dalfox, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hahwul/dalfox
- Repository: https://github.com/hahwul/dalfox

## Overview

##### Main Components
- CLI/Command Layer – This is defined in the “cmd” directory. It includes the various command entry points (url, pipe, file, server, sxss, etc.) and serves as the interface through which users trigger scanning.
- Scanning Engine & Modules – Under “pkg/scanning”, “internal/optimization”, and “internal/payload”, you have the core logic for:
- Parameter analysis and discovery
- Different scanning modes (BAV, grep, headless, etc.)
- Payload management (custom payloads, remote payloads, etc.)
- HTTP Handling & Network Communication – The “internal/har” package indicates that the tool uses or captures HTTP Archive (HAR) data, client tracing, and round-tripping for HTTP requests.
- Reporting & Output – Components in “internal/printing” and “internal/report” are dedicated to showing test results, banners, logs, and generating formatted JSON/plain text output.
- REST API / Server Module – There is a server mode available (found in the “cmd/server.go” and “pkg/server”) that facilitates optional integration via a REST API.
- Utility & Support Modules – The “internal/utils”, “lib”, and “pkg/model” directories hold common functions, data models, and support functions that tie the components together.

##### Component Interactions
- User Interaction: The user inputs commands through the CLI (using specific modes and flags).
- Command Dispatch: The commands in the “cmd” package route the request to the scanning engine, which then coordinates with the underlying modules.
- Scanning Flow: The scanning engine (under pkg/scanning and internal/optimization) analyzes parameters, constructs payloads (using internal/payload), and sends HTTP requests (via internal/har and pkg/scanning/transport).
- Output & Reporting: Results get processed, logged, and reported through the “internal/printing” and “internal/report” modules.
- Server/REST API: In server mode, the tool exposes endpoints (implemented in pkg/server) to handle scanning requests programmatically.

##### Architectural Patterns and Technologies
- Modular Design: The division into “cmd”, “internal”, “pkg”, and “lib” indicates a clean separation between user interface, core libraries, and support utilities.
- Extensibility: The presence of multiple scanning modes and the REST API endpoint suggest the design supports plug-and-play functionality and future expansion (like custom payloads and remote wordlists).
- CLI-first Design: The architecture is centered on command-line interactions, with specialized modules for each scanning method.
- Language & Tools: The project is developed in Go (with dependency files like “go.mod” and “go.sum”), and integrates CI/CD workflows (GitHub Actions), a Dockerfile, and Snapcraft for deployment.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% CLI Layer
    subgraph "CLI Layer"
        CLI_Interface["CLI Interface (cmd)"]:::cli
        Command_Dispatch["Command Dispatcher"]:::cli
    end

    %% Scanning Engine
    subgraph "Scanning Engine"
        Parameter_Analysis["Parameter Analysis Module"]:::scanning
        Payload_Manager["Payload Manager (internal/payload)"]:::scanning
        Optimization_Engine["Optimization Engine (internal/optimization)"]:::scanning
        Direct_Scanner["Direct Scanning Engine"]:::scanning
    end

    %% HTTP Handling & Network Communication
    subgraph "HTTP Handling & Network"
        HAR_Processor["HAR Data Handler (internal/har)"]:::http
        Transport_Layer["HTTP Transport (pkg/scanning/transport.go)"]:::http
    end

    %% Reporting & Output
    subgraph "Reporting & Output"
        Printing_Engine["Printing Engine (internal/printing)"]:::reporting
        Report_Formatter["Report Formatter (internal/report)"]:::reporting
    end

    %% REST API / Server Module
    subgraph "REST API/Server"
        REST_ServerCmd["Server Command (cmd/server.go)"]:::api
        REST_ServerImpl["Server Implementation (pkg/server)"]:::api
    end

    %% Utility & Support Modules
    subgraph "Utilities & Support"
        Common_Utils["Common Utilities (internal/utils)"]:::util
        Shared_Lib["Shared Libraries (lib)"]:::util
        Data_Models["Data Models (pkg/model)"]:::util
    end

    %% Data flows
    CLI_Interface --> Command_Dispatch
    Command_Dispatch -->|"dispatches"| Parameter_Analysis
    Command_Dispatch -->|"dispatches"| Payload_Manager
    Command_Dispatch -->|"dispatches"| Optimization_Engine
    Command_Dispatch -->|"dispatches"| Direct_Scanner

    Parameter_Analysis -->|"generatesRequests"| HAR_Processor
    Payload_Manager -->|"suppliesPayloads"| HAR_Processor
    Optimization_Engine -->|"optimizes"| Direct_Scanner
    Direct_Scanner -->|"sendsRequests"| Transport_Layer
    HAR_Processor --> Transport_Layer

    Transport_Layer -->|"receivesResponses"| Printing_Engine
    Transport_Layer -->|"receivesResponses"| Report_Formatter

    REST_ServerCmd -->|"triggersScan"| Command_Dispatch
    REST_ServerImpl -->|"triggersScan"| Command_Dispatch

    Common_Utils --- Parameter_Analysis
    Common_Utils --- Payload_Manager
    Shared_Lib --- Parameter_Analysis
    Shared_Lib --- Optimization_Engine
    Data_Models --- Parameter_Analysis
    Data_Models --- Report_Formatter

    %% Click Events
    click CLI_Interface "https://github.com/hahwul/dalfox/tree/main/cmd/"
    click Command_Dispatch "https://github.com/hahwul/dalfox/tree/main/cmd/"
    click Parameter_Analysis "https://github.com/hahwul/dalfox/tree/main/pkg/scanning/"
    click Payload_Manager "https://github.com/hahwul/dalfox/tree/main/internal/payload/"
    click Optimization_Engine "https://github.com/hahwul/dalfox/tree/main/internal/optimization/"
    click HAR_Processor "https://github.com/hahwul/dalfox/tree/main/internal/har/"
    click Transport_Layer "https://github.com/hahwul/dalfox/blob/main/pkg/scanning/transport.go"
    click Printing_Engine "https://github.com/hahwul/dalfox/tree/main/internal/printing/"
    click Report_Formatter "https://github.com/hahwul/dalfox/tree/main/internal/report/"
    click REST_ServerCmd "https://github.com/hahwul/dalfox/blob/main/cmd/server.go"
    click REST_ServerImpl "https://github.com/hahwul/dalfox/tree/main/pkg/server/"
    click Common_Utils "https://github.com/hahwul/dalfox/tree/main/internal/utils/"
    click Shared_Lib "https://github.com/hahwul/dalfox/tree/main/lib/"
    click Data_Models "https://github.com/hahwul/dalfox/tree/main/pkg/model/"

    %% Styles
    classDef cli fill:#f9e79f,stroke:#000,stroke-width:2px;
    classDef scanning fill:#aed6f1,stroke:#000,stroke-width:2px;
    classDef http fill:#a9dfbf,stroke:#000,stroke-width:2px;
    classDef reporting fill:#f5cba7,stroke:#000,stroke-width:2px;
    classDef api fill:#d7bde2,stroke:#000,stroke-width:2px;
    classDef util fill:#f9c2c2,stroke:#000,stroke-width:2px;
```
