# mikepenz/multiplatform-markdown-renderer architecture

> Architecture diagram of the GitHub repository mikepenz/multiplatform-markdown-renderer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mikepenz/multiplatform-markdown-renderer
- Repository: https://github.com/mikepenz/multiplatform-markdown-renderer

## Overview

##### Main Components
- Core Library Module:
– The central “multiplatform-markdown-renderer” provides common markdown processing (parsing using JetBrains’ library) and rendering logic using Compose.
– It exposes the main Markdown composable API and supports various customizations (styles, animations, extended spans, etc.).
- Feature/Extension Modules:
– Modules for theming (m2 and m3): Provide Material 2 and Material 3 defaults.
– Image Transformer Modules (coil2 and coil3): Offer image-loading strategies using different versions of Coil.
– Code Syntax Highlighting Module (code): Integrates with an external highlighter (Highlights) for rendering code blocks.
- API Modules:
– Each module includes separate API definitions (e.g., the “api” subdirectories for android, jvm, and klib) to specify interfaces and expected behaviors.
- Platform-Specific Implementation Modules:
– Each multiplatform module contains directories for platform-specific code (androidMain, jvmMain, iosMain, etc.) to handle platform-specific rendering concerns.
- Sample Applications:
– The “sample” folder shows real-life integration for Android, Desktop, iOS, Web, and shared modules to demonstrate how to consume the library.

##### Detail the Relationships and Interactions
- The Core Module interacts directly with all other modules:
– Common business logic and markdown parsing/rendering lies at the center.
– Feature modules (m2/m3, coil2/coil3, code) extend or specialize that core via additional rendering components (like custom Markdown components).
- Platform-Specific API Implementations:
– Each platform-specific directory (androidMain, jvmMain, iosMain, etc.) implements the necessary glue-code that adapts the common logic to that platform.
- Dependency Injection & Customizability:
- Gradle and CI Integration:
– The project uses Gradle (with build.gradle.kts scripts, gradle.properties, and the Gradle wrapper) to build, package, and manage dependencies.
– CI workflows (under .github/workflows) ensure continuous integration and testing.

##### Architectural Patterns and Design Principles
- Modularity:
– The project is split into separate modules for core functionality, feature-specific enhancements, and platform adaptations.
- Separation of Concerns:
– The rendering logic (Markdown composable), API definitions, and platform-specific implementations are organized in distinct directories.
- Extensibility by Design:
– By allowing custom components, annotators, and configurable image transformers and code highlighters, the system adheres to the Open/Closed Principle.
- Gradle/Multi-platform Build Pattern:
– Leveraging Kotlin multiplatform’s source set segregation (commonMain and platform-specific directories), the project cleanly isolates shared logic from platform-specific concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Extension Modules"
        m2["Material2 Theming"]:::extension
        m3["Material3 Theming"]:::extension
        coil2["Image Transformer - Coil2"]:::extension
        coil3["Image Transformer - Coil3"]:::extension
        code["Code Syntax Highlighting"]:::extension
    end

    Core["Multiplatform Markdown Renderer Core\n(markdown parsing, composable rendering,\ncustom theming, extended spans, animations)"]:::core

    subgraph "Platform Specific APIs"
        android["Android API"]:::platform
        jvm["JVM API"]:::platform
        ios["iOS API"]:::platform
        web["Web API"]:::platform
        desktop["Desktop API"]:::platform
    end

    subgraph "Sample Applications"
        sample_android["Android Sample"]:::sample
        sample_desktop["Desktop Sample"]:::sample
        sample_ios["iOS Sample"]:::sample
        sample_web["Web Sample"]:::sample
        sample_shared["Shared Sample"]:::sample
    end

    external["External: JetBrains Markdown Processor"]:::external
    build["CI/CD & Build Infrastructure"]:::build

    %% Extension Modules extending Core
    m2 -->|"extends"| Core
    m3 -->|"extends"| Core
    coil2 -->|"extends"| Core
    coil3 -->|"extends"| Core
    code -->|"extends"| Core

    %% Core implementing platform-specific APIs
    Core -->|"implements"| android
    Core -->|"implements"| jvm
    Core -->|"implements"| ios
    Core -->|"implements"| web
    Core -->|"implements"| desktop

    %% Sample Applications consuming platform APIs and Core
    sample_android -->|"consumes"| android
    sample_desktop -->|"consumes"| desktop
    sample_ios -->|"consumes"| ios
    sample_web -->|"consumes"| web
    sample_shared -->|"consumes"| Core

    %% Core dependency on External Library
    Core -->|"depends_on"| external

    %% Build & CI builds the Core module (and project)
    build -->|"builds"| Core

    %% Click Events
    click Core "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer"
    click m2 "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer-m2"
    click m3 "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer-m3"
    click coil2 "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer-coil2"
    click coil3 "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer-coil3"
    click code "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer-code"
    click android "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer/src (api/android)"
    click jvm "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/multiplatform-markdown-renderer/src (api/jvm)"
    click sample_android "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/sample/android"
    click sample_desktop "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/sample/desktop"
    click sample_ios "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/sample/ios"
    click sample_web "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/sample/web"
    click sample_shared "https://github.com/mikepenz/multiplatform-markdown-renderer/tree/develop/sample/shared"
    click build "https://github.com/mikepenz/multiplatform-markdown-renderer/blob/develop/build.gradle.kts"

    %% Styles
    classDef core fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef extension fill:#A9DFBF,stroke:#145A32,stroke-width:2px;
    classDef platform fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef sample fill:#D6EAF8,stroke:#1F618D,stroke-width:2px;
    classDef build fill:#F5CBA7,stroke:#9A7D0A,stroke-width:2px;
    classDef external fill:#E8DAEF,stroke:#6C3483,stroke-width:2px;
```
