# mohamedrejeb/compose-rich-editor architecture

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

- Interactive diagram: https://gitdiagram.com/mohamedrejeb/compose-rich-editor
- Repository: https://github.com/mohamedrejeb/compose-rich-editor

## Overview

##### Data flow and interactions
- User Input & State Management:
- That the user interacts with the RichTextEditor composable which in turn uses RichTextState for managing and updating text content.
- Styling and Formatting:
- Parsing Integration:
- Parsing modules (for HTML and Markdown) that receive data (such as imported HTML/Markdown content) and update the RichTextState, and vice versa (output operations like toHtml() and toMarkdown()).
- Platform Abstraction:
- External Dependencies:
- External services like Coil3 as an optional integration that the “richeditor-compose-coil3” module connects to (for image loading support).

##### Architectural patterns and design principles
- Multiplatform Architecture – Clearly separate the shared “commonMain” code (business logic, UI definitions, parsing utilities) from the “actual” platform-specific implementations.
- Composable Architecture – The system leverages composable functions (rich editor UI composition) to keep the UI flexible and declarative.
- Separation of Concerns – The library defines distinct layers: UI layer (composables), state management (RichTextState), parsing layer (HTML/Markdown converters), and platform abstraction layer.

##### Important Notes
- Be very detailed: capture every essential module and show relationships such as dependency and data flow.
- Don’t overcomplicate by creating too many small components – aim for a balance by splitting into major functional areas (i.e., Core, Platform, External, Sample Clients).
- How the “RichTextState” connects with both styling functions (e.g., toggleSpanStyle, toggleParagraphStyle) and parse methods (setHtml, toHtml, setMarkdown, toMarkdown).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Library (RichEditor-Compose)
    subgraph "Core Library (RichEditor-Compose)"
        RT("RichTextState"):::core
        UI("UI Composables"):::core
        PAR("Parsing Modules (HTML/Markdown)"):::core
        UTIL("Utility Functions"):::core
    end

    %% Platform Specific Implementations
    subgraph "Platform Specific Implementations"
        ANDR("Android Bridge"):::platform
        DESK("Desktop Bridge"):::platform
        IOS("iOS Bridge"):::platform
        JS("JavaScript Bridge"):::platform
        WASM("WasmJs Bridge"):::platform
    end

    %% Optional Integration
    subgraph "Optional Integration"
        COIL("Coil3 Integration Module"):::integration
    end

    %% Sample Applications
    subgraph "Sample Applications"
        SAP("Android Sample App"):::sample
        SCP("Common Sample App"):::sample
        SDAP("Desktop Sample App"):::sample
        SIAP("iOS Sample App"):::sample
        SWAP("Web Sample App"):::sample
    end

    %% Data Flow Connections
    UI -->|"updates"| RT
    UI -->|"triggersStyling"| UTIL
    RT -->|"parsesContent"| PAR
    RT -->|"delegatesTo"| ANDR
    RT -->|"delegatesTo"| DESK
    RT -->|"delegatesTo"| IOS
    RT -->|"delegatesTo"| JS
    RT -->|"delegatesTo"| WASM
    COIL -->|"integratesWith"| UI

    SAP -->|"usesAPI"| RT
    SCP -->|"usesAPI"| RT
    SDAP -->|"usesAPI"| RT
    SIAP -->|"usesAPI"| RT
    SWAP -->|"usesAPI"| RT

    %% Click Events for Core Library
    click RT "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt"
    click UI "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui"
    click PAR "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser"
    click UTIL "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/utils"

    %% Click Events for Platform-Specific Implementations
    click ANDR "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose/src/androidMain/kotlin/com/mohamedrejeb/richeditor/platform/Platform.android.kt"
    click DESK "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose/src/desktopMain/kotlin/com/mohamedrejeb/richeditor/platform/Platform.desktop.kt"
    click IOS "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose/src/iosMain/kotlin/com/mohamedrejeb/richeditor/platform/Platform.ios.kt"
    click JS "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose/src/jsMain/kotlin/com/mohamedrejeb/richeditor/platform/Platform.js.kt"
    click WASM "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose/src/wasmJsMain/kotlin/com/mohamedrejeb/richeditor/platform/Platform.wasmJs.kt"

    %% Click Event for Optional Integration
    click COIL "https://github.com/mohamedrejeb/compose-rich-editor/blob/main/richeditor-compose-coil3/src/commonMain/kotlin/com/mohamedrejeb/richeditor/coil3/Coil3ImageLoader.kt"

    %% Click Events for Sample Applications
    click SAP "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/sample/android"
    click SCP "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/sample/common"
    click SDAP "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/sample/desktop"
    click SIAP "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/sample/ios"
    click SWAP "https://github.com/mohamedrejeb/compose-rich-editor/tree/main/sample/web"

    %% Styles
    classDef core fill:#AED6F1,stroke:#3498DB,stroke-width:2px;
    classDef platform fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
    classDef integration fill:#C39BD3,stroke:#8E44AD,stroke-width:2px;
    classDef sample fill:#A9DFBF,stroke:#27AE60,stroke-width:2px;
```
