# cnlohr/rawdrawandroid architecture

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

- Interactive diagram: https://gitdiagram.com/cnlohr/rawdrawandroid
- Repository: https://github.com/cnlohr/rawdrawandroid

## Overview

##### Main Components

a) Core Components:
- Native Application Layer (C/NDK)
- Android Native App Glue Bridge
- OpenGL ES Rendering System
- Asset Management System
- Input Handling System
- USB Device Interface
- Permission Management System

b) External Interfaces:
- Android Platform APIs
- Device Hardware (Accelerometer, Gyro, Touch)
- USB Devices
- OpenGL ES
- Asset Storage

**[Hardware Layer]**
- ↑↓
**[Android Platform Layer]**
- ↑↓
**[Native Bridge Layer (android_native_app_glue)]**
- ↑↓
**[Core Application Layer]**

- [Rendering System]

- [Input System]

- [Asset Management]

- [USB Interface]

##### Key Relationships to Highlight

a) Data Flow:
- How input events flow from hardware through the native bridge
- Rendering pipeline from application to screen
- Demonstrate asset loading path
- USB device communication flow

b) Component Integration:
- How the native code interfaces with Android through JNI
- Permission management flow
- Build system integration

##### Technical Details

- NDK/JNI bridge mechanisms
- OpenGL ES integration
- Asset management through AAssetManager
- Input handling system (touch, accelerometer, keyboard)
- USB device interface
- Permission management system

##### Implementation Notes

- Notes about the required implementation of HandleResume(), HandleSuspend(), and HandleWindowTermination()
- Reference to the modified HandleMotion() behavior
- Relationship with the rawdraw framework

- Minimal overhead design
- Direct hardware access
- Native code focus
- Build system simplicity

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Hardware
        HW_TOUCH["Touch Input"]:::hardware
        HW_ACCEL["Accelerometer/Gyro"]:::hardware
        HW_USB["USB Devices"]:::hardware
        HW_DISPLAY["Display"]:::hardware
    end

    subgraph "Android Platform"
        AND_API["Android Platform APIs"]:::android
        AND_GL["OpenGL ES"]:::android
    end

    subgraph "Native Bridge"
        GLUE["Android Native App Glue"]:::native
        JNI["JNI Interface"]:::native
    end

    subgraph "Core Application"
        NATIVE_APP["Native Application"]:::native
        RENDER["Rendering System"]:::native
        INPUT["Input System"]:::native
        ASSET["Asset Management"]:::native
        USB["USB Interface"]:::native
        PERM["Permission Manager"]:::native
        WV["WebView Interface"]:::native
    end

    subgraph "Build System"
        MAKE["Make System"]:::build
        APK["APK Generation"]:::build
        DOCKER["Container Environment"]:::build
    end

    subgraph "Resources"
        ASSETS["Asset Storage"]:::resource
        RES["Resource Files"]:::resource
    end

    %% Relationships
    HW_TOUCH --> AND_API
    HW_ACCEL --> AND_API
    HW_USB --> USB
    AND_GL --> HW_DISPLAY

    AND_API --> GLUE
    GLUE --> JNI
    JNI --> NATIVE_APP

    NATIVE_APP --> RENDER
    NATIVE_APP --> INPUT
    NATIVE_APP --> ASSET
    NATIVE_APP --> USB
    NATIVE_APP --> PERM
    NATIVE_APP --> WV

    RENDER --> AND_GL
    INPUT --> GLUE
    ASSET --> ASSETS
    PERM --> AND_API
    USB --> HW_USB

    MAKE --> APK
    DOCKER --> MAKE

    %% Styles
    classDef hardware fill:#ff9900,stroke:#333,stroke-width:2px
    classDef android fill:#3498db,stroke:#333,stroke-width:2px
    classDef native fill:#2ecc71,stroke:#333,stroke-width:2px
    classDef build fill:#95a5a6,stroke:#333,stroke-width:2px
    classDef resource fill:#e74c3c,stroke:#333,stroke-width:2px

    %% Click events
    click NATIVE_APP "https://github.com/cnlohr/rawdrawandroid/blob/master/test.c"
    click GLUE "https://github.com/cnlohr/rawdrawandroid/blob/master/android_native_app_glue.c"
    click USB "https://github.com/cnlohr/rawdrawandroid/blob/master/android_usb_devices.c"
    click ASSET "https://github.com/cnlohr/rawdrawandroid/tree/master/Sources/assets/"
    click RES "https://github.com/cnlohr/rawdrawandroid/tree/master/Sources/res/"
    click PERM "https://github.com/cnlohr/rawdrawandroid/blob/master/AndroidManifest.xml.template"
    click MAKE "https://github.com/cnlohr/rawdrawandroid/tree/master/Makefile"
    click DOCKER "https://github.com/cnlohr/rawdrawandroid/tree/master/docker/Dockerfile"
    click WV "https://github.com/cnlohr/rawdrawandroid/blob/master/webview_native_activity.h"
    click ASSETS "https://github.com/cnlohr/rawdrawandroid/blob/master/Sources/res/values/strings.xml"
    click RES "https://github.com/cnlohr/rawdrawandroid/tree/master/Sources/res/mipmap/"
```
