# anaer/sub architecture

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

- Interactive diagram: https://gitdiagram.com/anaer/sub
- Repository: https://github.com/anaer/sub

## Overview

##### Project type and purpose
- This repository holds Clash configuration files (clash.yaml and proxies.yaml) and serves as a proxy subscription/configuration manager.
- Its primary purpose is to collect and maintain proxy node lists (proxies.yaml), define routing rules (clash.yaml), and provide these configs to a Clash-compatible client.

##### File structure
- README.MD: Documentation and usage instructions.
- clash.yaml: Main Clash configuration (rules, proxy-group definitions, scheduled tasks).
- proxies.yaml: List of proxy node definitions (addresses, ports, credentials).

##### README for additional insights
- It mentions a timed task that updates clash.yaml (“节点定时任务跑”).
- It provides usage warnings and links to related tools (Quantumult X, mihomo).
- No code modules or services—this is purely configuration + scheduling.

##### Main system components
a. Configuration Store
– proxies.yaml (proxy node definitions)
– clash.yaml (routing rules + references to proxies.yaml)
b. Scheduler / Updater
– Cron job or CI task that periodically runs to refresh node lists
– May invoke a script or external subscription-fetch mechanism
c. External Subscription Sources
– Remote URLs or APIs from which proxy lists are pulled
d. Clash Client (runtime)
– Loads clash.yaml & proxies.yaml at startup or on reload
– Implements routing logic and connects to proxy servers
e. Proxy Servers (the actual nodes)
– The endpoints (from proxies.yaml) to which Clash forwards user traffic
f. End-User Device
– Device running Clash (desktop, mobile) generating network requests

##### Relationships and data flows
1. Scheduler → External Subscription Sources
- Fetch updated proxy lists on a schedule
2. Subscription Fetcher → proxies.yaml
- Writes/overwrites updated node definitions
3. Scheduler/Script → clash.yaml
- May merge new proxies into the config, update rule-group references
4. Clash Client → (reads) clash.yaml & proxies.yaml
- Loads routing rules and node lists
5. End-User Apps → Clash Client
- All DNS/HTTP/TCP requests are received by Clash
6. Clash Client → Proxy Servers
- Based on rules, forwards traffic to selected proxies

##### Architectural patterns and key principles
- Single Source of Truth for proxies (proxies.yaml)
- Separation of concerns:
– Scheduler/Updater (data acquisition)
– Configuration (YAML files)
– Runtime proxy engine (Clash)
- Cron-based refresh ensures configs stay up to date without manual intervention
- Declarative config approach—no custom code modules

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Acquisition Layer
    subgraph "Data Acquisition"
        Scheduler["Scheduler / Updater"]:::scheduler
        ExternalSubs["External Subscription Sources"]:::external
    end

    %% Configuration Store
    subgraph "Configuration Store"
        Proxies["proxies.yaml"]:::config
        ClashConfig["clash.yaml"]:::config
    end

    %% Runtime Layer
    subgraph "Runtime"
        ClashClient["Clash Client"]:::runtime
    end

    %% External Systems
    subgraph "External"
        EndUser["End-User Device"]:::external
        ProxyServers["Proxy Servers"]:::external
    end

    %% Documentation
    README["README.MD"]:::doc

    %% Connections
    Scheduler -->|"fetch proxy list"| ExternalSubs
    ExternalSubs -->|"write updated nodes"| Proxies
    Scheduler -->|"merge new proxies"| ClashConfig
    ClashClient -->|"load configs"| Proxies
    ClashClient -->|"load configs"| ClashConfig
    EndUser -->|"network requests"| ClashClient
    ClashClient -->|"forward traffic"| ProxyServers

    %% Click Events
    click Proxies "https://github.com/anaer/sub/blob/main/proxies.yaml"
    click ClashConfig "https://github.com/anaer/sub/blob/main/clash.yaml"
    click README "https://github.com/anaer/sub/blob/main/README.MD"

    %% Styles
    classDef config fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef scheduler fill:#e8f5e9,stroke:#2e7d32,color:#1b5e20
    classDef runtime fill:#fff3e0,stroke:#e65100,color:#bf360c
    classDef external fill:#eceff1,stroke:#37474f,color:#263238
    classDef doc fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
```
