# 1zilc/fishing-funds architecture

> Architecture diagram of the GitHub repository 1zilc/fishing-funds, 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/1zilc/fishing-funds
- Repository: https://github.com/1zilc/fishing-funds

## Overview

##### Main Components
- Electron Main Process – Found in the “src/main” folder. This contains the core backend logic responsible for creating application windows, initializing auto-updating (autoUpdater.ts), managing the system tray/menubar (menubar.ts, tray.ts), handling system menus (contextMenu.ts), and managing application proxies and child windows.
- Renderer Process – Located in “src/renderer”. This holds all the frontend UI logic built primarily with React (e.g., index.tsx, app.tsx), styling (SCSS modules), and a wide variety of modular UI components (for fund views, charts, stock details, news lists, etc.).
- Preload Scripts – In “src/preload”. They bridge the main and renderer processes providing secure APIs.
- Workers and Utility Services – “src/renderer/workers” (for offloading heavy tasks) and “src/renderer/utils” for additional helpers like HTTP requests, coding, and system hooks.
- State Management – In “src/renderer/store” which employs a Redux-like pattern (multiple “features” folders, “listeners”, etc.) to handle application state and configurations.
- External Data Services – Though not defined as separate microservices, there is a well-organized “src/renderer/services” layer for fetching and processing data from different sources such as “东财”, “蚂蚁基金”, “同花顺” and other APIs.

##### Component Relationships and Data Flow
- The Electron Main Process initializes the application window(s), loads the preload scripts, and sets up inter-process communication (IPC) channels. It then communicates with the Renderer Process to deliver configuration settings, auto-update notifications, system tray interactions, and proxy settings.
- The Renderer Process (React application) is divided into many functional components and pages. The components (organized within “src/renderer/components”) interact with the state store (“src/renderer/store”) and call service modules (“src/renderer/services”) to fetch data from external APIs.
- Worker threads (“src/renderer/workers”) can be diagrammed as background tasks that help process data (e.g., search or coding-related tasks) independently from the main UI thread.
- The state management interacts with the UI components via listeners to react to changes (cache, sync, configuration updates).

##### Architectural Patterns & Design Principles
- Separation of Concerns: The main vs. renderer process clearly divides OS-level/system responsibilities from the presentation logic.
- Modular Structure: The project uses modular components, helpers, and services that can be independently managed and tested.
- Event-driven Communication: IPC between main and renderer processes and state listeners (cache.listener.ts, share.listener.ts, etc.) drive data flows.
- Use of a Worker pattern for offloading heavy operations, improving performance on the UI thread.
- The usage of electron-vite indicates a modern development workflow emphasizing fast rebuilds, hot module replacement, and a streamlined bundling process.

##### Relevant Technologies and Frameworks
- Electron – Core desktop application framework.
- React – The frontend framework for building the UI components.
- Vite (via electron-vite) – For bundling and running the development environment.
- SCSS modules – Styled components for UI theming.
- Redux-like state management – For handling app state.
- Node.js – As the runtime for the main process.

##### Putting It All Together
- Break the Renderer Process into submodules: UI Components, State Management, Data Services, and Utility/Worker modules.
- A section for external factors – third-party data sources, and how system proxy settings allow connections to these.
- Finally, place configuration and build processes (e.g., electron-vite, CI/CD workflows) on the periphery to emphasize deployment and development aspects.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Core Processes
    subgraph "Core Processes"
        E_Main["Electron Main Process"]:::main
        Preload["Preload Scripts"]:::preload
    end

    %% Frontend Layer
    subgraph "Frontend Layer"
        Renderer["Renderer Process (React UI)"]:::renderer
        subgraph "Renderer Components"
            UI["React UI Components"]:::ui
            State["State Management/Store"]:::state
            Workers["Worker Threads"]:::worker
            Utilities["Utility Services"]:::utility
            Services["External Data Services"]:::service
        end
    end

    %% Build and Deployment
    subgraph "Build & Deployment"
        BuildConfig["Build Config (electron.vite.config.ts, package.json)"]:::build
        CI["CI/CD Workflows (.github/workflows)"]:::build
        Assets["Assets & Release (assets, release)"]:::build
    end

    %% Connections between Core Processes
    E_Main -->|"loads"| Preload
    Preload -->|"bridges"| Renderer
    E_Main <-->|"IPC"| Renderer

    %% Connections in Frontend Layer
    Renderer -->|"updates"| State
    Renderer -->|"fetches"| Services
    Workers -->|"processesHeavyTasks"| Renderer
    Workers -->|"notifies"| State
    Utilities -->|"assists"| Renderer
    Utilities -->|"supports"| State
    State -->|"triggers"| UI
    Services -->|"supplies"| UI

    %% Click Events
    click E_Main "https://github.com/1zilc/fishing-funds/tree/main/src/main"
    click Preload "https://github.com/1zilc/fishing-funds/blob/main/src/preload/index.ts"
    click Renderer "https://github.com/1zilc/fishing-funds/tree/main/src/renderer"
    click State "https://github.com/1zilc/fishing-funds/tree/main/src/renderer/store"
    click Workers "https://github.com/1zilc/fishing-funds/tree/main/src/renderer/workers"
    click Utilities "https://github.com/1zilc/fishing-funds/tree/main/src/renderer/utils"
    click Services "https://github.com/1zilc/fishing-funds/tree/main/src/renderer/services"
    click BuildConfig "https://github.com/1zilc/fishing-funds/blob/main/electron.vite.config.ts"
    click CI "https://github.com/1zilc/fishing-funds/tree/main/.github/workflows"
    click Assets "https://github.com/1zilc/fishing-funds/tree/main/assets"

    %% Styles
    classDef main fill:#ffcccc,stroke:#cc0000,stroke-width:2px,color:#000;
    classDef preload fill:#ffe6cc,stroke:#cc6600,stroke-width:2px,color:#000;
    classDef renderer fill:#ccffcc,stroke:#009900,stroke-width:2px,color:#000;
    classDef ui fill:#e6f7ff,stroke:#007acc,stroke-width:2px,color:#000;
    classDef state fill:#f0e68c,stroke:#c0ab00,stroke-width:2px,color:#000;
    classDef worker fill:#d1c4e9,stroke:#673ab7,stroke-width:2px,color:#000;
    classDef utility fill:#d1c4e9,stroke:#512da8,stroke-width:2px,color:#000;
    classDef service fill:#fff0f5,stroke:#d63384,stroke-width:2px,color:#000;
    classDef build fill:#f8d7da,stroke:#a71d2a,stroke-width:2px,color:#000;
```
