# purocean/yn architecture

> Architecture diagram of the GitHub repository purocean/yn, 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/purocean/yn
- Repository: https://github.com/purocean/yn

## Overview

##### Main Components
- Main Process (Backend):
– Located in the src/main directory.
– Responsible for core functions such as application startup, window management, app menus, protocol handling, security (encryption for files), and various utilities.
– Contains modules for configuration (config.ts, constant.ts, envs.ts), inter-process communication (jsonrpc.ts), and integration with external services (e.g., file server, pandoc conversion, PlantUML conversion, etc., found under src/main/server).
– Handles extension management (extension.ts) with mechanisms for plug-in support.

- Renderer Process (Frontend):
– Located in the src/renderer directory.
– The UI is built using Vue components (Files with .vue) and managed by Vite (vite.config.mts and vite-env.d.ts), integrating the Monaco editor for Markdown editing.
– Organized into components (e.g., Editor.vue, Previewer.vue, Toolbar/ActionBar.vue), services (for document, export, markdown, repository, etc.), and utilities.
– Contains tests and plugin-related modules (under src/renderer/plugins) that extend functionality via custom and built-in plug-ins.
– Implements rich user interactions such as synchronized scrolling, embedded media support, live preview, and integrated terminal.

- External Tools & Services:
– Integration with pandoc for multi-format export.
– OpenAI integration for auto-completion and a plug-in system for further extensibility.
– File-based storage (local Markdown files are used to persist document data).

##### Relationships and Interactions
- The Main and Renderer Processes communicate via Electron’s IPC channels (likely using jsonrpc implementations as seen in src/main/jsonrpc.ts and related modules).
- The Main Process initiates app-level services (e.g., auto-updater, window management, command execution) and forwards events/commands to the Renderer Process.
- Renderer components (Vue components) react to user actions and invoke services (located in src/renderer/services) which may then reach back to the Main Process.
- Plug-in architecture: Custom plug-ins are loaded from the plugin directories. They interact with core parts of the editor (both in the Renderer and possibly via main processes) to extend functionality.
- External converters and integrations (pandoc, PlantUML scripts in build and scripts directories) operate as standalone utilities that are invoked by the system as needed.

##### Architectural Patterns and Design Principles
- Separation of Concerns: Clear separation is maintained between the Electron main process (application lifecycle and OS interactions) and the renderer process (UI and interactive components).
- Modularity and Extensibility: The plug-in system is designed so that extended functionality is nearly “plug-and-play.” This is visible from the dedicated plugins directory and the core extensibility files in both main and renderer areas.
- Component-based UI: Vue components in the renderer process, coupled with a set of services and contexts (like i18n and theming), employ a component-based design.
- Use of IPC for decoupling: Communication between critical modules uses “jsonrpc,” ensuring services remain decoupled and maintainable.
- Integrations with external services: Reliance on external converters and tools (e.g., pandoc, PlantUML) is explicitly part of the architecture.

##### Relevant Technologies and Frameworks
- Electron – for creating cross-platform desktop applications.
- Vue.js – for rendering the user interface.
- Vite – for module bundling and development environment.
- Monaco Editor – providing a coding experience resembling VSCode.
- Pandoc, PlantUML, Drawio, among others – for document conversion and embedded multimedia support.
- Node.js – underpins the entire development stack, with various scripts for asset management and testing (jest.config.js, ESLint config files).

- Within “Main Process”, include sub-components such as:
- App Startup (app.ts, startup.ts)
- IPC & Configuration (jsonrpc.ts, config.ts)
- Server Modules (found in src/main/server)
- Extension & Plugin Bootstrappers (extension.ts)
- Within “Renderer Process”, include groups for:
- UI Components (from src/renderer/components)
- Service Layers (document, editor, theme, etc.)
- Plugin Management (from src/renderer/plugins)
- Testing and Utilities (tests, support, utils)
- Critical data storage (local Markdown files, encryption workflows) that is central to the application’s functioning.

## Diagram (Mermaid)

```mermaid
graph TD
    A["Yank Note Application"]:::appStyle

    subgraph "Main Process"
        MP["Main Process (Backend)"]:::main
        AppStartup["App Startup"]:::main
        MPConfig["Configuration Modules"]:::main
        MPIPC["IPC & JSONRPC"]:::main
        MPServer["Server Modules"]:::main
        MPExt["Extension Management"]:::main
    end

    subgraph "Renderer Process"
        RP["Renderer Process (Frontend)"]:::frontend
        RPComponents["UI Components"]:::frontend
        RPServices["Service Layers"]:::frontend
        RPPlugins["Plugin Framework"]:::frontend
        ViteConfig["Vite Configuration"]:::frontend
    end

    subgraph "External Tools & Services"
        Pandoc["Pandoc Integration"]:::external
        PlantUML["PlantUML Integration"]:::external
    end

    A --> MP
    A --> RP
    A --> Pandoc
    A --> PlantUML

    MP --> AppStartup
    MP --> MPConfig
    MP --> MPIPC
    MP --> MPServer
    MP --> MPExt

    RP --> RPComponents
    RP --> RPServices
    RP --> RPPlugins
    RP --> ViteConfig

    MPIPC -->|"IPC"| RPServices
    MPServer -->|"calls"| Pandoc
    MPServer -->|"calls"| PlantUML
    RPComponents -->|"triggers"| RPServices
    RPPlugins -->|"extends"| RPServices

    %% Click Events
    click MP "https://github.com/purocean/yn/tree/develop/src/main"
    click MPConfig "https://github.com/purocean/yn/blob/develop/src/main/config.ts"
    click MPIPC "https://github.com/purocean/yn/blob/develop/src/main/jsonrpc.ts"
    click MPServer "https://github.com/purocean/yn/tree/develop/src/main/server"
    click MPExt "https://github.com/purocean/yn/blob/develop/src/main/extension.ts"
    
    click RP "https://github.com/purocean/yn/tree/develop/src/renderer"
    click RPComponents "https://github.com/purocean/yn/tree/develop/src/renderer/components"
    click ViteConfig "https://github.com/purocean/yn/blob/develop/vite.config.mts"
    click RPPlugins "https://github.com/purocean/yn/tree/develop/src/renderer/plugins"
    click RPServices "https://github.com/purocean/yn/tree/develop/src/renderer/services"
    
    click Pandoc "https://github.com/purocean/yn/blob/develop/scripts/download-pandoc.js"
    click PlantUML "https://github.com/purocean/yn/blob/develop/src/main/server/plantuml.ts"

    %% Styles
    classDef appStyle fill:#f9c,stroke:#333,stroke-width:4px;
    classDef main fill:#bbf,stroke:#333,stroke-width:2px;
    classDef frontend fill:#bfb,stroke:#333,stroke-width:2px;
    classDef external fill:#ff9,stroke:#333,stroke-width:2px;
```
