# celpear/flutdot architecture

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

- Interactive diagram: https://gitdiagram.com/celpear/flutdot
- Repository: https://github.com/celpear/flutdot

## Overview

##### Project type and purpose
- This is a cross-platform Flutter application (mobile: Android/iOS; desktop: Windows/macOS/Linux; web) that embeds a Godot game export (WebAssembly + HTML + JS) inside a Flutter InAppWebView.
- Its purpose is to combine Flutter’s UI and sensor-access capabilities with Godot’s 3D rendering engine, allowing bidirectional communication (e.g. passing sensor data into Godot and game events back to Flutter).

##### File structure
- Top-level “GoDotExport/” folder holds the Godot Web export (index.html, index.js, index.wasm, audio.worklet).
- “flutdot_godot_demo_project/” is the original Godot project source.
- “lib/” contains Flutter code:
- lib/main.dart – application entry point
- lib/module/flutdot.dart – plugin module wrapping webview + communication logic
- Platform folders (android/, ios/, macos/, linux/, windows/) contain Flutter project boilerplate and native runner code.
- “APKBuilds/” holds test APKs.
- Configuration files: pubspec.yaml, build scripts (Gradle, Xcode project files, CMake scripts for desktop).

##### Key insights from README
- The Godot export is loaded into a Flutter InAppWebView widget.
- Temporary communication uses JS injection + log parsing; future plan is Socket.IO/WebSocket.
- Uses Flutter packages: flutter_inappwebview, sensors_plus, axios (JS), socket.io (planned).

##### Main components
a. Flutter Layer
- UI widgets (Material UI)
- Sensor plugin (sensors_plus)
- InAppWebView widget
b. WebView / Godot Layer
- Godot engine compiled to WASM
- index.html + index.js loader
- Game logic scripts (DemoScene.gd, Player.gd inside WASM)
c. Communication Layer
- JS ↔ Dart bridge (evaluateJavascript, onConsoleMessage)
- Planned WebSocket/Socket.IO channel
d. Native Runners & Platform Folders
- Android (Kotlin MainActivity)
- iOS/macOS (Swift AppDelegate)
- Windows/Linux (C++ runner)

##### Relationships & data flows
- Sensor data (Dart) → serialize to JSON → WebView.evaluateJavascript() → Godot game engine
- Game events (JS console.log or WebSocket) → Dart onConsoleMessage or WebSocket listener → Flutter UI
- App lifecycle & platform channels (Flutter → native runner → embed WebView)

##### Architectural patterns & design principles
- Separation of concerns: Flutter UI vs. embedded game engine
- Plugin/module pattern: lib/module/flutdot.dart encapsulates webview + comms
- Cross-platform abstraction: a single Flutter codebase with per-platform runners

1. Sketch high-level layers (Flutter → WebView → Godot → Platform).
2. Break out sub-components (Dart modules, JS loader, WASM engine).
5. Notes on build outputs (APKBuilds, desktop binaries) and configuration (pubspec.yaml, gradle, CMake).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer"
        UI["Flutter UI Widgets"]:::flutter
        Main["main.dart"]:::flutter
        Sensor["sensors_plus Integration"]:::flutter
        Flutdot["Flutdot Plugin Module\n(WebView + Comms)"]:::flutter
    end

    %% Engine Layer
    subgraph "Engine Layer"
        subgraph "GoDotExport (Engine Assets)"
            HTML["index.html"]:::godot
            JSLoader["index.js"]:::godot
            WASM["index.wasm"]:::godot
            AudioWorklet["index.audio.worklet.js"]:::godot
            Engine["Godot Engine + Game Logic\n(DemoScene.gd, Player.gd)"]:::godot
        end
        subgraph "Godot Source"
            DemoSceneGd["DemoScene.gd"]:::godot
            PlayerGd["Player.gd"]:::godot
            DemoSceneTscn["DemoScene.tscn"]:::godot
        end
    end

    %% Communication Layer
    subgraph "Communication Layer"
        JSBridge["JS ↔ Dart Bridge\n(evaluateJavascript & onConsoleMessage)"]:::comm
        WS["WebSocket / Socket.IO (planned)"]:::comm
    end

    %% Platform Runners
    subgraph "Platform Runners"
        Android["Android Runner\n(MainActivity.kt)"]:::platform
        iOS["iOS Runner\n(AppDelegate.swift)"]:::platform
        macOS["macOS Runner\n(AppDelegate.swift)"]:::platform
        Linux["Linux Runner\n(main.cc)"]:::platform
        WindowsMain["Windows Runner\n(main.cpp)"]:::platform
        WindowsWindow["Windows Runner\n(flutter_window.cpp/h)"]:::platform
        WebHost["Flutter Web Host\n(web/index.html)"]:::platform
    end

    %% Config & Build Outputs
    subgraph "Configuration & Build"
        Pubspec["pubspec.yaml"]:::config
        Gradle["android/app/build.gradle"]:::config
        Podfile["ios/Podfile"]:::config
        CMakeLinux["linux/CMakeLists.txt"]:::config
        CMakeWindows["windows/CMakeLists.txt"]:::config
        Test["test/widget_test.dart"]:::config
        APK["APKBuilds/flutdot_test.apk"]:::config
    end

    %% Data Flows
    Sensor -->|JSON| Main
    Main --> Flutdot
    Flutdot -->|embed| WebView
    WebView -->|loads| HTML
    HTML --> JSLoader
    JSLoader --> WASM
    JSLoader --> AudioWorklet
    JSLoader --> Engine
    DemoSceneGd --> Engine
    PlayerGd --> Engine
    DemoSceneTscn --> Engine
    Engine -->|console.log / WebSocket| JSBridge
    JSBridge --> Flutdot
    WS --> Flutdot
    Flutdot -->|evaluateJavascript| JSBridge
    Android --> Flutdot
    iOS --> Flutdot
    macOS --> Flutdot
    Linux --> Flutdot
    WindowsMain --> Flutdot
    WindowsWindow --> Flutdot
    WebHost --> Flutdot
    Pubspec --> Sensor
    Pubspec --> Flutdot
    Gradle --> Android
    Podfile --> iOS
    CMakeLinux --> Linux
    CMakeWindows --> WindowsMain
    Test --> Main
    APK --> Android

    %% Click Events
    click Main "https://github.com/celpear/flutdot/blob/main/lib/main.dart"
    click Flutdot "https://github.com/celpear/flutdot/blob/main/lib/module/flutdot.dart"
    click Sensor "https://github.com/celpear/flutdot/blob/main/pubspec.yaml"
    click WebView "https://github.com/celpear/flutdot/blob/main/lib/module/flutdot.dart"
    click HTML "https://github.com/celpear/flutdot/blob/main/GoDotExport/index.html"
    click JSLoader "https://github.com/celpear/flutdot/blob/main/GoDotExport/index.js"
    click WASM "https://github.com/celpear/flutdot/blob/main/GoDotExport/index.wasm"
    click AudioWorklet "https://github.com/celpear/flutdot/blob/main/GoDotExport/index.audio.worklet.js"
    click DemoSceneGd "https://github.com/celpear/flutdot/blob/main/flutdot_godot_demo_project/DemoScene.gd"
    click PlayerGd "https://github.com/celpear/flutdot/blob/main/flutdot_godot_demo_project/Player.gd"
    click DemoSceneTscn "https://github.com/celpear/flutdot/blob/main/flutdot_godot_demo_project/DemoScene.tscn"
    click Android "https://github.com/celpear/flutdot/blob/main/android/app/src/main/kotlin/com/example/flutdot/MainActivity.kt"
    click iOS "https://github.com/celpear/flutdot/blob/main/ios/Runner/AppDelegate.swift"
    click macOS "https://github.com/celpear/flutdot/blob/main/macos/Runner/AppDelegate.swift"
    click Linux "https://github.com/celpear/flutdot/blob/main/linux/main.cc"
    click WindowsMain "https://github.com/celpear/flutdot/blob/main/windows/runner/main.cpp"
    click WindowsWindow "https://github.com/celpear/flutdot/blob/main/windows/runner/flutter_window.cpp"
    click WebHost "https://github.com/celpear/flutdot/blob/main/web/index.html"

    %% Styles
    classDef flutter fill:#bbdefb,stroke:#1e88e5,color:#1e88e5
    classDef webview fill:#cfd8dc,stroke:#607d8b,color:#37474f
    classDef godot fill:#c8e6c9,stroke:#388e3c,color:#2e7d32
    classDef comm fill:#ffecb3,stroke:#fbc02d,color:#f57f17
    classDef platform fill:#ffe0b2,stroke:#fb8c00,color:#e65100
    classDef config fill:#f5f5f5,stroke:#9e9e9e,color:#616161
```
