# galis/opentiktok architecture

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

- Interactive diagram: https://gitdiagram.com/galis/opentiktok
- Repository: https://github.com/galis/opentiktok

## Overview

- The “app” module, which contains the Android front-end, including activities, layout resources, and UI logic.
- The “avcore” module, which contains the video/audio processing engine. This module uses native C++ code (with shader files, JNI bridges, and build scripts for CMake) and integrates external libraries (like OpenCV, libyuv, and GLM) to implement filters, rendering effects, frame manipulation, and other core editing functions.

##### Overall Structure
a. Two main layers:
– The UI/Presentation Layer (from “app”) that handles user interaction, preview, and editing controls.
– The Core Video Processing Layer (from “avcore”) that includes lower-level native processing, filter application, video composition, and JNI bridging.

##### Main Components
- User Interface (UI):
– Activities and UI components (e.g., VideoEditActivity, VideoExportActivity, LogoActivity, and various custom views).
– Layouts and resources (layouts, menus, drawable assets).
- Application Logic:
– Java helper classes (e.g., BaseActivity, utility classes contained in “app/src/main/java/com/galix/opentiktok/ui”).
- Native Video Editing/Processing Engine:
– JNI Bridge Layer (files under avcore/src/main/cpp/jni and corresponding Java wrappers in avcore/src/main/java/com/galix/avcore/avcore).
– Core Processing Modules:
- AVEngine, AVFrame, AVVideo, AVSync, etc. (classes handling audio/video processing and composition).
– Rendering and Filter Modules:
- Submodules under “avcore/src/main/java/com/galix/avcore/render” (e.g., filters like BeautyFilter, LutFilter, OesFilter, PagFilter, etc.).
- Native C++ Code:
– Core implementation files and shader resources (located in avcore/src/main/cpp, including the shader files in res/raw for different effects).
- External Libraries & Dependencies:
– OpenCV, libyuv, GLM, and others (visible from the extensive include directories and integration code).
- Build and Configuration:
– Gradle build scripts and CMakeLists.txt, which direct how the Java and native layers are compiled and integrated.
- Assets:
– Video test files, LUTs, animation files, etc. (present in app/src/main/assets and app/src/main/res).

##### Relationships and Interactions
- That user interactions in the UI trigger events in the application layer that call into the AVCore’s Java wrappers.
- That these Java components call the JNI methods to invoke native C++ processing functions.
- Integration boundaries:
- How external libraries (like OpenCV) are “wrapped” inside the native processing engine, and how shader code is employed to implement rendering effects.

##### Architectural Patterns and Principles
- Modular design: Separation between UI and processing layers.
- Encapsulation: The AVCore module provides clean interfaces (via JNI and Java wrappers) to hide native implementation details.
- Use of a layered approach:
– Presentation layer (Android activities, layouts)
– Application logic (Java classes managing user actions)
– Processing layer (native video/audio processing, filter pipelines)
- Integration and dependency inversion: The UI layer depends on abstractions provided by AVCore, which in turn relies on lower-level native libraries.

- Link this block to an “AVCore Engine” block that further breaks down into:
– “Java Wrapper & AV Interface” (handling calls from the app)
– “Native C++ Processing Core” (filtering, compositing, video rendering, and shader management)
- A side component for “External Libraries” that feeds into the native layer.
- Every edge has labels showing data flow (e.g., “User Command”, “Frame Data”, “Processing Results”) and every component is clearly delineated.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top level user interaction
    U("User Interaction") 

    %% UI/Presentation Layer
    subgraph "UI/Presentation Layer"
        UI("UI Components (Activities, Layouts)"):::ui
        AL("Application Logic (Java Helpers)"):::ui
    end

    %% AVCore Engine Layer
    subgraph "AVCore Engine"
        JW("AVCore Java Wrapper"):::bridge
        JNI("JNI Bridge"):::bridge
        CPP("Native C++ Processing"):::core
        RF("Rendering & Filters (Java)"):::core
    end

    %% External & Configuration
    EL("External Libraries"):::external
    AS("Assets & Shader Resources"):::external
    BC("Build & Config"):::external

    %% Connections between layers
    U -->|"UserCommand"| UI
    UI -->|"Triggers"| AL
    UI -->|"UserCommand"| JW
    JW -->|"CallJNI"| JNI
    JNI -->|"ProcessVideo"| CPP
    CPP -->|"ApplyFilters"| RF
    RF -->|"DisplayFrame"| UI

    %% External and configuration integrations
    EL -->|"LibraryIntegration"| CPP
    AS -->|"ResourceData"| CPP
    BC -->|"AppSetup"| UI
    BC -->|"NativeBuildSetup"| JW

    %% Styles
    classDef ui fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef bridge fill:#ffff99,stroke:#000,stroke-width:2px;
    classDef core fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef external fill:#dda0dd,stroke:#000,stroke-width:2px;

    %% Click events for components
    click UI "https://github.com/galis/opentiktok/tree/master/app/src/main/java/com/galix/opentiktok/ui"
    click AL "https://github.com/galis/opentiktok/tree/master/app/src/main/java/com/galix/opentiktok/ui"
    click JW "https://github.com/galis/opentiktok/tree/master/avcore/src/main/java/com/galix/avcore/avcore"
    click JNI "https://github.com/galis/opentiktok/tree/master/avcore/src/main/cpp/jni"
    click CPP "https://github.com/galis/opentiktok/tree/master/avcore/src/main/cpp/core"
    click RF "https://github.com/galis/opentiktok/tree/master/avcore/src/main/java/com/galix/avcore/render"
    click EL "https://github.com/galis/opentiktok/tree/master/avcore/src/main/cpp/include/opencv2"
    click AS "https://github.com/galis/opentiktok/tree/master/app/src/main/assets"
    click BC "https://github.com/galis/opentiktok/blob/master/avcore/src/main/cpp/CMakeLists.txt"
```
