# mihomo-party-org/mihomo-party architecture

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

- Interactive diagram: https://gitdiagram.com/mihomo-party-org/mihomo-party
- Repository: https://github.com/mihomo-party-org/mihomo-party

## Overview

##### Main Components
- Electron Main Process – Under src/main, this includes configuration files (config/), core modules (factory, manager, various API integrations like mihomoApi and subStoreApi), system-level functionality (src/main/sys), and resolution modules (autoUpdater, backup, tray management, etc.). It orchestrates the backend logic and interacts with the OS.
- Preload Scripts – Located in src/preload, these serve as a secure communication bridge (via IPC) between the main process and the renderer.
- Renderer Process – Under src/renderer, you have multiple layers: the HTML files, the React application (App.tsx, FloatingApp.tsx), routing, components (UI elements ranging from base components to settings and modals), hooks, assets, and utility modules. This layer handles all the UI interactions and presentation.
- Build & Packaging Components – The build directory, electron-builder.yml, and the aur directory (with multiple AUR package configurations) indicate that software packaging/distribution is an essential part of the overall architecture.
- External and Shared Services – Integration points to external APIs (e.g., Mihomo API, SubStore), backup/restore facilities (WebDAV integration), possibly Telegram for updater notifications (visible in scripts/telegram.mjs), and utility modules for configuration and IPC. Shared modules in src/shared support cross-cutting concerns like internationalization and type definitions.

##### Relationships and Data Flow
- The Electron main process is the core controller that initializes configurations, manages the backend logic, and communicates with external APIs.
- Preload scripts expose selected functionalities safely to the Renderer, allowing UI components to send/receive commands via IPC to the main process.
- The Renderer (React app) takes user actions, presents the UI, and uses hooks and components to interact with the underlying services of the main process.
- External services (like Mihomo APIs and WebDAV) are accessed as needed by either the main process or specialized modules to update configurations, perform backups, or deliver auto-update functionality.
- The packaging and build pipelines (configured in build files, GitHub workflows, and AUR package scripts) are connected to the main development cycle to produce distributable binaries for multiple platforms.

##### Architectural Patterns & Technologies
- Use of Electron’s dual-process model (Main vs. Renderer) is a core architectural principle.
- Modular design: Separation into config, core functionality, UI components, and utilities offers clear responsibilities.
- IPC communication pattern via preload scripts enforces security while bridging the processes.
- Adoption of React (with TypeScript) ensures clean UI composition and state management.
- Build tools and CI/CD (GitHub workflows, eslint, prettier) enforce code quality and automated packaging.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Electron Main Process"
        A1["Config"]
        A2["Core Modules"]
        A3["System-Level Functionality"]
        A4["Resolution Modules"]
        A5["Utilities"]
    end

    subgraph "Preload - Secure IPC"
        B1["Preload Scripts"]
    end

    subgraph "Renderer Process (React/TS UI)"
        C1["HTML Files"]
        C2["React Components & Application"]
        C3["Internationalization"]
    end

    subgraph "Build & Packaging"
        D1["Build Scripts & Configs"]
        D2["AUR Packaging"]
    end

    subgraph "External & Shared Services"
        E1["External Script Integrations"]
        E2["Shared Utilities & Types"]
    end

    C2 -->|"IPC-call"| B1
    C1 -->|"IPC-call"| B1
    B1 -->|"BridgeIPC"| A1
    B1 -->|"BridgeIPC"| A2
    B1 -->|"BridgeIPC"| A3
    B1 -->|"BridgeIPC"| A4
    B1 -->|"BridgeIPC"| A5
    A2 -->|"APIIntegration"| E1
    A4 -->|"ModuleInteraction"| E1
    A5 -->|"UtilizeShared"| E2
    D1 -->|"PackageBuild"| D2
    D1 -->|"BuildTrigger"| A1
    D1 -->|"BuildTrigger"| A2
    D1 -->|"BuildTrigger"| C2

    class A1,A2,A3,A4,A5 fill:#f2a65a,stroke:#333,stroke-width:2px;
    class B1 fill:#8ec3eb,stroke:#333,stroke-width:2px;
    class C1,C2,C3 fill:#a1d490,stroke:#333,stroke-width:2px;
    class D1,D2 fill:#d492a1,stroke:#333,stroke-width:2px;
    class E1,E2 fill:#e4e1b9,stroke:#333,stroke-width:2px;

    click A1 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/main/config"
    click A2 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/main/core"
    click A3 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/main/sys"
    click A4 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/main/resolve"
    click A5 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/main/utils"
    click B1 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/preload"
    click C1 "https://github.com/mihomo-party-org/mihomo-party/blob/master/src/renderer/index.html"
    click C2 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/renderer/src"
    click C3 "https://github.com/mihomo-party-org/mihomo-party/blob/master/src/renderer/src/i18n.ts"
    click D1 "https://github.com/mihomo-party-org/mihomo-party/tree/master/build"
    click D2 "https://github.com/mihomo-party-org/mihomo-party/tree/master/aur"
    click E1 "https://github.com/mihomo-party-org/mihomo-party/tree/master/scripts"
    click E2 "https://github.com/mihomo-party-org/mihomo-party/tree/master/src/shared"
```
