# sergeydigl3/zapret-discord-youtube-linux architecture

> Architecture diagram of the GitHub repository sergeydigl3/zapret-discord-youtube-linux, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sergeydigl3/zapret-discord-youtube-linux
- Repository: https://github.com/sergeydigl3/zapret-discord-youtube-linux

## Overview

##### Project type and purpose
- This is a CLI/DevOps “adapter” project: a set of Bash scripts and a small helper binary (`nfqws`) that automates installing, configuring, and running a specific network-firewall strategy for bypassing YouTube throttling on Linux via `nftables`.
- It bundles a hard-coded Flowseal configuration (pulled from a specific commit), lets the user choose among `.bat` strategy files, applies them via `nftables` + the `nfqws` process, and can register itself as a systemd service for automatic startup.

##### File structure
- Top-level scripts:
- `main_script.sh` (installer/interactive runner)
- `rename_bat.sh` (helper to normalize strategy filenames)
- `service.sh` (creates/updates a systemd unit)
- `stop_and_clean_nft.sh` (teardown helper)
- `nfqws/` directory (compiled binary and support files)
- Config file: a generated `conf.env` defining `strategy`, `auto_update`, and `interface`.
- No frontend/backend split—this is a single “automation service” component.
- Deployment: systemd unit, leveraging standard Linux filesystem and `nftables`, plus optional auto-update logic.

##### README for additional insights
- Describes interactive vs. non-interactive mode, configuration persistence in `conf.env`, service installation, and cleanup behavior.
- Emphasizes reliance on `nftables` and `systemd`.
- Notes external dependency: the Flowseal GitHub repo for `.bat` strategies.

a. Main components
- User CLI (invokes `main_script.sh` or `service.sh`)
- Script layer (Bash scripts)
- Configuration store (`conf.env`)
- Strategy files (*.bat) fetched/renamed by `rename_bat.sh`
- Binary process (`nfqws`)
- Systemd (unit file `zapret_discord_youtube.service`)
- `nftables` (kernel firewall subsystem)
- Network interface (e.g., `enp0s3`)
- External GitHub repo (Flowseal strategies)
b. Relationships and interactions
1. User → CLI
- `main_script.sh` reads user input or `conf.env`.
2. CLI → rename-bat sub-script
- Normalizes `.bat` strategy filenames.
3. CLI → strategy fetch
- Optionally clones/updates `zapret-latest` from Flowseal.
4. CLI → `nftables` rules
- Applies or flushes rules via `nft` commands.
5. CLI → `nfqws` process
- Launches `nfqws`, passing the chosen strategy.
6. service.sh → systemd
- Generates a `.service` file referencing `main_script.sh -nointeractive`.
7. systemd → script at boot
- Ensures `nfqws` is running and `nftables` rules applied.
8. stop-and-clean → teardown
- Removes rules and stops background processes.
c. Architectural patterns / principles
- Separation of concerns:
- Interactive installer vs. non-interactive service mode
- Dedicated helper scripts for renaming and cleanup
- Centralized configuration (`conf.env`)
- Declarative service definition via systemd
- Idempotent firewall management (flush vs. apply)
d. Key technologies/frameworks
- Bash scripting
- systemd service management
- nftables (via `nft` CLI)
- nfqueue helper binary (`nfqws`)
- Git for fetching external configs

##### Elements
- CLI → rename script
- CLI → Git fetch
- CLI → nfqws
- CLI → nftables
- service.sh → systemd
- systemd → main_script.sh at boot

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Installation Phase
    subgraph "Installation Phase"
        direction TB
        UserCLI["User CLI\n(main_script.sh)"]:::script
        Rename["rename_bat.sh"]:::script
        Flowseal["Flowseal GitHub Repo"]:::external
        Config["conf.env"]:::config
        Nftables["nftables"]:::system
        Binary["nfqws"]:::binary
        ServiceInstaller["service.sh"]:::script

        UserCLI -->|"normalize strategies"| Rename
        Rename -->|"updates strategy names"| Config
        UserCLI -->|"fetch strategies"| Flowseal
        UserCLI -->|"initialize config"| Config
        UserCLI -->|"apply firewall rules"| Nftables
        UserCLI -->|"launch nfqws with strategy"| Binary
        UserCLI -->|"install service"| ServiceInstaller
        ServiceInstaller -->|"generates unit file"| Systemd
    end

    %% Runtime Phase
    subgraph "Runtime Phase"
        direction TB
        Systemd["systemd"]:::system
        RunScript["main_script.sh\n(non-interactive)"]:::script
        Systemd -->|"on boot | executes"| RunScript
        RunScript -->|"reads config"| Config
        RunScript -->|"apply/flush rules"| Nftables
        RunScript -->|"launch nfqws"| Binary
    end

    %% Teardown Phase
    subgraph "Teardown Phase"
        direction TB
        Teardown["stop_and_clean_nft.sh"]:::script
        Teardown -->|"flush rules"| Nftables
        Teardown -->|"stop nfqws"| Binary
    end

    %% External Documentation
    README["Project README"]:::external
    Flowseal --> README

    %% Click Events
    click UserCLI "https://github.com/sergeydigl3/zapret-discord-youtube-linux/blob/stable3/main_script.sh"
    click Rename "https://github.com/sergeydigl3/zapret-discord-youtube-linux/blob/stable3/rename_bat.sh"
    click ServiceInstaller "https://github.com/sergeydigl3/zapret-discord-youtube-linux/blob/stable3/service.sh"
    click Teardown "https://github.com/sergeydigl3/zapret-discord-youtube-linux/blob/stable3/stop_and_clean_nft.sh"
    click Binary "https://github.com/sergeydigl3/zapret-discord-youtube-linux/tree/stable3/nfqws/"
    click README "https://github.com/sergeydigl3/zapret-discord-youtube-linux/blob/stable3/README.md"

    %% Styles
    classDef script fill:#f9f,stroke:#333,stroke-width:1px;
    classDef binary fill:#ff9,stroke:#333,stroke-width:1px;
    classDef system fill:#9ff,stroke:#333,stroke-width:1px;
    classDef config fill:#cfc,stroke:#333,stroke-width:1px,stroke-dasharray:5 5;
    classDef external fill:#ccc,stroke:#333,stroke-width:1px,stroke-dasharray:5 5;
```
