V2 Execution Flow
Understanding how V2 executes projects from V2Genome to generated code.
Overview
V2 execution follows a strict order:
V2Genome
↓
Marketplace Transformation (transformGenome)
↓
StandardizedGenome
↓
Path Mapping Generation
↓
Framework Bootstrap
↓
Module Execution
↓
Generated ProjectPhase 1: Marketplace Transformation
What Happens:
- CLI loads marketplaces from V2Genome
- CLI calls
marketplaceAdapter.transformGenome() - Marketplace expands packages → modules using recipe book
- Marketplace resolves dependencies
- Marketplace generates lock file
- Marketplace returns StandardizedGenome
Key Components:
CompositionEngine: Expands packages, resolves dependenciesRecipeExpander: Maps packages to modulesDependencyResolver: Resolves module prerequisitesLockFileService: Generates lock file
Output: StandardizedGenome with:
modules: Array of modules to executemetadata.executionPlan: Execution ordermetadata.moduleIndex: Module metadata
Phase 2: Path Mapping Generation
What Happens:
- Load path keys from marketplaces
- Generate path mappings for all path keys
- Compute paths for apps/packages (even if not created yet)
- Store paths in PathService
Key Components:
PathMappingGenerator: Generates all path mappingsPathService: Stores and resolves paths
Why First?
- Frameworks need paths during bootstrap
- Paths must be available before any file creation
- Prevents path resolution errors
Example:
// Path keys defined in path-keys.json
'apps.web.root' → 'apps/web/'
'apps.web.src' → 'apps/web/src/'
'packages.auth.root' → 'packages/auth/'
// Generated before framework bootstrap
paths['apps.web.root'] = 'apps/web/'
paths['apps.web.src'] = 'apps/web/src/'Phase 3: Framework Bootstrap
What Happens:
- Identify framework modules (via metadata)
- For each app with a framework:
- Create VFS with app directory as root
- Execute framework blueprint
- Run framework CLI (create-next-app, create-expo-app, etc.)
- Framework modules execute only during bootstrap
Key Components:
ProjectBootstrapService: Orchestrates framework bootstrapVirtualFileSystem: Manages file operationsBlueprintExecutor: Executes framework blueprints
Path Resolution:
- VFS root = app directory (e.g.,
apps/web) - Paths resolve relative to VFS root (
./notapps/web/) - Prevents nested directories
Example:
// Framework: nextjs for web app
// VFS root: /project/apps/web
// Path resolution: paths.apps.web.root → './'
// Command: npx create-next-app@latest . (runs in apps/web)Phase 4: Module Execution
What Happens:
- Filter out framework modules (already executed)
- Execute regular modules in dependency order
- Each module:
- Loads blueprint
- Creates VFS (if needed)
- Executes blueprint actions
- Flushes VFS to disk
Key Components:
OrchestratorAgent: Coordinates executionModuleService: Loads modules and adaptersBlueprintExecutor: Executes blueprintsVirtualFileSystem: Manages file operations
Execution Order:
- Based on
metadata.executionPlan - Respects module prerequisites
- Framework modules filtered out
Detailed Flow
Step 1: Load V2Genome
const genome = await loadGenome('genome.ts');
// genome is V2Genome formatStep 2: Transform to StandardizedGenome
const standardizedGenome = await marketplaceAdapter.transformGenome(
genome,
options,
context
);
// standardizedGenome is StandardizedGenome formatStep 3: Generate Path Mappings
const pathMappings = await PathMappingGenerator.generateMappings(
standardizedGenome,
marketplaceAdapters,
recipeBooks
);
// All path keys now availableStep 4: Bootstrap Frameworks
const frameworkConfig = await projectBootstrapService.bootstrap(
standardizedGenome,
structureResult,
marketplaceAdapters,
recipeBooks
);
// Frameworks initialized (Next.js, Expo, Hono)Step 5: Execute Modules
const regularModules = standardizedGenome.modules.filter(
mod => !isFrameworkModule(mod, standardizedGenome)
);
for (const module of regularModules) {
await orchestrator.executeModule(module, standardizedGenome);
}
// All modules executedExecution Context
Framework Bootstrap Context
{
projectRoot: '/project/apps/web', // VFS root = app directory
paths: {
'apps.web.root': './', // Relative to VFS root
'apps.web.src': './src/'
},
targetApp: 'web'
}Module Execution Context
{
projectRoot: '/project', // VFS root = project root
paths: {
'apps.web.root': 'apps/web/', // Absolute from project root
'packages.auth.root': 'packages/auth/'
},
targetPackage: 'auth' // For package modules
}Key Differences from V1
| Aspect | V1 | V2 |
|---|---|---|
| Genome Format | Genome (modules array) | V2Genome (packages/apps) |
| Transformation | CLI handles | Marketplace handles |
| Structure | Single-app or monorepo | Monorepo only |
| Framework Handling | Mixed with modules | Bootstrap first |
| Path Resolution | Simple | Semantic path keys |
Troubleshooting
Framework not bootstrapping
Check:
- Framework module detected? (metadata.type === 'framework')
- VFS root correct? (should be app directory)
- Paths available? (generated before bootstrap)
Modules executing in wrong order
Check:
- Execution plan correct? (from lock file)
- Prerequisites resolved? (dependency graph)
- Framework modules filtered? (should not execute twice)
Path resolution errors
Check:
- Path keys loaded? (from marketplace)
- Paths generated? (before bootstrap)
- Path resolution correct? (relative vs absolute)
Related
- Framework Bootstrap - Detailed bootstrap process
- V2Genome Structure - V2Genome format
- Marketplace-CLI Relationship - How transformation works