v2
Core Concepts
Marketplace-CLI Relationship

Marketplace-CLI Relationship

V2 introduces a clear separation between marketplaces (opinionated) and CLI (generic). Marketplaces transform genomes; the CLI executes them.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   V2Genome      β”‚  User defines business-level packages/apps
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Marketplace    β”‚  Transforms V2Genome β†’ StandardizedGenome
β”‚  Adapter        β”‚  - Loads recipe books
β”‚  transformGenomeβ”‚  - Expands packages β†’ modules
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜  - Resolves dependencies
         β”‚           - Creates lock file
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ StandardizedGenomeβ”‚  Unified format for CLI
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      CLI        β”‚  Executes StandardizedGenome
β”‚  Orchestrator   β”‚  - Framework bootstrap
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  - Module execution

Marketplace Responsibilities

1. Load Recipe Books

Recipe books map business packages β†’ technical modules:

{
  "packages": {
    "auth": {
      "providers": {
        "default": {
          "modules": [
            { "id": "capabilities/auth", "targetPackage": "auth" }
          ]
        }
      }
    }
  }
}

2. Transform Genome

Marketplace adapter's transformGenome() method:

  1. Expands packages into modules using recipe book
  2. Resolves dependencies using prerequisites
  3. Generates lock file for reproducible builds
  4. Returns StandardizedGenome ready for CLI execution
async transformGenome(genome: V2Genome, options, context) {
  // 1. Load recipe books
  const recipeBooks = await this.loadRecipeBooks(genome);
  
  // 2. Use CompositionEngine to resolve
  const handler = new context.V2GenomeHandler(
    context.marketplaceAdapters,
    context.logger,
    context.projectRoot
  );
  
  // 3. Resolve to lock file
  const lockFile = await handler.resolveGenome(genome, context.projectRoot);
  
  // 4. Convert to StandardizedGenome
  return handler.convertLockFileToResolvedGenome(
    lockFile,
    genome,
    context.genomeFilePath
  );
}

3. Provide Path Defaults

Marketplaces provide default path values:

async resolvePathDefaults(context) {
  return {
    'apps.web.root': 'apps/web/',
    'apps.web.src': 'apps/web/src/',
    'packages.auth.root': 'packages/auth/',
    // ...
  };
}

CLI Responsibilities

1. Load Marketplaces

CLI loads marketplaces specified in V2Genome:

const marketplaces = genome.marketplaces;
for (const [name, config] of Object.entries(marketplaces)) {
  const adapter = await loadMarketplaceAdapter(name, config);
  marketplaceAdapters.set(name, adapter);
}

2. Call transformGenome()

CLI calls marketplace adapter's transformGenome():

const standardizedGenome = await marketplaceAdapter.transformGenome(
  genome,
  options,
  {
    marketplaceAdapters,
    logger,
    projectRoot,
    V2GenomeHandler,
    CompositionEngine
  }
);

3. Execute StandardizedGenome

CLI executes the standardized genome:

  1. Path mapping generation
  2. Framework bootstrap
  3. Module execution

Key Principles

1. CLI is Generic

The CLI does not know about:

  • Package β†’ Module mappings (handled by recipe books)
  • Framework detection (handled by metadata)
  • Path resolution (handled by path keys)

Result: CLI works with any marketplace structure.

2. Marketplaces are Opinionated

Marketplaces define:

  • Which modules are available
  • How packages map to modules
  • What paths are available
  • Framework compatibility

Result: Different marketplaces can have different opinions.

3. StandardizedGenome is the Contract

Both CLI and marketplaces agree on StandardizedGenome:

interface StandardizedGenome {
  project: { name, structure, ... };
  modules: Module[];
  metadata: { moduleIndex, executionPlan, ... };
  // Optional: V2 structure preserved
  packages?: Record<string, PackageConfig>;
  apps?: Record<string, AppConfig>;
}

Result: CLI can execute any StandardizedGenome, regardless of source.

Example Flow

1. User Creates V2Genome

{
  packages: { auth: {} },
  apps: { web: { framework: 'nextjs', packages: ['auth'] } }
}

2. Marketplace Transforms

// Marketplace loads recipe book
recipeBook.packages.auth β†’ capabilities/auth module
 
// Marketplace expands
packages.auth β†’ capabilities/auth β†’ packages/auth/
 
// Marketplace resolves
apps.web.framework β†’ capabilities/nextjs β†’ apps/web/
 
// Marketplace creates lock file
{
  executionPlan: ['capabilities/nextjs', 'capabilities/auth'],
  modules: [...]
}

3. CLI Executes

// CLI receives StandardizedGenome
{
  modules: [
    { id: 'capabilities/nextjs', ... },
    { id: 'capabilities/auth', ... }
  ],
  metadata: {
    executionPlan: ['capabilities/nextjs', 'capabilities/auth']
  }
}
 
// CLI executes
1. Bootstrap: capabilities/nextjs β†’ apps/web/
2. Execute: capabilities/auth β†’ packages/auth/

Benefits

  1. Separation of Concerns: Marketplaces handle business logic, CLI handles execution
  2. Flexibility: Different marketplaces can have different structures
  3. Reusability: CLI works with any marketplace
  4. Type Safety: StandardizedGenome provides consistent interface

Related