# 10play/10tap-editor architecture

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

- Interactive diagram: https://gitdiagram.com/10play/10tap-editor
- Repository: https://github.com/10play/10tap-editor

## Overview

##### Project Type and Purpose
- This is an open-source React Native library (“@10play/tentap-editor”) that wraps a rich-text editor powered by Tiptap/ProseMirror and exposes native toolbar/keyboard support on Android and iOS.
- It includes:
- Native code (Android + iOS) for view managers and custom keyboards.
- JavaScript/TypeScript wrapper exposing a RichText component, Toolbar, hooks, and bridges for editor state.
- Example/demo apps demonstrating usage.
- A Docusaurus-based website hosting docs and examples.
- Build tooling (babel, TypeScript, yarn workspaces, GitHub Actions).

##### File Structure
- Top-level folders:
- android/ & ios/ → Native modules (view managers, packages).
- src/ → Core JS/TS library (RichText, Toolbar, bridges, hooks, utilities).
- example/ & example76/ → Demo React Native apps (Android + iOS projects) consuming the package.
- website/ → Documentation site (Docusaurus).
- scripts/ → Build-time helper (e.g., buildEditor.js).
- Configuration: babel.config.js, tsconfig.json, vite.config.ts, turbo.json, GitHub workflows.
- Patterns:
- React Native module pattern (JS ↔ Native via Bridge).
- ProseMirror plugin pattern (“bridges” folder).
- Web‐editor submodule (simpleWebEditor, webEditorUtils) bundled into a WebView.

##### Key README Insights
- Core features and tech stack: React Native, React + TypeScript + Tiptap/ProseMirror + react-native-webview.
- Native toolbar & custom keyboards (Android & iOS view managers).
- Supports both Classic and New RN Architecture.
- Docs and examples hosted separately via website/.

##### Main Components & Their Interactions
a. React Native App (Host)
- Imports `@10play/tentap-editor`.
- Renders `<RichText>` and `<Toolbar>` components.
b. JS Core Library (src/)
- RichText.tsx, Toolbar.tsx: UI wrappers.
- Hooks: useEditorBridge(), useEditorContent(), useBridgeState().
- Bridges folder: ProseMirror node/mark extensions (bold, link, lists, etc.).
- Utilities & Themes.
c. Native Module Layer
- Android: TenTapPackage.kt, TenTapViewManager.kt, native spec files.
- iOS: RCTBridgeProvider.m, TenTapViewManager.mm, TenTapViewImpl.mm, helper utils.
- Exposes a Native UI component to JS (via ReactNativeViewManager).
d. WebView Editor Engine
- simpleWebEditor + webEditorUtils: Bundles a React + Tiptap editor UI in a webpage.
- Communicates with JS Core via postMessage/AsyncMessages.ts.
e. Messaging Bridge
- AsyncMessages.ts, useEditorBridge.tsx: bidirectional message dispatch between JS ↔ WebView ↔ Native.
f. Demo Applications
- example/, example76/: full RN apps integrating the library, showing Classic vs. New architecture.
g. Documentation Site
- website/: Docusaurus app serving docs (setup, API, examples).
h. Build & CI/CD
- scripts/buildEditor.js: compiles web editor bundle.
- GitHub Actions / workflows: CI tests, CD to npm & documentation site.

##### Architectural Patterns & Principles
- Layered architecture:
1. App Layer (React Native host)
2. Presentation Layer (RichText UI + Toolbar UI)
3. Domain Layer (Editor logic, ProseMirror plugins, state hooks)
4. Infrastructure Layer (Native view manager + WebView engine + messaging)
- Bridge Pattern: JS ↔ Native ↔ WebView.
- Plugin Pattern: ProseMirror extensions in `src/bridges`.
- Module separation: core library vs. examples vs. docs.
- Monorepo workspace (yarn, turbo.json).

##### Final Checklist
- Each component clearly labeled.
- Annotations of major frameworks and file-tree pointers (e.g., “android/ → TenTapPackage.kt”).
- A title and version note (e.g., “TenTap Editor vX – System Architecture”).

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "App Layer"
        RNApp["React Native App"]:::app
    end

    subgraph "Presentation Layer"
        JSCore["@10play/tentap-editor JS Core\n(React, TS, Tiptap)"]:::js
        subgraph "Messaging Bridge"
            AsyncMsgs["AsyncMessages.ts"]:::js
            UseBridge["useEditorBridge.tsx"]:::js
            UseState["useBridgeState.tsx"]:::js
            MsgTypes["Messaging.ts"]:::js
        end
    end

    subgraph "Infrastructure Layer"
        subgraph "Native Module - Android"
            AndPkg["TenTapPackage.kt"]:::native
            AndVM["TenTapViewManager.kt"]:::native
            AndNewSpec["TenTapViewManagerSpec.kt\n(newarch)"]:::native
            AndOldSpec["TenTapViewManagerSpec.kt\n(oldarch)"]:::native
        end
        subgraph "Native Module - iOS"
            iOSProv["RCTBridgeProvider.m"]:::native
            iOSVM["TenTapViewManager.mm"]:::native
            iOSImpl["TenTapViewImpl.mm"]:::native
            iOSUtils["TentapUtils.m"]:::native
        end
        subgraph "WebView Editor Engine"
            WEIndex["index.tsx"]:::web
            WEHtml["index.html"]:::web
            WETiptap["Tiptap.tsx"]:::web
            WEConfig["vite.config.ts"]:::web
            BuildEditor["buildEditor.js"]:::doc
        end
    end

    subgraph "Demo Applications"
        DemoClassic["Classic RN Demo"]:::app
        DemoNew["New RN Architecture Demo"]:::app
    end

    subgraph "Docs & CI/CD"
        Docs["Documentation Site\n(Docusaurus)"]:::doc
        CI["CI/CD & Tooling"]:::doc
    end

    RNApp -->|"imports & renders"| JSCore
    JSCore -->|"uses messaging"| AsyncMsgs
    AsyncMsgs -->|"dispatches"| UseBridge
    UseBridge -->|"updates"| UseState
    UseState -->|"types from"| MsgTypes

    JSCore -->|"UIManager.dispatchCommand"| AndPkg
    JSCore --> AndVM
    AndVM --> AndNewSpec
    AndVM --> AndOldSpec

    JSCore -->|"postMessage"| WEIndex
    WEIndex -->|"loads"| WEHtml
    WEIndex --> WETiptap
    WEIndex --> WEConfig
    WEIndex -->|"bundled by"| BuildEditor

    DemoClassic -->|"consumes"| JSCore
    DemoClassic -->|"includes native"| AndPkg
    DemoClassic --> iOSProv

    DemoNew -->|"consumes"| JSCore
    DemoNew --> AndNewSpec
    DemoNew --> iOSVM

    CI -->|"publishes"| JSCore
    CI -->|"deploys"| Docs
    JSCore -->|"docs sources"| Docs

    classDef app fill:#E3F2FD,stroke:#42A5F5,color:#0D47A1;
    classDef js fill:#E8EAF6,stroke:#5C6BC0,color:#1A237E;
    classDef native fill:#E8F5E9,stroke:#66BB6A,color:#1B5E20;
    classDef web fill:#FFFDE7,stroke:#FFEE58,color:#F57F17;
    classDef doc fill:#ECEFF1,stroke:#78909C,color:#263238;

    click JSCore "https://github.com/10play/10tap-editor/blob/main/src/index.tsx"
    click AsyncMsgs "https://github.com/10play/10tap-editor/blob/main/src/RichText/AsyncMessages.ts"
    click UseBridge "https://github.com/10play/10tap-editor/blob/main/src/useEditorBridge.tsx"
    click UseState "https://github.com/10play/10tap-editor/blob/main/src/useBridgeState.tsx"
    click MsgTypes "https://github.com/10play/10tap-editor/blob/main/src/types/Messaging.ts"
    click AndPkg "https://github.com/10play/10tap-editor/blob/main/android/src/main/java/com/tentap/TenTapPackage.kt"
    click AndVM "https://github.com/10play/10tap-editor/blob/main/android/src/main/java/com/tentap/TenTapViewManager.kt"
    click AndNewSpec "https://github.com/10play/10tap-editor/blob/main/android/src/newarch/TenTapViewManagerSpec.kt"
    click AndOldSpec "https://github.com/10play/10tap-editor/blob/main/android/src/oldarch/TenTapViewManagerSpec.kt"
    click iOSProv "https://github.com/10play/10tap-editor/blob/main/ios/RCTBridgeProvider.m"
    click iOSVM "https://github.com/10play/10tap-editor/blob/main/ios/TenTapViewManager.mm"
    click iOSImpl "https://github.com/10play/10tap-editor/blob/main/ios/TenTapViewImpl.mm"
    click iOSUtils "https://github.com/10play/10tap-editor/blob/main/ios/TentapUtils.m"
    click WEIndex "https://github.com/10play/10tap-editor/blob/main/src/simpleWebEditor/index.tsx"
    click WEHtml "https://github.com/10play/10tap-editor/blob/main/src/simpleWebEditor/index.html"
    click WETiptap "https://github.com/10play/10tap-editor/blob/main/src/simpleWebEditor/Tiptap.tsx"
    click WEConfig "https://github.com/10play/10tap-editor/blob/main/src/simpleWebEditor/vite.config.ts"
    click BuildEditor "https://github.com/10play/10tap-editor/blob/main/scripts/buildEditor.js"
    click DemoClassic "https://github.com/10play/10tap-editor/blob/main/example/src/App.tsx"
    click DemoNew "https://github.com/10play/10tap-editor/blob/main/example76/App.tsx"
    click Docs "https://github.com/10play/10tap-editor/blob/main/website/docusaurus.config.ts"
    click CI "https://github.com/10play/10tap-editor/blob/main/scripts/buildEditor.js"
```
