# lthero-big/smartdns_sniproxy_installer architecture

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

- Interactive diagram: https://gitdiagram.com/lthero-big/smartdns_sniproxy_installer
- Repository: https://github.com/lthero-big/smartdns_sniproxy_installer

## Overview

1. The “被解锁机” (the machine that “cannot unlock” content) which uses smartdns to manage DNS resolution and apply rules for media streaming services.
2. The “解锁机” (the machine that “can unlock” content) where sniproxy is installed to work as a transparent reverse proxy for streaming platforms.

##### Main Components
- Installer Script: At the core is the “smtdns_install.sh” script that acts as the interactive one-click configuration tool.
- Configuration File: “StreamConfig.yaml” which may be used to store or manage configuration options.
- README/Documentation: Although not an active component, the README outlines how commands map to functionalities.
- SmartDNS Service: Installed and configured on the “被解锁机”; its components include:
- Upstream DNS configuration (with either direct IP addresses or nameserver choices).
- DNS domains assigned for different streaming platforms and the grouping mechanism.
- Sniproxy Service: Installed on the “解锁机” and configured through options (e.g., starting, stopping services, adding proxy rules).
- User Input/CLI Menu: This offers a simple text-based UI for selecting different functions like installing smartdns, adding streaming platforms, configuring firewall rules, etc.
- External DNS Unlock Services: For example, the free Alice DNS unlocking service, which may be referenced if users do not operate their own unlocking VPS.

##### Relationships and Interactions
- The installer script (smtdns_install.sh) is the entry point; it takes user input and then configures the SmartDNS and/or sniproxy services.
- For the “被解锁机”: The script will install SmartDNS, configure upstream DNS, and establish domain-to-DNS mappings.
- For the “解锁机”: The script installs and configures sniproxy, linking it to the proper network interfaces and opening necessary ports (80/443/53) for secure reverse proxying.
- There's a clear connection between user selection in the CLI and changes applied to SmartDNS/sniproxy configurations. Additionally, there is a flow between smartdns acting on DNS resolution and sniproxy handling reverse proxy requests.
- Including external unlocking services (Alice) as part of the flow where if a user chooses nameserver over address, then lookup redirection is performed.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Differentiating configuration and management tasks for smartdns (DNS manipulation) versus sniproxy (streaming proxy).
- Modular Design: Each function in the menu (installation, reconfiguration, DNS grouping, proxy configuration, firewall setup) is modular and follows a clear branch in the overall flow.
- Interactive CLI-driven orchestration: The installer script drives service installation and configuration based on input choices.
- Scalability in configuration: The possibility of running smartdns on “解锁机” for a nested unlocking configuration showcases flexibility in design.

##### Relevant Technologies and Frameworks
- Shell Scripting (Bash), which is used for the installer.
- SmartDNS and sniproxy as the primary services.
- Typical Linux firewall and service management utilities (such as ufw and systemctl) for controlling service status and port access.
- YAML for configuration representation (StreamConfig.yaml).

##### Elements
- Labels: Ensure every component is clearly labeled with its role (e.g., “Installer Script”, “SmartDNS Service (被解锁机)”, “sniproxy Service (解锁机)”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        CLI["CLI Menu: UserInput"]:::cli
    end

    subgraph "Installer"
        INST["Installer Script\n(smtdns_install.sh)"]:::installer
    end

    CLI -->|"UserInput"| INST

    subgraph "被解锁机: SmartDNS Configuration"
        SMARTDNS["SmartDNS Service"]:::service
        UPSTREAM["UpstreamDNSConfiguration"]:::service
        DNSDOM["DNSDomains&Grouping"]:::service
        CONFIG["Configuration File\n(StreamConfig.yaml)"]:::config
        EXTERNAL["External:AliceDNSUnlockService"]:::external
        SMARTDNS -->|"Setup"| UPSTREAM
        SMARTDNS -->|"Setup"| DNSDOM
        UPSTREAM -->|"Nameserver"| EXTERNAL
        DNSDOM -->|"Persist"| CONFIG
    end

    subgraph "解锁机: sniproxy Configuration"
        SNIPROXY["sniproxy Service"]:::service
        PROXY["ReverseProxySetup"]:::service
        FIREWALL["Firewall&PortSettings"]:::service
        SNIPROXY -->|"Configure"| PROXY
        SNIPROXY -->|"Configure"| FIREWALL
    end

    INST -->|"Configure"| SMARTDNS
    INST -->|"Configure"| SNIPROXY

    DOC["Documentation\n(README.md)"]:::doc
    INST --- DOC

    click INST "https://github.com/lthero-big/smartdns_sniproxy_installer/blob/main/smtdns_install.sh"
    click CONFIG "https://github.com/lthero-big/smartdns_sniproxy_installer/blob/main/StreamConfig.yaml"
    click DOC "https://github.com/lthero-big/smartdns_sniproxy_installer/blob/main/README.md"

    classDef cli fill:#f4d03f,stroke:#000,stroke-width:2px;
    classDef installer fill:#aed6f1,stroke:#000,stroke-width:2px;
    classDef service fill:#d5f5e3,stroke:#000,stroke-width:2px;
    classDef external fill:#f5b7b1,stroke:#000,stroke-width:2px;
    classDef config fill:#d2b4de,stroke:#000,stroke-width:2px;
    classDef doc fill:#f9e79f,stroke:#000,stroke-width:2px;
```
