# swagnikdutta/netprobe architecture

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

- Interactive diagram: https://gitdiagram.com/swagnikdutta/netprobe
- Repository: https://github.com/swagnikdutta/netprobe

## Overview

##### Main Components
- Command-Line Interface (CLI) Component:
- Represented by the cmd/main.go file.
- This is the entry point (npctl) which interacts with the user and invokes various underlying network utilities.

- Dialer Module:
- Located in pkg/dialer.
- Provides the abstraction for making network connections.

- Protocol Implementations:
- Found in pkg/protocols – with subdirectories for “icmp” and “ipv4”.
- Each protocol directory contains implementation files (e.g., icmp.go, ipv4.go), serializers, and type definitions for handling protocol-specific data and communication.

- Utilities:
- Located in pkg/utilities.
- Contains the “dig” subpackage (for DNS lookups) and the “ping” subpackage (for ICMP-based latency checks), along with some general network helper functions.

- General Utilities:
- pkg/utils.go and pkg/protocols/util.go serve to provide common helper functions shared across various modules.

##### Relationships and Data Flow
- The CLI (cmd/main.go) interacts with the user and issues commands.
- When a command is received (for example, to perform a “ping” or “dig”), the CLI calls into the appropriate utility function from pkg/utilities/ping or pkg/utilities/dig.
- These utilities rely on the underlying protocol implementations in pkg/protocols (ICMP for ping, IPv4 for low-level networking operations) to correctly format, serialize, and handle network packets.
- The dialer (pkg/dialer) provides the necessary low-level control for establishing network connections, feeding into the protocol modules.
- The common utilities ensure that configurations, logging, and network data processing are consistent across the modules.

##### Architectural Patterns and Design Principles
- Layered Architecture: There is a clear separation between the user interface (CLI), core networking logic (protocol and utility packages), and low-level network operations (dialer).
- Modularity: Each protocol (ICMP, IPv4) and utility (dig, ping) are encapsulated in their own package, which improves maintainability and extensibility.
- Abstraction: The dialer package abstracts network connection details, while the protocol packages abstract the specifics of handling network packet structures and serialization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top Layer: CLI
    subgraph "User Interface Layer"
        CLI["CLI (npctl)"]:::cli
    end

    %% Middle Layer: Utilities
    subgraph "Utilities Layer"
        Ping["Ping Utility"]:::utility
        Dig["Dig Utility"]:::utility
    end

    %% Middle Layer: Protocols
    subgraph "Protocols Layer"
        ICMP["ICMP Protocol"]:::protocol
        IPv4["IPv4 Protocol"]:::protocol
    end

    %% Side Node: Shared Utilities
    Shared["Shared Utilities"]:::shared

    %% Bottom Layer: Dialer
    subgraph "Network Layer"
        Dialer["Dialer Module"]:::dialer
    end

    %% Data Flow Connections
    CLI -->|"CommandInvocation"| Ping
    CLI -->|"CommandInvocation"| Dig

    Ping -->|"PacketProcessing"| ICMP
    Dig  -->|"PacketProcessing"| IPv4

    ICMP -->|"NetworkIO"| Dialer
    IPv4 -->|"NetworkIO"| Dialer

    %% Shared Utilities dotted connections
    Ping -.->|"uses"| Shared
    Dig -.->|"uses"| Shared
    ICMP -.->|"common"| Shared
    IPv4 -.->|"common"| Shared

    %% Click Events
    click CLI "https://github.com/swagnikdutta/netprobe/blob/main/cmd/main.go"
    click Dialer "https://github.com/swagnikdutta/netprobe/tree/main/pkg/dialer"
    click ICMP "https://github.com/swagnikdutta/netprobe/tree/main/pkg/protocols/icmp"
    click IPv4 "https://github.com/swagnikdutta/netprobe/tree/main/pkg/protocols/ipv4"
    click Ping "https://github.com/swagnikdutta/netprobe/tree/main/pkg/utilities/ping"
    click Dig "https://github.com/swagnikdutta/netprobe/tree/main/pkg/utilities/dig"
    click Shared "https://github.com/swagnikdutta/netprobe/blob/main/pkg/utils.go"

    %% Styles
    classDef cli fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef utility fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef protocol fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef dialer fill:#FFB347,stroke:#000,stroke-width:2px;
    classDef shared fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
