# fearlessgeekmedia/geekdown architecture

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

- Interactive diagram: https://gitdiagram.com/fearlessgeekmedia/geekdown
- Repository: https://github.com/fearlessgeekmedia/geekdown

## Overview

##### Project Type and Purpose
- GeekDown is a desktop Markdown editor built with Electron.
- It uses Milkdown (with Crepe), W3.css for styling, and Electron as the host environment.
- The goal is a cross-platform (Linux, macOS, Windows) Markdown editor with live preview and basic file operations.

##### Main Architectural Components
a. Electron Main Process
- Entry point: `main.js`
- Responsibilities: application lifecycle, window creation, IPC listeners for file operations.
b. Preload Script
- File: `preload.js`
- Purpose: expose a secure, limited API (via `contextBridge`) to the renderer for file I/O and OS interactions.
c. Renderer Process (UI Layer)
- HTML/CSS: `index.html`, `w3.css`
- JavaScript modules handling UI actions and Markdown rendering:
- `index.ts` (primary renderer bootstrap)
- Feature scripts: `newfile.js`, `openfile.js`, `savefile.js`, `closefile.js`, `exportfile.js`, `image-upload.js`, `fontsettings.js`, `hotkeys.js`, `togglemode.js`
- Markdown engine: Milkdown + Crepe plugin + upload plugin
d. Build & Dev Tooling
- Vite for bundling/rendering in dev mode (`vite.config.js`)
- NPM scripts and dependencies defined in `package.json` (electron:dev, electron:build)
- Electron Builder for packaging (output in `electron-dist`)

##### Relationships and Data Flows
- Renderer → Preload: invokes exposed APIs (e.g., openFile, saveFile)
- Preload → Main: relays IPC calls to perform file system operations
- Main → Renderer: sends back file contents or error messages
- Renderer UI: user enters Markdown → Milkdown parser/render engine produces HTML → displayed in preview pane
- Build pipeline: Vite serves hot-reload content to renderer in dev mode; on build, Electron Builder packages the app

##### Architectural Patterns & Design Principles
- Separation of concerns:
- Main process handles OS-level tasks (file system, window management)
- Renderer strictly handles presentation and user interactions
- Preload layer as a secure boundary
- Modular UI: each feature (new/open/save/export/toggle) lives in its own JS file
- Plugin-based Markdown engine: Milkdown core + Crepe plugin + upload plugin

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build & Dev Tools
    subgraph "Build & Dev Tools"
        direction TB
        Vite["Vite (Dev Server)"]:::dev
        PackageJSON["package.json / package-lock.json"]:::dev
        Builder["Electron Builder"]:::dev
    end

    %% Electron Core
    subgraph "Electron Core"
        direction TB
        Main["main.js\n(Electron Main Process)"]:::core
        Preload["preload.js\n(Preload Script)"]:::core
    end

    %% Renderer Process
    subgraph "Renderer Process (Chromium)"
        direction TB

        subgraph "UI Layer"
            direction TB
            HTML["index.html"]:::ui
            CSS["w3.css"]:::ui
            IndexTS["index.ts\n(Renderer Bootstrap)"]:::ui
        end

        subgraph "Renderer Feature Modules"
            direction TB
            NewFile["newfile.js"]:::ui
            OpenFile["openfile.js"]:::ui
            SaveFile["savefile.js"]:::ui
            CloseFile["closefile.js"]:::ui
            ExportFile["exportfile.js"]:::ui
            ImageUpload["image-upload.js"]:::ui
            FontSettings["fontsettings.js"]:::ui
            Hotkeys["hotkeys.js"]:::ui
            ToggleMode["togglemode.js"]:::ui
        end

        subgraph "Markdown Engine"
            direction TB
            MDCore["Milkdown + Crepe + upload plugin"]:::ui
        end
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        FileSystem["File System"]:::fs
        OS["OS Window Manager"]:::fs
    end

    %% Connections
    PackageJSON -->|defines scripts & deps| Vite
    PackageJSON -->|defines build config| Builder
    Vite -->|serves content| HTML
    Vite --> IndexTS

    Main -->|creates window| OS
    Main -->|responds via IPC| IndexTS
    IndexTS -->|"open-file, save-file"| Preload
    Preload -->|"ipcMain calls"| Main
    Main -->|"fs operations"| FileSystem
    Main -->|"send-content / errors"| Preload
    Preload --> IndexTS

    HTML -->|loads| IndexTS
    IndexTS --> NewFile
    IndexTS --> OpenFile
    IndexTS --> SaveFile
    IndexTS --> CloseFile
    IndexTS --> ExportFile
    IndexTS --> ImageUpload
    IndexTS --> FontSettings
    IndexTS --> Hotkeys
    IndexTS --> ToggleMode

    IndexTS --> MDCore
    MDCore --> IndexTS

    %% Click Events
    click Main "https://github.com/fearlessgeekmedia/geekdown/blob/main/main.js"
    click Preload "https://github.com/fearlessgeekmedia/geekdown/blob/main/preload.js"
    click HTML "https://github.com/fearlessgeekmedia/geekdown/blob/main/index.html"
    click CSS "https://github.com/fearlessgeekmedia/geekdown/blob/main/w3.css"
    click IndexTS "https://github.com/fearlessgeekmedia/geekdown/blob/main/index.ts"
    click NewFile "https://github.com/fearlessgeekmedia/geekdown/blob/main/newfile.js"
    click OpenFile "https://github.com/fearlessgeekmedia/geekdown/blob/main/openfile.js"
    click SaveFile "https://github.com/fearlessgeekmedia/geekdown/blob/main/savefile.js"
    click CloseFile "https://github.com/fearlessgeekmedia/geekdown/blob/main/closefile.js"
    click ExportFile "https://github.com/fearlessgeekmedia/geekdown/blob/main/exportfile.js"
    click ImageUpload "https://github.com/fearlessgeekmedia/geekdown/blob/main/image-upload.js"
    click FontSettings "https://github.com/fearlessgeekmedia/geekdown/blob/main/fontsettings.js"
    click Hotkeys "https://github.com/fearlessgeekmedia/geekdown/blob/main/hotkeys.js"
    click ToggleMode "https://github.com/fearlessgeekmedia/geekdown/blob/main/togglemode.js"
    click Vite "https://github.com/fearlessgeekmedia/geekdown/blob/main/vite.config.js"
    click PackageJSON "https://github.com/fearlessgeekmedia/geekdown/blob/main/package.json"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000
    classDef dev fill:#FFA500,stroke:#000
    classDef ui fill:#90EE90,stroke:#000
    classDef fs fill:#D3D3D3,stroke:#000
```
