# ytssamuel/md_editor architecture

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

- Interactive diagram: https://gitdiagram.com/ytssamuel/md_editor
- Repository: https://github.com/ytssamuel/md_editor

## Overview

##### Project Type and Purpose
- This is a single‐page, front-end only Markdown editor (“md_editor”).
- It consists of static assets (HTML/CSS) and a set of JavaScript modules that handle file I/O, markdown parsing, UI updates, and modal dialogs.

##### High-Level Components
a. Presentation Layer
- index.html – the container for the editor and preview panes
- styles/*.css – styling rules (variables, layout, components, markdown theme)
b. Application Logic (JavaScript Modules)
- scripts/main.js – bootstrapper; wires together UI events and core modules
- scripts/uiManager.js – orchestrates DOM updates (editor ↔ preview pane)
- scripts/markdownRenderer.js – parses Markdown to HTML (via in-browser library)
- scripts/fileHandler.js – handles “Open File” (FileReader API) and “Save File” (Blob + download link)
- scripts/modalManager.js – manages modals/prompts (e.g., “Unsaved changes?”)

##### Relationships & Interactions
- User → Browser UI (index.html)
- Typing in the editor triggers uiManager events
- Click “Open”/“Save” buttons invoke fileHandler
- “Settings” or warnings invoke modalManager
- uiManager → markdownRenderer
- On editor input or “Render” action, uiManager passes raw markdown text to markdownRenderer
- markdownRenderer returns HTML, uiManager injects it into the preview pane
- uiManager & modalManager
- Before destructive actions, uiManager asks modalManager to display confirmation
- fileHandler ↔ Browser File API
- fileHandler uses FileReader to load .md files and Blob + anchor download to save

##### Architectural Patterns & Principles
- Modular separation: each JavaScript file is a focused component (single responsibility)
- Event-driven flow: user actions trigger events that bubble through main → uiManager → other modules
- Layered presentation: HTML/CSS layers separated from business logic (JS)

##### Technologies & Frameworks
- Vanilla JavaScript (ES modules or namespace objects)
- In-browser Markdown library (e.g., marked.js or markdown-it)
- HTML5 File API (FileReader, Blob)
- CSS for styling; no front-end framework (React/Angular) detected

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Presentation Layer"
        UI["index.html"]:::ui
        click UI "https://github.com/ytssamuel/md_editor/blob/main/index.html"
        CSS1["variables.css"]:::ui
        click CSS1 "https://github.com/ytssamuel/md_editor/blob/main/styles/variables.css"
        CSS2["base.css"]:::ui
        click CSS2 "https://github.com/ytssamuel/md_editor/blob/main/styles/base.css"
        CSS3["layout.css"]:::ui
        click CSS3 "https://github.com/ytssamuel/md_editor/blob/main/styles/layout.css"
        CSS4["components.css"]:::ui
        click CSS4 "https://github.com/ytssamuel/md_editor/blob/main/styles/components.css"
        CSS5["main.css"]:::ui
        click CSS5 "https://github.com/ytssamuel/md_editor/blob/main/styles/main.css"
        CSS6["markdown.css"]:::ui
        click CSS6 "https://github.com/ytssamuel/md_editor/blob/main/styles/markdown.css"
    end

    subgraph "Application Logic"
        Main["main.js"]:::logic
        click Main "https://github.com/ytssamuel/md_editor/blob/main/scripts/main.js"
        UIM["uiManager.js"]:::logic
        click UIM "https://github.com/ytssamuel/md_editor/blob/main/scripts/uiManager.js"
        MR["markdownRenderer.js"]:::logic
        click MR "https://github.com/ytssamuel/md_editor/blob/main/scripts/markdownRenderer.js"
        FH["fileHandler.js"]:::logic
        click FH "https://github.com/ytssamuel/md_editor/blob/main/scripts/fileHandler.js"
        MM["modalManager.js"]:::logic
        click MM "https://github.com/ytssamuel/md_editor/blob/main/scripts/modalManager.js"
    end

    subgraph "External APIs"
        API["Browser File API\n(FileReader, Blob)"]:::external
    end

    User["User"]:::external
    User -->|"editorInput"| UI
    UI -->|"load & wire events"| Main
    Main -->|"init UI events"| UIM
    UIM -->|"onInput: rawMarkdown"| MR
    MR -->|"HTML output"| UIM
    UIM -->|"update preview"| UI
    UI -->|"click Open/Save"| FH
    FH -->|"read/write"| API
    API -->|"file data/download"| FH
    FH -->|"file content"| UIM
    UIM -->|"unsaved? confirm"| MM
    MM -->|"response"| UIM

    classDef ui fill:#D6EAF8,stroke:#2471A3,stroke-width:1px;
    classDef logic fill:#ABEBC6,stroke:#239B56,stroke-width:1px;
    classDef external fill:#F9E79F,stroke:#B7950B,stroke-width:1px;
```
