ADR-050: Hierarchical Command Structure

Status: Proposed Date: 2025-12-11 Deciders: CloudEmpiere Technical Team Related: ADR-049 (Project Rebranding)


Context

The current iDempiere AI Hub (v1.59.0) has a flat command structure that has grown organically:

idempiere-cli gen model
idempiere-cli gen process
idempiere-cli dict add table
idempiere-cli pack out
idempiere-cli rag search
idempiere-cli server mcp

Problems with current structure:

  1. Poor Discoverability - Commands don't group logically
  2. Inconsistent Naming - gen, dict, pack, rag lack pattern
  3. Limited Scalability - Hard to add new commands without confusion
  4. Tab Completion Pollution - All commands at same level
  5. Not User-Friendly - Users must memorize unrelated command names

Analysis from vision documents (idempiere-ai-cli-architecture.md) proposes a superior hierarchical structure that groups related commands:

idempiere-cli app generate
idempiere-cli model generate
idempiere-cli metamodel generate
idempiere-cli plugin scaffold
idempiere-cli knowledge query

We must decide: Keep flat structure or adopt hierarchical grouping?


Decision

Adopt hierarchical command structure organized by functional domain, with backward-compatible aliases for existing commands.

New Command Structure (v1.60+):

idempiere-cli
├── app                    # Application generation
│   └── generate          # Full application from requirements
│
├── model                  # Java model generation
│   └── generate          # Generate I_, X_, M_ classes
│
├── metamodel             # Database schema & AD
│   ├── create            # Create new tables (AI-assisted)
│   ├── generate          # Generate from requirements (AI-driven)
│   ├── export            # Export to 2Pack/SQL
│   ├── import            # Import from 2Pack
│   └── sync              # Synchronize AD to database
│
├── code                  # Code generation
│   ├── process           # Generate process class
│   ├── callout           # Generate callout class
│   ├── form              # Generate form class
│   └── validator         # Generate model validator
│
├── plugin                # Plugin scaffolding
│   ├── scaffold          # Create complete plugin structure
│   └── validate          # Validate plugin structure
│
├── knowledge             # Knowledge base operations
│   ├── query             # Semantic search
│   ├── search            # Hybrid search
│   ├── index             # Index documents
│   └── stats             # Knowledge base statistics
│
├── registry              # Application Dictionary registry
│   ├── search            # Smart search (SQL/semantic)
│   ├── list              # List entities (tables, windows, etc.)
│   └── describe          # Describe entity
│
├── db                    # Database operations
│   ├── analyze           # Analyze schema
│   ├── query             # Execute SQL queries
│   └── migration         # Create migration scripts
│
├── server                # Server modes
│   ├── mcp               # MCP server (port 8765)
│   └── chat-api          # Chat API (port 8081)
│
└── dev                   # Developer utilities
    ├── doctor            # Environment health check
    ├── config            # Configuration management
    └── demo              # Demo/test commands

Migration Strategy:

  1. Phase 1 (v1.60): Implement new structure, add aliases
  2. Phase 2 (v1.61-1.65): Deprecation warnings on old commands
  3. Phase 3 (v2.0): Remove aliases, new structure only

Rationale

Why Hierarchical?

1. Better Organization

# OLD - Unclear relationships
idempiere-cli gen model
idempiere-cli gen process
idempiere-cli gen callout

# NEW - Clear grouping
idempiere-cli code process
idempiere-cli code callout
idempiere-cli model generate

2. Improved Discoverability

# User explores naturally
idempiere-cli model --help
  Commands:
    generate    Generate Java model classes

idempiere-cli metamodel --help
  Commands:
    create      Create new table in AD
    generate    Generate from AI requirements
    export      Export to 2Pack/SQL

3. Better Tab Completion

# OLD - All commands at once (overwhelming)
idempiere-cli <TAB>
  gen  dict  pack  rag  server  dev  registry  mig

# NEW - Grouped exploration
idempiere-cli <TAB>
  app  model  metamodel  code  plugin  knowledge  registry  db  server  dev

idempiere-cli model <TAB>
  generate

4. Scalability

# Easy to add new commands without confusion
idempiere-cli code <TAB>
  process  callout  form  validator  docaction  interceptor  # NEW

5. Industry Standard

# Follows patterns from successful CLIs
docker container ls
kubectl get pods
git remote add
aws s3 ls
npm run build

Why Backward Compatible?

Reasoning:

Alias Strategy:

# OLD command (deprecated, aliased)
idempiere-cli gen model XX_Table
# ⚠️  WARNING: 'gen model' is deprecated, use 'model generate' instead

# NEW command (preferred)
idempiere-cli model generate XX_Table

Implementation

Picocli Structure

@Command(
    name = "idempiere-cli",
    description = "iDempiere AI Hub - CLI, MCP Server, and Chat API",
    subcommands = {
        AppCommands.class,
        ModelCommands.class,
        MetamodelCommands.class,
        CodeCommands.class,
        PluginCommands.class,
        KnowledgeCommands.class,
        RegistryCommands.class,
        DatabaseCommands.class,
        ServerCommands.class,
        DevCommands.class,

        // Deprecated aliases (to be removed in v2.0)
        GenCommands.class,       // @Deprecated
        DictCommands.class,      // @Deprecated
        PackCommands.class,      // @Deprecated
        RagCommands.class,       // @Deprecated
        MigCommands.class        // @Deprecated
    }
)
public class IdempiereCli {
    // ...
}

Example: Model Commands

@Command(
    name = "model",
    description = "Java model class generation",
    subcommands = {
        ModelGenerateCommand.class
    }
)
public class ModelCommands {
    // Parent command, delegates to subcommands
}

@Command(
    name = "generate",
    description = "Generate Java model classes (I_, X_, M_) from database table"
)
public class ModelGenerateCommand implements Callable<Integer> {

    @Parameters(description = "Table name (e.g., XX_MyTable)")
    String tableName;

    @Option(names = {"-p", "--package"}, description = "Java package name")
    String packageName;

    @Option(names = {"-o", "--output"}, description = "Output directory")
    Path outputDir;

    @Override
    public Integer call() {
        // Implementation
        return 0;
    }
}

Alias Implementation

@Command(
    name = "gen",
    description = "Code generation (DEPRECATED: use 'model', 'code', or 'plugin' instead)",
    subcommands = {
        GenModelCommand.class,    // Alias to ModelGenerateCommand
        GenProcessCommand.class,  // Alias to CodeProcessCommand
        GenCalloutCommand.class   // Alias to CodeCalloutCommand
    }
)
@Deprecated(since = "1.60", forRemoval = true)
public class GenCommands {

    @Spec CommandSpec spec;

    @Override
    public Integer call() {
        System.err.println("⚠️  WARNING: 'gen' command is deprecated.");
        System.err.println("   Use specific commands instead:");
        System.err.println("     gen model    → model generate");
        System.err.println("     gen process  → code process");
        System.err.println("     gen callout  → code callout");
        return 0;
    }
}

Help Text

$ idempiere-cli --help

Usage: idempiere-cli [COMMAND]

iDempiere AI Hub - CLI, MCP Server, and Chat API

Commands:
  app         Application generation from requirements
  model       Java model class generation
  metamodel   Database schema and Application Dictionary
  code        Code generation (processes, callouts, forms)
  plugin      Plugin scaffolding and validation
  knowledge   Knowledge base operations (RAG)
  registry    Application Dictionary registry
  db          Database operations
  server      Server modes (MCP, Chat API)
  dev         Developer utilities

Deprecated (use alternatives above):
  gen         → Use 'model', 'code', or 'plugin'
  dict        → Use 'metamodel' or 'registry'
  pack        → Use 'metamodel export/import'
  rag         → Use 'knowledge'
  mig         → Use 'db migration'

Run 'idempiere-cli COMMAND --help' for more information.

Consequences

Positive

  1. Better User Experience

    • Intuitive command discovery
    • Logical grouping reduces cognitive load
    • Tab completion becomes useful
  2. Scalability

    • Easy to add new commands without confusion
    • Clear namespace for each domain
    • Subcommands can have subcommands
  3. Consistency

    • Follows industry standards (docker, kubectl, git)
    • Predictable command patterns
    • Clear command hierarchy
  4. Documentation

    • Easier to document (organized by domain)
    • Help text is hierarchical
    • Examples are clearer
  5. MCP Integration

    • Tool names map naturally to commands
    • model_generate → idempiere-cli model generate
    • Better API surface for AI assistants

Negative

  1. Migration Effort

    • Need to create new command classes
    • Update all documentation
    • Communicate changes to users
    • Maintain aliases during transition
  2. Verbosity

    • Commands are longer
    • More typing for users
    • Offset by: tab completion, aliases
  3. Breaking Change (v2.0)

    • Eventually remove aliases
    • Users must update scripts
    • Mitigation: 6+ month deprecation period
  4. Implementation Complexity

    • More command classes
    • Alias routing logic
    • Deprecation warnings
    • Mitigation: Well-structured codebase

Alternatives Considered

Alternative 1: Keep Flat Structure

Pros:

Cons:

Decision: ❌ Rejected - Technical debt will grow

Alternative 2: Complete Rewrite (No Aliases)

Pros:

Cons:

Decision: ❌ Rejected - Too disruptive

Alternative 3: Namespaced Flat Commands

# Example
idempiere-cli model:generate
idempiere-cli code:process
idempiere-cli metamodel:create

Pros:

Cons:

Decision: ❌ Rejected - Doesn't follow industry standards

Alternative 4: Hybrid Approach (Selected)

✅ Hierarchical structure + backward-compatible aliases + gradual migration

Balances all concerns:


Migration Plan

Phase 1: v1.60 (Q1 2025) - Implement New Structure

Week 1-2: Core Implementation

Week 3: MCP Integration

Week 4: Documentation

Week 5: Testing

Phase 2: v1.61-1.65 (Q2 2025) - Deprecation Period

v1.61:

v1.62-1.65:

Phase 3: v2.0 (Q3 2025) - Remove Aliases

Pre-release:

v2.0.0:


Command Mapping Reference

Old Command New Command Alias Until
gen model model generate v2.0
gen process code process v2.0
gen callout code callout v2.0
gen plugin plugin scaffold v2.0
dict add table metamodel create v2.0
dict list tables registry list tables v2.0
dict describe table registry describe table v2.0
pack out metamodel export v2.0
pack in metamodel import v2.0
rag search knowledge search v2.0
rag ingest knowledge index v2.0
mig create db migration create v2.0

Success Metrics

Track via observability:

  1. Command Usage

    • New commands: % of total executions
    • Old commands: % of total executions
    • Target: 80%+ new commands by v1.65
  2. User Feedback

    • GitHub issues/discussions
    • Survey results
    • Support tickets
  3. Tab Completion Usage

    • Track via shell hooks (if user consents)
    • Measure discoverability improvement
  4. Documentation Views

    • Migration guide views
    • Command help usage
    • Example code copies

ADRs:

Vision Documents:

Implementation:


References

Industry Examples:

Design Principles:


Decision

Approved: [Pending] By: [CloudEmpiere Technical Team] Date: [TBD]


Document Status: Proposed Next Review: After team discussion Implementation Target: v1.60 (Q1 2025)

Path: /docs/developers/architecture/idempiere-hub/050-command-restructuring-hierarchical