# wuqb2i4f/xray-config-toolkit architecture

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

- Interactive diagram: https://gitdiagram.com/wuqb2i4f/xray-config-toolkit
- Repository: https://github.com/wuqb2i4f/xray-config-toolkit

## Overview

##### Main Components to Highlight
- CI/CD Workflows: In “.github/workflows”, you have three YAML files (workflow-stage-1.yml, workflow-stage-2.yml, workflow-stage-3.yml) that clearly define parallel or sequential stages. These workflows trigger the generation and testing of the configuration files.
- Script Executor Engine: Under “src/bash” you see multiple subdirectories (base64, check, common, custom, fetch, local, main, sed) that house various Bash scripts. These are responsible for orchestrating how templates are read, processed, and converted into outputs.
- Template Processor: The “src/template” directory contains Markdown templates used to generate base configuration snippets (protocols, network types, security layers) that are later filled in by the scripts.
- Output Generator: The “output” directory holds the final generated configuration files, partitioned by format (base64, json, cloudflare worker scripts, etc.). Although Cloudflare worker and the Xray folder are present, they are less critical here.

##### Relationships and Interactions
- The CI/CD workflows are the entry point: They trigger the execution of the bash scripts.
- During a workflow run (stage 1 to stage 3), the “src/bash/main” or related scripts call different script modules (like “fetch”, “check”, “sed”) to process configuration rules and pull in values from environment variables or external sources.
- The scripts use the files from “src/template” to render the configuration details and then deposit the final products under “output” (in multiple formats).
- These outputs are then made available via public URLs as described in the README.

##### Architectural Patterns and Technologies
- Pipeline/Workflow Pattern: The project clearly uses a multi-stage CI/CD pipeline, with each stage building upon the work of the previous one.
- Modular Scripting: The division of bash scripts into several subdirectories illustrates a modular design. Each module performs a specific task (for example, base64 encoding, fetching data, or text processing with sed).
- Template-Based Generation: The use of standard templates facilitates the creation of numerous variations (protocol, network, and security configurations).
- GitHub Actions: As the mechanism for automation, indicating how code commits trigger the workflows.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD Workflows Subgraph
    subgraph "CI/CD Workflows"
        WS1("Workflow Stage 1"):::workflows
        WS2("Workflow Stage 2"):::workflows
        WS3("Workflow Stage 3"):::workflows
        WS1 -->|"triggers"| WS2
        WS2 -->|"triggers"| WS3
    end

    %% Bash Script Engine Node with Modules
    BSE("Bash Script Engine"):::script
    subgraph "Script Modules"
        BASE64("Base64"):::script
        CHECK("Check"):::script
        COMMON("Common"):::script
        CUSTOM("Custom"):::script
        FETCH("Fetch"):::script
        LOCAL("Local"):::script
        MAIN("Main"):::script
        SED("Sed"):::script
        BASE64 --> CHECK
        CHECK --> COMMON
        COMMON --> CUSTOM
        CUSTOM --> FETCH
        FETCH --> LOCAL
        LOCAL --> MAIN
        MAIN --> SED
    end

    %% Template Processor with Template Files
    TP("Template Processor"):::template
    subgraph "Templates"
        T0("0-base.md"):::template
        T1("1-protocol-*.md"):::template
        T2("2-network-*.md"):::template
        T3("3-security-*.md"):::template
        T0 --> T1
        T1 --> T2
        T2 --> T3
    end

    %% Output Generator with Outputs
    OG("Output Generator"):::output
    subgraph "Outputs"
        OB("Base64 Output"):::output
        OJ("JSON Output"):::output
        OC("Cloudflare Worker Output"):::auxiliary
        OB --> OJ
        OJ --> OC
    end

    %% Auxiliary Xray Module (De-emphasized)
    XM("Xray Module (Auxiliary)"):::auxiliary

    %% Connections between main components
    WS3 -->|"triggers"| BSE
    BSE -->|"processes"| TP
    TP -->|"generates"| OG
    OG ---|"tested against"| XM

    %% Click Events for CI/CD Workflows
    click WS1 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/.github/workflows/workflow-stage-1.yml"
    click WS2 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/.github/workflows/workflow-stage-2.yml"
    click WS3 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/.github/workflows/workflow-stage-3.yml"

    %% Click Events for Script Executor Engine and its Modules
    click BSE "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash"
    click BASE64 "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/base64"
    click CHECK "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/check"
    click COMMON "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/common"
    click CUSTOM "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/custom"
    click FETCH "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/fetch"
    click LOCAL "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/local"
    click MAIN "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/main"
    click SED "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/bash/sed"

    %% Click Events for Template Processor and its Templates
    click TP "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/template"
    click T0 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/src/template/0‑base.md"
    click T1 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/src/template/1‑protocol‑*.md"
    click T2 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/src/template/2‑network‑*.md"
    click T3 "https://github.com/wuqb2i4f/xray-config-toolkit/blob/main/src/template/3‑security‑*.md"

    %% Click Events for Output Generator and its Outputs
    click OG "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/output"
    click OB "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/output/base64"
    click OJ "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/output/json"
    click OC "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/output/cloudflare"

    %% Click Event for Auxiliary Xray Module
    click XM "https://github.com/wuqb2i4f/xray-config-toolkit/tree/main/src/xray"

    %% Styles
    classDef workflows fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef script fill:#d4edda,stroke:#333,stroke-width:2px;
    classDef template fill:#fff3cd,stroke:#333,stroke-width:2px;
    classDef output fill:#d1ecf1,stroke:#333,stroke-width:2px;
    classDef auxiliary fill:#e2e3e5,stroke:#333,stroke-dasharray: 5,5,stroke-width:2px;
```
