# yonatanmgr/mathberet architecture

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

- Interactive diagram: https://gitdiagram.com/yonatanmgr/mathberet
- Repository: https://github.com/yonatanmgr/mathberet

## Overview

##### Main Components
- Electron Main Process: Represented in the “src/main” directory, including files like app.ts, appWindow.ts, and Onboarding.js. This component handles the lifecycle of the application, window management, and communicates with the renderer via IPC.
- Renderer Process: Found in “src/renderer” – the heart of the user interface built with React. Include UI components such as CommandBar, FilesSidebar, Header, MathSidebar, Page components, and various modals. This layer renders the dynamic notebook interface.
- Common Utilities: In “src/common”, these helper modules (keybindings, i18n, shortcuts) are shared across the main and renderer processes.
- Miscellaneous/Window Components: Under “misc/window”, components specifically focus on customizing the window appearance (title bar, window controls) and window-related IPC interactions, further refining the Electron window management.
- Build & Configuration Tools: The “tools” directory holds webpack and electron-forge configurations, and files like package.json, tsconfig.json, and various config files at the project root provide build/test/deployment settings.

##### Relationships and Interactions
- The Main Process should be drawn on one side to show its role in creating and managing application windows. It communicates with the Renderer Process via Electron’s IPC (as apparent from files like titlebarIPC.ts and appPreload.tsx).
- The Renderer Process, built with React, is responsible for displaying the block-based editor interface, handling drag-and-drop, and integrating with various plugins (like MathLive, Mafs, tldraw, and react-grid-layout).
- The Common Utilities are used by both these processes to maintain consistency in internationalization (i18next), shortcuts, and keybindings.
- The Build & Configuration Tools indicate external tooling that compiles, bundles, and packages the application (using webpack, Electron Forge, etc.)

##### Architectural Patterns and Key Technologies
- Component-based UI design: Evident from the richly organized “src/renderer/components” folder. Emphasize how loosely-coupled components (like the CommandBar, FilesSidebar, and Page blocks) interact.
- Separation between Main and Renderer processes: A classic Electron pattern with a clear boundary managed by IPC.
- Build and Deployment Pipeline: Configuration files in “tools/webpack” and “tools/forge” show how the app’s code is bundled and packaged for distribution.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Electron Main Process"
        EM["Electron Main Process (app.ts, appWindow.ts, Onboarding.js)"]:::main
    end

    subgraph "Renderer Process (React UI)"
        R["Renderer Process (appRenderer.tsx, appPreload.tsx, components: CommandBar, FilesSidebar, Header, MathSidebar, Page, etc.)"]:::renderer
    end

    subgraph "Common Utilities"
        CU["Common Utilities (helpers, i18n, keybindings, shortcuts, locals)"]:::common
    end

    subgraph "Window Components"
        W["Window Components (windowPreload.ts, titlebarIPC.ts, ControlButton, Titlebar, WindowControls, WindowFrame)"]:::window
    end

    subgraph "Build & Configuration Tools"
        B["Build & Config (webpack, forge, package.json, tsconfig.json, etc.)"]:::build
    end

    EM -->|"IPC"| R
    CU -->|"provides"| EM
    CU -->|"provides"| R
    EM -->|"manages"| W
    B -->|"builds"| EM
    B -->|"builds"| R

    click EM "https://github.com/yonatanmgr/mathberet/tree/master/src/main"
    click R "https://github.com/yonatanmgr/mathberet/tree/master/src/renderer"
    click CU "https://github.com/yonatanmgr/mathberet/tree/master/src/common"
    click W "https://github.com/yonatanmgr/mathberet/tree/master/misc/window"
    click B "https://github.com/yonatanmgr/mathberet/tree/master/tools"

    classDef main fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef renderer fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef common fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef window fill:#FFA500,stroke:#000,stroke-width:2px;
    classDef build fill:#9370DB,stroke:#000,stroke-width:2px;
```
