ADRs/0036 - Namespace refactoring.md
Proposed
Proposed by: Adam Gibson (May 8, 2025)
Discussed with: Paul Dubs
The Deeplearning4j project ecosystem currently utilizes multiple root Java package namespaces, primarily org.nd4j, org.deeplearning4j, and org.datavec, along with existing code under org.eclipse.deeplearning4j, bindings to
external libraries (like FlatBuffers, ONNX, TensorFlow, Python), and various contrib and codegen modules. This distributed namespace structure can make navigation, maintenance, and
understanding component relationships more challenging than necessary.
The goal is to consolidate the core project codebase under a single, unified root namespace: org.eclipse.deeplearning4j. This aligns with the project's stewardship under the Eclipse Foundation and aims to create a clearer,
more consistent, and maintainable structure. Given the project's large scale, an automated refactoring approach using OpenRewrite is optimal for feasibility. This ADR proposes the strategy and
specific rules for this migration.
This is part of a 2 phase release plan where a milestone release that has the old package names is performed followed by the major renamespacing.
This ADR proposes using a comprehensive OpenRewrite recipe to automatically refactor the project's primary Java packages into the org.eclipse.deeplearning4j namespace. The refactoring follows a two-phase conceptual approach:
org.nd4j, org.deeplearning4j, org.datavec) to logical sub-packages under the new root (.nd4j, .dl4jcore, .datavec).org.eclipse.deeplearning4j.ui package.jita and jcublas into .cuda) under org.eclipse.deeplearning4j.nd4j.backend.[type].org.eclipse.deeplearning4j.datavec.*.org.eclipse.deeplearning4j.bindings.*.contrib and codegen modules.common and resources packages (though full consolidation requires further steps).The core of the proposal is the following OpenRewrite YAML recipe, which implements the automated parts of this strategy:
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~# type: org.openrewrite.Recipe name: org.eclipse.deeplearning4j.refactor.NamespaceMigration displayName: Migrate DL4J Project to org.eclipse.deeplearning4j Namespace description: Comprehensive refactoring of core DL4J, ND4J, and DataVec packages under the org.eclipse.deeplearning4j root, including backend consolidation and UI elevation.
recipeList: #--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
org.openrewrite.java.ChangePackage: oldPackageName: org.nd4j # General ND4J code not caught by specific rules above newPackageName: org.eclipse.deeplearning4j.nd4j recursive: true
org.openrewrite.java.ChangePackage: oldPackageName: org.deeplearning4j # General DL4J Core code (excluding UI already handled) newPackageName: org.eclipse.deeplearning4j.dl4jcore recursive: true
org.openrewrite.java.ChangePackage: oldPackageName: org.datavec # General DataVec code newPackageName: org.eclipse.deeplearning4j.datavec recursive: true
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#--------------------------------------------------------------------------#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
org.eclipse.deeplearning4j) for the entire project, aligning with Eclipse Foundation stewardship.org.openrewrite.java.ChangePackage recipe.recipeList and applies more specific package mapping rules before more general ones to handle structural changes like backend separation and UI elevation correctly.ChangePackage Limitations: This recipe primarily uses ChangePackage. Achieving the full Phase 2 vision, especially consolidating classes from multiple old locations into a single new package (e.g., common utilities), may require additional recipes using MoveClass, MovePackage, or custom Java-based recipes after this initial migration.com.google.flatbuffers, onnx.*, tensorflow.*) are intentionally excluded from automated changes due to high risk. Runtime wrappers/runners for these are included in the refactoring.The proposed structure aims for a balance between respecting the original component boundaries (ND4J, DL4J Core, DataVec) and creating a more modern, cohesive structure under the Eclipse Foundation namespace. Key decisions reflected in the proposal:
.nd4j.backend.[type])..ui)..bindings), contrib (.contrib), and codegen (.codegen)..common) and resource management (.resources), acknowledging full consolidation is a subsequent step..dl4jcore to house the bulk of the original org.deeplearning4j code to distinguish it clearly within the new structure.Further discussion within the development team is needed to confirm these target structures and plan the implementation, particularly the steps required beyond the initial automated recipe application for deeper Phase 2 refinements.