Skip to content

Intelligent Template System and Project Analysis for ctx init #240

@butschster

Description

@butschster

Currently, ctx init creates a hardcoded configuration with a fixed src directory structure. This requires manual customization for different project types and frameworks, creating friction for new users and inconsistent setups across teams.

// Current hardcoded approach in InitCommand.php
firstSource: new TreeSource(
    sourcePaths: ['src'], // Always 'src' - not flexible
    treeView: new TreeViewConfig(
        showCharCount: true,
    ),
),

Proposed Solution

Transform ctx init into an intelligent system supporting:

  1. Template-based initialization: ctx init laravel using predefined templates
  2. Smart project analysis: ctx init with automatic project type detection

Core Components

Template Configuration Format (YAML):

# templates/laravel.yaml
name: "Laravel"
description: "Laravel PHP Framework project template"
tags: ["php", "laravel", "web", "framework"]
priority: 10
detection:
  files: ["composer.json", "artisan"]
  patterns: ["laravel/framework"]
documents:
  - description: "Laravel Application Overview"
    outputPath: "docs/laravel-overview.md"
    sources:
      - type: tree
        sourcePaths: ["app", "database", "routes", "config"]
      - type: file
        sourcePaths: ["app/Http/Controllers", "app/Models"]
        filePattern: "*.php"
        modifiers: ["php-signature"]

Smart Project Analysis:

  • ComposerAnalyzer: Detects Laravel/Symfony/other PHP frameworks
  • PackageJsonAnalyzer: Detects React/Vue/Node.js projects
  • DirectoryStructureAnalyzer: Fallback based on folder patterns
  • GitAnalyzer: Analyzes .gitignore and repository patterns

Command Usage Examples

# List available templates
ctx init --list-templates

# Use specific template  
ctx init laravel
ctx init react
ctx init --template=symfony

# Smart analysis mode (default)
ctx init
# Output: "Detected Laravel project (95% confidence)
#          Use Laravel template? [Y/n]"

Built-in Templates

Initial templates to include:

  • laravel - Laravel PHP framework
  • symfony - Symfony PHP framework
  • react - React.js application
  • vue - Vue.js application
  • spiral - Spiral PHP framework
  • generic-php - Generic PHP project
  • generic-node - Generic Node.js project

Benefits

  • Zero Configuration: Works out-of-the-box for common project types
  • Consistent Structure: Standardized context generation across teams
  • Extensible: Easy to add new templates and analyzers via bootloader system
  • Educational: Users learn best practices through templates
  • Framework Integration: Follows existing CTX patterns (Registry, Factory, Bootloader)

Metadata

Metadata

Assignees

Labels

console:cliConsole commands and CLI interfaceenhancementNew feature or request

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions