# jagt/clumsy architecture

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

- Interactive diagram: https://gitdiagram.com/jagt/clumsy
- Repository: https://github.com/jagt/clumsy

## Overview

##### Main Components
- Packet Capture/Injection Layer: This layer is built on top of the WinDivert library (located under external/WinDivert-… directories). It handles interception of live network packets from the Windows network stack.
- Core Packet Processing/Manipulation Modules: In the “src” directory, there are several C source files (e.g., lag.c, drop.c, duplicate.c, tamper.c, throttle.c, packet.c) which indicate that different packet manipulation functions are implemented as separate modules. There is also a “common.h” that likely holds shared definitions.
- User Interface (UI) and Interactive Control: The project leverages IUP (found under external/iup-… directories) to create an interactive GUI. This module receives user input (e.g., when to start dropping or delaying packets) and provides visual feedback (as seen in the demo gif mentioned in the README).
- Configuration and Runtime Resource Files: The “etc” directory contains configuration, manifest, and resource files like clumsy.rc and config.txt, which likely support runtime settings and define application properties.
- Build and Script Infrastructure: Files such as build.zig and the scripts in the “scripts” folder represent the build and execution support, ensuring the project can be configured and launched correctly.

##### Relationships and Data Flow
- Client/User → UI Module: The user interacts with the GUI (built with IUP), triggering network manipulations.
- UI Module → Core Packet Processing: The UI sends commands to the underlying processing components that are implemented in various “*.c” files. Each module (for example, drop, lag, duplicate) is responsible for a specific network condition simulation.
- Core Processing → WinDivert Driver/Library: The core logic makes calls to the WinDivert library to capture live network packets. The library acts as the bridge between the user-level application and the network driver, manipulating packets as directed by the user.
- Configuration Files → Initialization/Runtime Control: At startup, configuration files (from the “etc” directory) may be read to set initial parameters or modify the behavior of the application.

##### Architectural Patterns and Design Principles
- Modular Design: The source files are organized functionally such that each packet manipulation behavior is encapsulated in its own module, enhancing clarity and maintainability.
- External Dependency Integration: The design incorporates libraries like WinDivert for low-level packet handling and IUP for the GUI. These should be highlighted as foundational external components that the application relies on.

## Diagram (Mermaid)

```mermaid
flowchart TD
    User["User"]
    ui["IUP-based UI/Control Module"]:::ui
    srcModules["Core Processing Modules (lag,drop,duplicate,tamper,throttle)"]:::core
    winDivert["WinDivert Library/Driver"]:::windivert

    subgraph "Support Infrastructure"
        config["Configuration Files"]:::config
        build["Build Infrastructure"]:::build
        scripts["Script Infrastructure"]:::build
    end

    User -->|"triggers"| ui
    ui -->|"sends_commands"| srcModules
    srcModules -->|"processes_packets"| winDivert
    winDivert -->|"feedback"| srcModules

    config -->|"initializes"| ui
    config -->|"initializes"| srcModules
    build -->|"builds"| ui
    scripts -->|"scripts"| ui

    click ui "https://github.com/jagt/clumsy/blob/master/external/iup-3.30_Win32_dll16_lib"
    click srcModules "https://github.com/jagt/clumsy/tree/master/src"
    click winDivert "https://github.com/jagt/clumsy/blob/master/external/WinDivert-2.2.0-A"
    click config "https://github.com/jagt/clumsy/tree/master/etc"
    click build "https://github.com/jagt/clumsy/blob/master/build.zig"
    click scripts "https://github.com/jagt/clumsy/tree/master/scripts"

    classDef ui fill:#66ccff,stroke:#333,stroke-width:2px;
    classDef core fill:#8fbc8f,stroke:#333,stroke-width:2px;
    classDef windivert fill:#ff6666,stroke:#333,stroke-width:2px;
    classDef config fill:#d3d3d3,stroke:#333,stroke-width:2px;
    classDef build fill:#d3d3d3,stroke:#333,stroke-width:2px;
```
