CLI Internals
Architecture
Layer 3: Preprocessor

Layer 3: Blueprint Preprocessor

Dynamic → Static Conversion

The Blueprint Preprocessor handles the "Constitutional Architecture" pattern where blueprints can be functions that generate actions based on configuration.


Purpose

Enable dynamic blueprints that generate different actions based on user configuration.

Traditional (Static) Blueprint:

export default {
  id: 'my-blueprint',
  actions: [
    { type: 'CREATE_FILE', path: 'core.ts' },
    { type: 'CREATE_FILE', path: 'auth.ts' }  // Always created
  ]
};

Dynamic Blueprint:

export default function(config: MergedConfiguration): BlueprintAction[] {
  const actions = [];
  
  // Always add core
  actions.push({ type: 'CREATE_FILE', path: 'core.ts' });
  
  // Conditionally add auth
  if (config.activeFeatures.includes('auth')) {
    actions.push({ type: 'CREATE_FILE', path: 'auth.ts' });
  }
  
  return actions;
}

Benefit: One blueprint handles multiple configurations.


Implementation

// src/core/services/blueprint-preprocessor/blueprint-preprocessor.ts
export class BlueprintPreprocessor {
  async processBlueprint(
    blueprintModule: BlueprintModule,
    mergedConfig: MergedConfiguration
  ): Promise<{ success: boolean; actions: BlueprintAction[] }> {
    
    // Dynamic blueprint (function)
    if (typeof blueprintModule.default === 'function') {
      const actions = blueprintModule.default(mergedConfig);
      return { success: true, actions };
    }
    
    // Static blueprint (object)
    if (blueprintModule.default?.actions) {
      return { success: true, actions: blueprintModule.default.actions };
    }
    
    return { success: false, actions: [], error: 'Invalid blueprint' };
  }
}

Use Case: Conditional Features

// auth blueprint
export default function(config: MergedConfiguration): BlueprintAction[] {
  const actions = [];
  
  // Core auth (always)
  actions.push(
    { type: 'CREATE_FILE', path: 'src/auth/core.ts', template: 'core.ejs' }
  );
  
  // Password reset (optional)
  if (config.activeFeatures.includes('passwordReset')) {
    actions.push(
      { type: 'CREATE_FILE', path: 'src/auth/password-reset.ts', template: 'reset.ejs' }
    );
  }
  
  // MFA (optional)
  if (config.activeFeatures.includes('mfa')) {
    actions.push(
      { type: 'CREATE_FILE', path: 'src/auth/mfa.ts', template: 'mfa.ejs' }
    );
  }
  
  return actions;
}

User genome:

{
  id: 'auth/better-auth',
  features: {
    passwordReset: true,
    mfa: false  // Skip MFA
  }
}

Result: Only core + password-reset actions generated.


Next: Layer 4: Executor →