# vhqtvn/vheditor-android architecture

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

- Interactive diagram: https://gitdiagram.com/vhqtvn/vheditor-android
- Repository: https://github.com/vhqtvn/vheditor-android

## Overview

##### Project type and purpose
- Project Type: This is an Android application that repurposes the open-source code-server (from https://github.com/cdr/code-server) to build a mobile version of a code editor. It integrates native Android UI components, built-in termux for terminal support, and even native C/C++ code (with SIMD optimizations for bitmap processing) to enhance performance.
- Purpose: The app not only delivers a code editing experience similar to Visual Studio Code (but using code-server as its core) but also integrates terminal functionalities and additional enhancements (such as a virtual mouse and React Native modules) to deliver a modern, mobile-friendly development environment.

##### Analyzing the file structure
- Top-Level Directories & Key Files:
- The “app/” directory contains the complete Android app’s source code.
- “app/src/main/java” hosts multiple Java/Kotlin packages:
▸ com.termux – for Termux integration.
▸ vn.vhn.reactnative – for bridging native functionalities with React Native modules.
▸ vn.vhn.vhscode – the main code server integration and UI logic (including activities, fragments, and background services).
▸ vn.vhn.virtualmouse – for the virtual mouse support.
- “app/src/main/cpp” contains C/C++ code supporting performance-critical functionalities (like bitmap rendering, blur operations, and bootstrapping scripts). This part uses Gradle (via CMakeLists.txt and Android.mk) to compile native libraries.
- Build scripts (e.g., build.gradle, settings.gradle, and gradlew/sk) and CI configurations in “.github/workflows” indicate automated build/test pipelines.
- Configuration and resource files under “app/src/main/res” define the UI layouts, drawable assets, and other Android-specific resources.
- Additional JavaScript and React Native configuration files (e.g., metro.config.js, react-native.config.js) lie in the root and “js/” directories.

##### Components and their roles
a. UI/Presentation Layer (Android Activities/Fragments):
- Contains activities like EditorHostActivity, NewSessionActivity, and components such as sessions list and dialog fragments.
- Managed under packages such as vn.vhn.vhscode.root and vn.vhn.vhscode.ui.
b. Code Server Integration:
- Provides the core code editor engine (adapted from cdr/code-server), incorporating server-side functionalities that enable editing and file management.
- Components include services like CodeServerLocalService and managers for local/remote sessions.
c. Terminal/Termux Integration:
- Integrated as a built-in terminal for running shell commands (e.g., the apt install note in the README).
- Managed by classes in com.termux and vn.vhn.vhscode.root.terminal.
d. Native Code (C/C++ Layer):
- Implements performance-intensive features for bitmap processing (e.g., blending, blur operations) with architecture-specific optimizations using assembly (neon, advsimd) for rapid execution.
- Acts as a native native module callable from Java via JNI.
e. React Native Modules:
- Present in the vn.vhn.reactnative package, providing bridging to additional functionalities (likely for enhancing UI or integrating extra features).
f. Virtual Mouse Module:

##### Relationships and interactions between components
- The Android UI layer communicates with background services:
- The Code Server components run as services (local/remote) that the UI invokes to create editor sessions.
- The built-in terminal (via Termux service) is launched through dedicated activities/fragments.
- The Java/Kotlin code interacts with native libraries:
- JNI bridges are established between Java activities (or service components) and the C/C++ native library for bitmap operations.
- React Native modules and other delegated components hook into the Android lifecycle to render or augment features when needed.
- Virtual Mouse touches both the UI and system input layers to enhance the interaction experience.

##### Architectural patterns and design principles in use
- Modularity: The project clearly separates concerns by isolating Android UI, code-server backend components, native code segments, and terminal features in distinct packages.
- Service-oriented components: Background services (e.g., CodeServerLocalService, TermuxService) handle specific functions in a decoupled manner.
- Native-bridge design: The integration of C/C++ via JNI reflects the optimization for performance-critical sections.
- Hybrid Integration: The mix of standard Android UI with React Native modules shows a design oriented toward utilizing multiple frameworks where they best fit.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "Android Application"
        subgraph "UI Layer"
            UI["Android UI (Activities/Fragments)"]:::ui
        end
        subgraph "Service Layer"
            CS["Code Server Integration"]:::service
            TUI["Terminal UI & Management"]:::service
            TServ["Termux Services & Installer"]:::service
        end
        subgraph "Native Integration"
            NJ["Native Code (JNI & C/C++)"]:::native
        end
    end

    subgraph "Additional Modules"
        RN["React Native Module"]:::module
        VM["Virtual Mouse Module"]:::module
    end

    subgraph "CI/CD & Build"
        Gradle["Gradle Build Scripts"]:::build
        Workflows["GitHub Workflows"]:::build
    end

    %% Connections within Android Application
    UI -->|"sessionMgmt"| CS
    UI -->|"terminalOps"| TUI
    TUI -->|"integrates"| TServ
    CS -->|"JNIcalls"| NJ
    TUI -->|"JNIcalls"| NJ

    %% Connections from Additional Modules to Android UI
    RN -->|"bridges"| UI
    VM -->|"enhancedInput"| UI

    %% CI/CD supports Android Application
    Gradle -->|"buildDeploy"| UI
    Workflows -->|"buildDeploy"| UI

    %% Styling
    classDef ui fill:#a2d5f2,stroke:#000,stroke-width:2px;
    classDef service fill:#f3d250,stroke:#000,stroke-width:2px;
    classDef native fill:#e27d60,stroke:#000,stroke-width:2px;
    classDef module fill:#85dcb,stroke:#000,stroke-width:2px;
    classDef build fill:#d5e1df,stroke:#000,stroke-width:2px;

    %% Click Events
    click UI "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/java/vn/vhn/vhscode/root"
    click CS "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/java/vn/vhn/vhscode/root/codeserver"
    click TUI "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/java/vn/vhn/vhscode/root/terminal"
    click TServ "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/java/com/termux/app"
    click NJ "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/cpp"
    click RN "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/java/vn/vhn/reactnative/modules"
    click VM "https://github.com/vhqtvn/vheditor-android/tree/master/app/src/main/java/vn/vhn/virtualmouse"
    click Gradle "https://github.com/vhqtvn/vheditor-android/blob/master/build.gradle"
    click Workflows "https://github.com/vhqtvn/vheditor-android/blob/master/.github/workflows/build-android.yaml"
```
