# libnyanpasu/clash-nyanpasu architecture

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

- Interactive diagram: https://gitdiagram.com/libnyanpasu/clash-nyanpasu
- Repository: https://github.com/libnyanpasu/clash-nyanpasu

## Overview

Based on our analysis of the file tree and the README, Clash Nyanpasu is a desktop GUI application for the Clash network proxy that leverages Tauri for its desktop-side integration. In short, it is a full‐stack desktop application written in Rust (backend) with a modern web frontend (React/TypeScript with Material You styling and Tailwind CSS). The project is architected with a clear separation of concerns, where the Rust backend (with several dedicated crates and modules) handles core functions, IPC, plugins (like a deep linking plugin), and various services, while the frontend (in multiple directories such as “interface”, “nyanpasu”, and “ui”) implements the user interface and interacts with the backend via Tauri’s IPC mechanisms.

##### Main components
- Frontend User Interface:
– The “frontend/nyanpasu” directory contains the primary application UI built with React, styled with Material You design and Tailwind.
– The “frontend/interface” directory handles the communication and bindings (via Tauri IPC) between the frontend and the backend.
– The “frontend/ui” directory holds additional UI components and theme definitions.
- Backend (Rust/Tauri):
– The “backend/tauri” directory comprises the core Tauri application. It hosts modules for configuration, IPC handling, core functionality (e.g., service management, migration, updater, tray, and logging), and system integration.
– Other Rust crates like “nyanpasu-egui”, “boa_utils”, and “nyanpasu-macro” provide specialized utilities and macros that extend the application’s capabilities.
– The “tauri-plugin-deep-link” provides extra integration for deep linking.
- Build and Automation:
– Multiple GitHub workflow YAML files, Rust/Cargo configuration files, and scripts (in the “scripts” directory) handle building, dependency management, publishing, and continuous integration.
- External Dependencies and Integrations:
– The project relies on external services including Clash (the proxy backend), Clash Premium, Clash Rust, and even Mihomo among other related projects.

- Build automation and deployment engines (GitHub workflows, scripts) in a distinct section, showing their relationship to both the frontend and backend build processes.
- If desired, note external dependencies such as Clash, clarifying that the backend interacts with these services.

##### Important Architectural Patterns & Technologies
- Separation between the frontend and backend through a clear IPC boundary.
- That the backend follows modular design principles with separate Rust crates for utilities, UI integrations (nyanpasu-egui), and macro processing (nyanpasu-macro).
- Specify the use of Tauri as the glue that integrates the web-based frontend with native system capabilities on Windows, macOS, and Linux.
- For the frontend, mention the use of modern web technologies (React, Vite, TypeScript) and design systems (Material You, Tailwind).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Section
    subgraph "Frontend"
        FE_UI["React UI (nyanpasu)"]:::frontend
        FE_IPC["IPC Bindings (interface)"]:::frontend
        FE_Theme["UI Components & Theming (ui)"]:::frontend
    end

    %% Backend Section
    subgraph "Backend"
        TAURI["Tauri Core (tauri)"]:::backend
        UI_INT["Rust UI Integration (nyanpasu-egui)"]:::backend
        UTILS["Rust Utility Crate (boa_utils)"]:::backend
        MACRO["Rust Macro Processing (nyanpasu-macro)"]:::backend
        DEEP_LINK["Deep Linking Plugin (tauri-plugin-deep-link)"]:::backend
    end

    %% Build and Automation Section
    subgraph "Build and Automation"
        AUTOMATION["CI/CD & Scripts (.github/workflows & scripts)"]:::automation
    end

    %% External Dependencies Section
    subgraph "External Dependencies"
        CLASH["Clash Proxy"]:::external
        CLASH_PREMIUM["Clash Premium"]:::external
        CLASH_RUST["Clash Rust"]:::external
        MIHOMO["Mihomo"]:::external
    end

    %% Frontend to Backend Communication
    FE_IPC -->|"IPC"| TAURI
    FE_UI -->|"UI Command"| TAURI

    %% Backend Module Interactions
    TAURI -->|"Utilizes"| UI_INT
    TAURI -->|"Utilizes"| UTILS
    TAURI -->|"Utilizes"| MACRO
    TAURI -->|"Handles"| DEEP_LINK

    %% Build and Automation impact on Frontend and Backend
    AUTOMATION -->|"Builds"| FE_UI
    AUTOMATION -->|"Builds"| TAURI

    %% Backend and External Dependencies
    TAURI -->|"Integrates"| CLASH
    TAURI -->|"Integrates"| CLASH_PREMIUM
    TAURI -->|"Integrates"| CLASH_RUST
    TAURI -->|"Integrates"| MIHOMO

    %% Click Events
    click FE_UI "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/frontend/nyanpasu"
    click FE_IPC "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/frontend/interface"
    click FE_Theme "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/frontend/ui"
    click TAURI "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/backend/tauri"
    click UI_INT "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/backend/nyanpasu-egui"
    click UTILS "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/backend/boa_utils"
    click MACRO "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/backend/nyanpasu-macro"
    click DEEP_LINK "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/backend/tauri-plugin-deep-link"
    click AUTOMATION "https://github.com/libnyanpasu/clash-nyanpasu/tree/main/.github/workflows and scripts"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#0D47A1,stroke-width:2px;
    classDef backend fill:#C8E6C9,stroke:#1B5E20,stroke-width:2px;
    classDef automation fill:#FFE0B2,stroke:#E65100,stroke-width:2px;
    classDef external fill:#F8BBD0,stroke:#880E4F,stroke-width:2px;
```
