# bhaskardharma/network_sniffing architecture

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

- Interactive diagram: https://gitdiagram.com/bhaskardharma/network_sniffing
- Repository: https://github.com/bhaskardharma/network_sniffing

## Overview

##### Project type and purpose
- This is a small, single-script, CLI network-sniffing tool written in Python. Its purpose is to capture and display (or log) network packets in real time using the Scapy library.

##### File structure
- Top-level files:
- README.md — describes usage and purpose
- sniffer.py — the sole Python script that imports Scapy and performs packet sniffing
- No “frontend” or “backend” directories—this is a standalone utility
- No build or deployment scripts—just a direct Python invocation

##### README for additional insights
- Confirms the use of Scapy for packet capture and decoding
- Usage instructions: clone repo, cd into it, run `python sniffer.py`

##### Main components and their relationships
a. User / CLI
– Invokes sniffer.py from a shell
b. sniffer.py (Application Logic)
– Defines packet-capture filters, callbacks, and display/storage logic
c. Scapy library
– Provides the programmatic API for raw socket access, packet parsing, and crafting
d. libpcap / OS Kernel Network Stack
– Underlying subsystem that actually sniffs packets at the NIC level
e. Network Interface (Ethernet/Wi-Fi)
– The source of raw traffic (LAN, Internet)
f. Output sink
– Console stdout, log file, or other storage mechanism

Relationships & Data Flow:
User → (runs) → sniffer.py → (calls) → Scapy → (interfaces with) → libpcap/Kernel → (reads) → Network Interface
Then reverse: packets flow from Network → Kernel → Scapy → sniffer.py → Console/File → User

##### Architectural patterns & design principles
- Single-process, imperative CLI tool
- Layered abstraction:
- sniffer.py (application layer)
- Scapy (library layer)
- libpcap/Kernel (system layer)
- Network Hardware (external layer)
- Clear separation of concerns: sniffing/filtering logic vs. packet parsing vs. output formatting

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Network to Kernel to Library to Application to Output
    Network{"Network Interface"}:::external
    Kernel{{"libpcap / OS Kernel"}}:::kernel
    Scapy("Scapy Library"):::code
    App["sniffer.py"]:::code
    Output[(Output Sink)]:::code
    User("User / CLI"):::external
    README["README.md"]:::code

    %% Data flow
    Network -->|"packet capture"| Kernel
    Kernel -->|"raw socket access"| Scapy
    Scapy -->|"import & API calls"| App
    App -->|"print/log packets"| Output

    %% User interaction and docs
    User -->|"python sniffer.py"| App
    README -.-> User

    %% Click events
    click App "https://github.com/bhaskardharma/network_sniffing/blob/main/sniffer.py"
    click README "https://github.com/bhaskardharma/network_sniffing/blob/main/README.md"

    %% Styles
    classDef external fill:#a8ddb5,stroke:#333,stroke-width:1px
    classDef kernel fill:#cbcbcb,stroke:#333,stroke-width:1px
    classDef code fill:#9ecae1,stroke:#333,stroke-width:1px
```
