# ph2n1a/zapret2-tui architecture

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

- Interactive diagram: https://gitdiagram.com/ph2n1a/zapret2-tui
- Repository: https://github.com/ph2n1a/zapret2-tui

## Overview

zapret2-tui is a Linux terminal interface for managing zapret2 strategy profiles, not a standalone DPI-bypass engine. The main workflow loads configuration and profiles, prepares profile configs, then runs an interactive loop that accepts input, updates application state, and redraws the interface. Users can apply a profile, manage the zapret2 service, and optionally test one or all profiles through NFQUEUE and HTTPS. The README documents these capabilities; links for some core actions rely on that documentation because their implementation excerpts were not provided.

Main entry points: [`src/main.c`](https://github.com/ph2n1a/zapret2-tui/blob/main/src/main.c) (Program entry), [`src/ui/app.c`](https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/app.c) (Application loop), [`src/ui/core.c`](https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/core.c) (Action handling), [`src/core/testing_profiles.c`](https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/testing_profiles.c) (Profile testing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup and configuration"]
  node_main["Program entry<br/>[main.c]"]
  node_dependency_check["Dependency check"]
  node_app_config["App configuration<br/>[readconf.c]"]
  node_zapret_reader["zapret config reader<br/>[read_zapret_conf.c]"]
  node_first_run["First-run wizard<br/>[first_start.c]"]
  node_logging[("Application logging<br/>[log.c]")]
end

subgraph group_interface["Interactive interface"]
  node_app_loop["Application loop<br/>[app.c]"]
  node_input["Input handling<br/>[input.c]"]
  node_state_actions["Action handling<br/>[core.c]"]
  node_screen["Interface rendering<br/>[ui.c]"]
end

subgraph group_profiles["Profile management"]
  node_profile_config["Profile configuration<br/>[readconf.c]"]
  node_profile_generator["Profile config generation"]
  node_profile_apply["Profile application<br/>[create_link.c]"]
end

subgraph group_testing["Profile testing"]
  node_profile_tester["Profile testing<br/>[testing_profiles.c]"]
  node_nfqueue["NFQUEUE rules"]
end

node_operator(("Operator"))
node_zapret_service["zapret2 service"]
node_https_target(("HTTPS test domain"))

node_operator -->|"launches"| node_main
node_main -->|"checks dependencies"| node_dependency_check
node_main -->|"loads config"| node_app_config
node_main -->|"starts wizard"| node_first_run
node_main -->|"reads zapret config"| node_zapret_reader
node_main -->|"loads profiles"| node_profile_config
node_main -->|"prepares configs"| node_profile_generator
node_main -->|"initializes app"| node_app_loop
node_operator -->|"uses controls"| node_app_loop
node_app_loop -->|"polls input"| node_input
node_app_loop -->|"updates state"| node_state_actions
node_app_loop -->|"draws interface"| node_screen
node_state_actions -->|"applies profile"| node_profile_apply
node_profile_apply -->|"copies active config"| node_zapret_service
node_state_actions -->|"controls service"| node_zapret_service
node_state_actions -->|"starts tests"| node_profile_tester
node_profile_tester -->|"sets queue rules"| node_nfqueue
node_profile_tester -->|"sends HTTPS test"| node_https_target
node_main -->|"logs startup"| node_logging

click node_main "https://github.com/ph2n1a/zapret2-tui/blob/main/src/main.c"
click node_dependency_check "https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/check_dependencies.c"
click node_app_config "https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/readconf.c"
click node_zapret_reader "https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/read_zapret_conf.c"
click node_first_run "https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/first_start.c"
click node_app_loop "https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/app.c"
click node_input "https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/input.c"
click node_state_actions "https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/core.c"
click node_screen "https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/ui.c"
click node_profile_config "https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/readconf.c"
click node_profile_generator "https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/create_zapret_configs.c"
click node_profile_apply "https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/create_link.c"
click node_profile_tester "https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/testing_profiles.c"
click node_logging "https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/log.c"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_dependency_check,node_app_config,node_zapret_reader,node_first_run,node_logging toneBlue
class node_app_loop,node_input,node_state_actions,node_screen toneAmber
class node_profile_config,node_profile_generator,node_profile_apply toneMint
class node_profile_tester,node_nfqueue toneRose
class node_operator,node_zapret_service,node_https_target toneIndigo
```

## Components

### Startup and configuration

- [Program entry](https://github.com/ph2n1a/zapret2-tui/blob/main/src/main.c): `src/main.c`
- [Dependency check](https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/check_dependencies.c): `src/utils/check_dependencies.c`
- [App configuration](https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/readconf.c): `src/utils/readconf.c`
- [zapret config reader](https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/read_zapret_conf.c): `src/core/read_zapret_conf.c`
- [First-run wizard](https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/first_start.c): `src/core/first_start.c`
- [Application logging](https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/log.c): `src/utils/log.c`

### Interactive interface

- [Application loop](https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/app.c): `src/ui/app.c`
- [Input handling](https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/input.c): `src/ui/input.c`
- [Action handling](https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/core.c): `src/ui/core.c`
- [Interface rendering](https://github.com/ph2n1a/zapret2-tui/blob/main/src/ui/ui.c): `src/ui/ui.c`

### Profile management

- [Profile configuration](https://github.com/ph2n1a/zapret2-tui/blob/main/src/utils/readconf.c): `src/utils/readconf.c`
- [Profile config generation](https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/create_zapret_configs.c): `src/core/create_zapret_configs.c`
- [Profile application](https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/create_link.c): `src/core/create_link.c`

### Profile testing

- [Profile testing](https://github.com/ph2n1a/zapret2-tui/blob/main/src/core/testing_profiles.c): `src/core/testing_profiles.c`
- **NFQUEUE rules**

### Other components

- **Operator**
- **zapret2 service**
- **HTTPS test domain**

## Connections

- Operator → Program entry: launches (evidence: `README.md`)
- Program entry → Dependency check: checks dependencies (evidence: `src/main.c`)
- Program entry → App configuration: loads config (evidence: `src/main.c`)
- Program entry → First-run wizard: starts wizard (evidence: `src/main.c`)
- Program entry → zapret config reader: reads zapret config (evidence: `src/main.c`)
- Program entry → Profile configuration: loads profiles (evidence: `src/main.c`)
- Program entry → Profile config generation: prepares configs (evidence: `src/main.c`)
- Program entry → Application loop: initializes app (evidence: `src/main.c`)
- Operator → Application loop: uses controls (evidence: `README.md`)
- Application loop → Input handling: polls input (evidence: `src/ui/app.c`)
- Application loop → Action handling: updates state (evidence: `src/ui/app.c`)
- Application loop → Interface rendering: draws interface (evidence: `src/ui/app.c`)
- Action handling → Profile application: applies profile (evidence: `README.md`)
- Profile application → zapret2 service: copies active config (evidence: `README.md`)
- Action handling → zapret2 service: controls service (evidence: `README.md`)
- Action handling → Profile testing: starts tests (evidence: `README.md`)
- Profile testing → NFQUEUE rules: sets queue rules (evidence: `README.md`)
- Profile testing → HTTPS test domain: sends HTTPS test (evidence: `README.md`)
- Program entry → Application logging: logs startup (evidence: `src/main.c`)
