# bytedeco/javacpp architecture

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

- Interactive diagram: https://gitdiagram.com/bytedeco/javacpp
- Repository: https://github.com/bytedeco/javacpp

## Overview

##### Main Components
- Java Application Layer: Represent the classes in src/main/java that expose the core API. Include major utility classes such as Loader, Pointer types, FunctionPointer, and annotation-based mappings.
- Native Component Layer: Indicate the native C/C++ code that is generated or wrapped through JNI. Highlight the examples (like the C++ native functions and header representations) and the “platform” module which includes build definitions and native assembly descriptors.
- Build and Test Infrastructure: Include the Maven build system (pom.xml files at the root and under platform), integration tests (src/it), and the continuous integration configuration files (in .github/workflows, .travis.yml). This shows how the code flows from source, through build, to testing.

##### Relationships and Interactions
- Bidirectional interaction: On one hand, JavaCPP acts as a generator—by processing annotated Java classes and producing corresponding JNI C++ files; on the other, it uses the JNI layer to relay calls from Java to native code and back.
- Build pipeline: Maven (and the accompanying pom.xml assemblies) drive the build process for both compiling Java code and assembling native binaries.

##### Architectural Patterns and Design Principles
- Modular Structure: Emphasize the separation of concerns; for example, integration tests (osgi tests in src/it) are kept separate from the core implementation.
- Abstraction through Annotations: Indicate how annotations (like @Platform, @Namespace, @Virtual, and @Cast) help abstract the complexity of native bindings.
- Cross-platform Strategy: Show that native properties files and assembly scripts facilitate compiling for multiple platforms (Android, iOS, Linux, Windows, etc.).

##### Relevant Technologies and Frameworks
- Java and the Java Virtual Machine, Maven (as build and dependency management tool), C++ (and its respective compilers such as gcc, clang, MSVC).
- JNI as the bridging technology.
- Tools like Travis CI and GitHub workflows for continuous integration.
- Optional integration with tools for Android (NDK) and iOS (RoboVM/Gluon VM) if needed.

##### Diagramical Elements
- Integration Points: Mark integration test areas and continuous integration flows (Travis CI, GitHub workflows) to complete the overall picture.

##### Final Advice
- Be detailed: Do not shy away from breaking down the project into subcomponents (e.g., separate those that handle annotations versus those that handle runtime loading).
- Out the dependencies: Indicate the build dependencies from Maven, how the “pom.xml” files control the compilation of both Java and native code.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build and Test Infrastructure
    subgraph "Build and Test Infrastructure"
        TRAVIS["Travis CI"]:::ci
        GITHUB["GitHub Workflows"]:::ci
        ROOTPOM["Root POM (pom.xml)"]:::build
        PLATFORMPOM["Platform POM (platform/pom.xml)"]:::build
        ITPOM["Integration Test POM (src/it/osgi/pom.xml)"]:::build
        INTEG["Integration Tests (src/it)"]:::build
    end

    %% Java Application Layer
    subgraph "Java Application Layer"
        COREAPI["Core API (Loader, Pointers, FunctionPointer, Annotations)"]:::java
    end

    %% JNI Bridge
    subgraph "JNI Bridge"
        JNI["JNI Bridge (Generated JNI Glue & Loader.load call)"]:::bridge
    end

    %% Native Component Layer
    subgraph "Native Component Layer"
        NATIVEEX["Native Examples & Test Code (C/C++)"]:::native
        PLATFORMCFG["Platform Build Configs & Assembly Descriptors"]:::native
    end

    %% Platform-specific and Preset Layers
    subgraph "Platform-specific Presets"
        PRESETS["Native Presets (Properties for Android, iOS, Linux, Windows, etc.)"]:::preset
    end

    %% Build Infrastructure Connections
    TRAVIS --> ROOTPOM
    GITHUB --> ROOTPOM
    ROOTPOM --> COREAPI
    PLATFORMPOM --> PLATFORMCFG
    ITPOM --> INTEG
    INTEG --> COREAPI

    %% Application to JNI Bridge Connections
    COREAPI -->|"calls Loader.load()"| JNI

    %% JNI Bridge to Native Component Connections
    JNI -->|"invokes native functions"| NATIVEEX
    JNI -->|"invokes native functions"| PLATFORMCFG
    NATIVEEX -->|"returns results"| JNI

    %% Preset to Platform Build Configs Connection
    PRESETS --> PLATFORMCFG

    %% Class Definitions for styling
    classDef java fill:#f4b400,stroke:#333,stroke-width:2px;
    classDef native fill:#4285f4,stroke:#333,stroke-width:2px;
    classDef build fill:#0f9d58,stroke:#333,stroke-width:2px;
    classDef ci fill:#fbbc05,stroke:#333,stroke-width:2px;
    classDef bridge fill:#9c27b0,stroke:#333,stroke-width:2px;
    classDef preset fill:#ff7043,stroke:#333,stroke-width:2px;

    %% Click Events for Component Mappings
    click COREAPI "https://github.com/bytedeco/javacpp/tree/master/src/main/java/org/bytedeco/javacpp"
    click JNI "https://github.com/bytedeco/javacpp/blob/master/src/main/java/org/bytedeco/javacpp/Loader.java"
    click NATIVEEX "https://github.com/bytedeco/javacpp/tree/master/src/it/osgi/src/main/c"
    click PLATFORMCFG "https://github.com/bytedeco/javacpp/tree/master/platform"
    click ROOTPOM "https://github.com/bytedeco/javacpp/blob/master/pom.xml"
    click PLATFORMPOM "https://github.com/bytedeco/javacpp/blob/master/platform/pom.xml"
    click ITPOM "https://github.com/bytedeco/javacpp/blob/master/src/it/osgi/pom.xml"
    click INTEG "https://github.com/bytedeco/javacpp/tree/master/src/it"
    click TRAVIS "https://github.com/bytedeco/javacpp/blob/master/.travis.yml"
    click GITHUB "https://github.com/bytedeco/javacpp/blob/master/.github/workflows/javacpp.yml"
    click PRESETS "https://github.com/bytedeco/javacpp/tree/master/src/main/resources/org/bytedeco/javacpp/properties"
```
