# appium/android-apidemos architecture

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

- Interactive diagram: https://gitdiagram.com/appium/android-apidemos
- Repository: https://github.com/appium/android-apidemos

## Overview

##### Project type and purpose
- This is a single-module Android application (“android-apidemos”) packaged inside a Node.js/npm wrapper.
- Its sole purpose is to build the Google ApiDemos Android app (a suite of demo screens) into a debug APK for automated UI testing with Appium.

##### File structure
- Top-level wrapper:
- package.json, index.js – npm entry point
- scripts/ (build.js, gradle-version-update.js) – Node.js build orchestration
- .github/workflows/build.yml – CI pipeline definition
- Android project in /app:
- app/build.gradle, settings.gradle, Gradle wrapper (gradlew, gradle/wrapper)
- app/src/main/java – Java source for all demo activities and AIDL interfaces
- app/src/main/res – layouts, drawables, menus, raw assets, XML resources
- app/src/main/assets – HTML, fonts, bundled APK for asset-read tests
- app/src/androidTest – instrumentation test stubs and resources
- The build output (ApiDemos-debug.apk) lands in an /apks folder (created at build time).

##### README for additional insights
- Requires Java 17 and Node.js.
- Build command is `npm run build`, which invokes the Node script that in turn calls Gradle to compile, link resources, and generate the APK.

##### Main components
a. Node.js/npm layer
– npm CLI
– index.js build entry point
– scripts/build.js → delegates to Gradle wrapper
b. Gradle build system
– gradlew + gradle-wrapper.jar
– app module (build.gradle)
c. Android app module
– Java source code (demo activities, AIDL services)
– Resource bundle (layouts, drawables, menus, values, assets)
– AndroidManifest (declares activities, services, instrumentation)
d. CI/CD pipeline (GitHub Actions)
– .github/workflows/build.yml
– installs Java/Node → npm run build → archives APK artifact
e. External test harness
– Appium server (not part of repo but target consumer)
– Android emulator or real device

##### Relationships and data flows
1. Developer runs `npm install` → Node dependencies loaded
2. Developer/CI invokes `npm run build`
3. index.js → build.js → executes `./gradlew assembleDebug`
4. Gradle compiles Java + AIDL → merges resources → packages ApiDemos-debug.apk
5. CI stores APK as build artifact
6. Appium connects to emulator/device, installs the APK, and drives UI tests

##### Architectural patterns and design principles
- Monolithic mobile app module built via standard Gradle Android plugin
- Node.js wrapper to integrate Android build into npm scripts (common for JavaScript-centric pipelines)
- Clear separation of concerns:
- Build orchestration (scripts)
- Build engine (Gradle)
- Application code & resources (app/)
- CI configuration (.github/)

##### Relevant technologies
- Java 17, Android SDK
- Gradle build system with wrapper
- Node.js and npm for scripting
- GitHub Actions for CI/CD
- AIDL (Android Interface Definition Language) for interprocess APIs
- Appium as external UI test consumer

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Developer
    Developer["Developer"]:::external

    %% Node.js/npm Layer
    subgraph "Node.js/npm Layer"
        pkg["package.json"]:::orchestration
        npm["npm CLI"]:::orchestration
        idx["index.js"]:::orchestration
        subgraph "Scripts"
            buildjs["build.js"]:::orchestration
            gradlevu["gradle-version-update.js"]:::orchestration
        end
    end

    %% Gradle Wrapper & Plugin
    subgraph "Gradle Wrapper & Plugin"
        gradlew["gradlew"]:::engine
        gradlewbat["gradlew.bat"]:::engine
        wrapperjar["gradle-wrapper.jar"]:::engine
        wrapperprops["gradle-wrapper.properties"]:::engine
    end

    %% Top-Level Gradle Configuration
    subgraph "Top-Level Gradle Config"
        rootbuild["build.gradle"]:::engine
        settings["settings.gradle"]:::engine
        gradleprops["gradle.properties"]:::engine
    end

    %% Android App Module
    subgraph "Android App Module"
        appgradle["app/build.gradle"]:::engine
        manifest["AndroidManifest.xml"]:::appcode
        subgraph "Source & Interfaces"
            java["app/src/main/java/"]:::appcode
            aidl["app/src/main/aidl/"]:::appcode
        end
        subgraph "Resources"
            res["app/src/main/res/"]:::appcode
        end
        assets["app/src/main/assets/"]:::appcode
        instr["app/src/androidTest/"]:::appcode
    end

    %% CI/CD Pipeline
    subgraph "CI/CD (GitHub Actions)"
        ciwf[".github/workflows/build.yml"]:::ci
    end

    %% Artifact
    apk["ApiDemos-debug.apk\n(/apks)"]:::external

    %% External Test Harness
    subgraph "External Test Harness"
        appium["Appium Server"]:::external
        device["Android Emulator/Device"]:::external
    end

    %% Connections
    Developer -->|"npm install"| npm
    npm -->|"reads pkg"| pkg
    npm -->|"exec index.js"| idx
    idx -->|"delegates"| buildjs
    idx -->|"delegates"| gradlevu
    buildjs -->|"invoke assembleDebug"| gradlew
    gradlew -->|"loads wrapper"| wrapperjar
    gradlew -->|"loads wrapper"| wrapperprops
    gradlew -->|"uses config"| rootbuild
    gradlew -->|"uses config"| settings
    gradlew -->|"uses config"| gradleprops
    gradlew -->|"executes"| appgradle
    appgradle -->|"compile & package"| java
    appgradle -->|"compile AIDL"| aidl
    appgradle -->|"merge resources"| res
    appgradle -->|"include assets"| assets
    appgradle -->|"include manifest"| manifest
    appgradle -->|"include tests"| instr
    appgradle -->|"output APK"| apk
    ciwf -->|"trigger build"| npm
    ciwf -->|"store artifact"| apk
    apk -->|"install & run tests"| appium
    appium -->|"drives UI on"| device

    %% Click Events
    click pkg "https://github.com/appium/android-apidemos/blob/master/package.json"
    click idx "https://github.com/appium/android-apidemos/blob/master/index.js"
    click buildjs "https://github.com/appium/android-apidemos/blob/master/scripts/build.js"
    click gradlevu "https://github.com/appium/android-apidemos/blob/master/scripts/gradle-version-update.js"
    click ciwf "https://github.com/appium/android-apidemos/blob/master/.github/workflows/build.yml"
    click gradlew "https://github.com/appium/android-apidemos/tree/master/gradlew"
    click gradlewbat "https://github.com/appium/android-apidemos/blob/master/gradlew.bat"
    click wrapperjar "https://github.com/appium/android-apidemos/blob/master/gradle/wrapper/gradle-wrapper.jar"
    click wrapperprops "https://github.com/appium/android-apidemos/blob/master/gradle/wrapper/gradle-wrapper.properties"
    click rootbuild "https://github.com/appium/android-apidemos/blob/master/build.gradle"
    click settings "https://github.com/appium/android-apidemos/blob/master/settings.gradle"
    click gradleprops "https://github.com/appium/android-apidemos/blob/master/gradle.properties"
    click appgradle "https://github.com/appium/android-apidemos/blob/master/app/build.gradle"
    click java "https://github.com/appium/android-apidemos/tree/master/app/src/main/java/"
    click aidl "https://github.com/appium/android-apidemos/tree/master/app/src/main/aidl/"
    click res "https://github.com/appium/android-apidemos/tree/master/app/src/main/res/"
    click assets "https://github.com/appium/android-apidemos/tree/master/app/src/main/assets/"
    click manifest "https://github.com/appium/android-apidemos/blob/master/app/src/main/AndroidManifest.xml"
    click instr "https://github.com/appium/android-apidemos/tree/master/app/src/androidTest/"

    %% Styles
    classDef orchestration fill:#AED6F1,stroke:#1B4F72,color:#1B2631
    classDef engine fill:#ABEBC6,stroke:#145A32,color:#0B5345
    classDef appcode fill:#F9E79F,stroke:#B9770E,color:#7E5109
    classDef external fill:#D5DBDB,stroke:#626567,color:#1C2833
    classDef ci fill:#D2B4DE,stroke:#6C3483,color:#4A235A
```
