# nstrmx/goodbye-dpi architecture

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

- Interactive diagram: https://gitdiagram.com/nstrmx/goodbye-dpi
- Repository: https://github.com/nstrmx/goodbye-dpi

## Overview

##### Project Type and Purpose
- Type: A cross-platform, CLI-based proxy server / DPI-circumvention utility written in Rust.
- Purpose: Listen on a local TCP port, intercept HTTP(S) traffic from a browser, fragment the first TCP packet of each flow according to host‐based blacklists (Aho-Corasick), resolve DNS via configurable external providers, and forward each connection to the appropriate upstream proxy.

##### File Structure
- src/main.rs: entry point, orchestrates startup, configuration loading, listener setup.
- src/config.rs: parses YAML configuration (buffer sizes, proxy servers, blacklists, DNS settings).
- src/dns.rs: implements DNS resolution using Cloudflare, Google, Quad9 over TLS/HTTPS/TCP/UDP.
- src/client.rs: handles individual client connections, implements TCP fragmentation logic and proxy routing.
- default_blacklist, tor_blacklist, youtube_blacklist: text files loaded at runtime by the blacklist engine.
- config.yaml: example runtime configuration.

##### README for Architecture Insights
- Core algorithms: Aho-Corasick for pattern matching in blacklists, TCP-level fragmentation to evade DPI.
- External interactions: DNS providers (DoT, DoH), upstream proxy servers (e.g., TCP 127.0.0.1:8080, SOCKS5 127.0.0.1:9050).

##### Main Components
a. Internal Modules (Rectangles):
- Orchestrator / CLI (main.rs)
- Configuration Loader (config.rs)
- Blacklist Engine (Aho-Corasick)
- DNS Resolver (dns.rs)
- TCP Listener & Connection Handler (client.rs)
- Fragmentation Processor (first‐packet splitter)
- Proxy Router / Dispatcher
b. External Systems (Ovals):
- Browser (HTTP/S client)
- DNS Providers (Cloudflare, Google, Quad9)
- Upstream Proxy Servers (default TCP proxy, Tor SOCKS5, others)
- Blacklist Files (default_blacklist, tor_blacklist, …)
- YAML Config File (config.yaml)

##### Relationships & Data Flow
1. Browser → TCP Listener (127.0.0.1:8080)
2. Listener passes raw stream to Connection Handler
3. Handler invokes Fragmentation Processor on first packet
4. Connection Handler performs a DNS lookup via DNS Resolver
5. Resolver → External DNS Provider → Resolver returns IP
6. Handler queries Blacklist Engine with hostname to pick target proxy
7. Proxy Router → selected Upstream Proxy
8. Upstream Proxy ↔ External network → responses back along same path
9. Handler re-assembles fragments if needed and writes back to Browser

##### Architectural Patterns & Design Principles
- Modular Monolith: clear separation of concerns by module.
- Plugin-style Blacklists: plain text files drive host matching logic.
- Single entry point with pluggable subsystems (DNS, fragmentation, proxy routing).
- Asynchronous I/O (if implemented with Tokio or similar)—highlight if using async runtimes.

##### Relevant Technologies & Libraries
- Rust toolchain (Cargo, rustc)
- Aho-Corasick crate for multi‐pattern matching
- serde / serde_yaml for config parsing
- tokio or std::net for networking
- YAML for configuration
- External DNS protocols: DoH, DoT, UDP/TCP

- Are all internal components labeled and placed within a “Goodbye-DPI” boundary?
- Are external actors (Browser, DNS, Proxy Servers) clearly outside that boundary?

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Actors
    Browser(("Browser")):::external
    DNSProviders(("DNS Providers")):::external
    UpstreamProxy(("Upstream Proxy Servers")):::external

    subgraph "Goodbye-DPI Core"
        Orchestrator["Orchestrator / CLI"]:::internal
        ConfigLoader["Configuration Loader"]:::internal
        Listener["TCP Listener & Connection Handler"]:::internal
        Fragmentation["Fragmentation Processor"]:::internal
        DNSResolver["DNS Resolver"]:::internal
        BlacklistEngine["Blacklist Engine (Aho-Corasick)"]:::internal
        ProxyRouter["Proxy Router / Dispatcher"]:::internal
        default_blacklist[(default_blacklist)]:::datastore
        tor_blacklist[(tor_blacklist)]:::datastore
        youtube_blacklist[(youtube_blacklist)]:::datastore
        ConfigFile[(config.yaml)]:::datastore
    end

    %% Data Flows
    Browser -->|opens TCP stream| Listener
    Listener -->|first packet| Fragmentation
    Fragmentation -->|DNS lookup| DNSResolver
    DNSResolver -->|query| DNSProviders
    DNSProviders -->|response| DNSResolver
    DNSResolver -->|IP returned| Listener
    Listener -->|check host| BlacklistEngine
    BlacklistEngine -->|patterns| default_blacklist
    BlacklistEngine -->|patterns| tor_blacklist
    BlacklistEngine -->|patterns| youtube_blacklist
    Listener -->|route to proxy| ProxyRouter
    ProxyRouter -->|forward| UpstreamProxy
    UpstreamProxy -->|response| ProxyRouter
    ProxyRouter -->|back to handler| Listener
    Listener -->|response| Browser

    %% Click events
    click Orchestrator "https://github.com/nstrmx/goodbye-dpi/blob/master/src/main.rs"
    click ConfigLoader "https://github.com/nstrmx/goodbye-dpi/blob/master/src/config.rs"
    click DNSResolver "https://github.com/nstrmx/goodbye-dpi/blob/master/src/dns.rs"
    click Listener "https://github.com/nstrmx/goodbye-dpi/blob/master/src/client.rs"
    click Fragmentation "https://github.com/nstrmx/goodbye-dpi/blob/master/src/client.rs"
    click ProxyRouter "https://github.com/nstrmx/goodbye-dpi/blob/master/src/client.rs"
    click default_blacklist "https://github.com/nstrmx/goodbye-dpi/tree/master/default_blacklist"
    click tor_blacklist "https://github.com/nstrmx/goodbye-dpi/tree/master/tor_blacklist"
    click youtube_blacklist "https://github.com/nstrmx/goodbye-dpi/tree/master/youtube_blacklist"
    click ConfigFile "https://github.com/nstrmx/goodbye-dpi/blob/master/config.yaml"

    %% Styles
    classDef internal fill:#a2d2ff,stroke:#333,stroke-width:1px;
    classDef external fill:#bde0fe,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;
    classDef datastore fill:#ffe066,stroke:#333,stroke-width:1px,shape:cylinder;
```
