// "Use this when user provides a Yii2 codebase for analysis or migration planning. Provides 6-phase workflow: scan, capability extraction, dependency analysis, requirements extraction, semantic indexing, and migration roadmap. Apply when user mentions Yii2, PHP legacy modernization, or framework migration to NestJS"
| name | analyze-yii2-project |
| description | Use this when user provides a Yii2 codebase for analysis or migration planning. Provides 6-phase workflow: scan, capability extraction, dependency analysis, requirements extraction, semantic indexing, and migration roadmap. Apply when user mentions Yii2, PHP legacy modernization, or framework migration to NestJS |
| categories | ["workflow","analysis","yii2","migration"] |
| tags | ["yii2","php","legacy","modernization","framework-migration"] |
| version | 1.0.0 |
Comprehensive workflow for analyzing legacy Yii2 projects to extract business logic, understand architecture, and plan modernization.
codecompass health
Verify:
vendor/ directory present (run composer install if missing)Step 1.1: Run Yii2 Analyzer
codecompass analyze:yii2 <path-to-yii2-project>
What this does:
Expected output:
Step 1.2: Validate Results Check for:
vendor/ โ Run composer installdocs/YII2_QUICK_REFERENCE.mdStep 2.1: Extract Controllers โ Capabilities
# Analyzer automatically extracts business capabilities from controllers
What this maps:
Controller โ Business Capability
โโโ UserController โ User Management
โโโ OrderController โ Order Processing
โโโ PaymentController โ Payment Handling
โโโ ReportController โ Reporting & Analytics
Step 2.2: Extract Models โ Domain Entities Identifies:
Step 2.3: Extract Migrations โ Data Model Evolution Traces:
Step 3.1: Analyze Class Dependencies
Uses: AstAnalyzerService for PHP parsing
Maps:
Step 3.2: Identify Core vs Supporting Logic Categorizes:
Step 4.1: Run Requirements Extractor
codecompass requirements:extract --project-id <yii2-project-id>
Extracts:
Step 4.2: Generate Documentation Outputs:
Step 5.1: Index Codebase
codecompass batch:index <path-to-yii2-project>
Why:
Step 5.2: Verify Indexing
curl http://localhost:8081/v1/schema
# Check for CodeContext or AtlasCode collection
Step 5.3: Test Semantic Search
codecompass search:semantic "validation rules for customer registration"
Should return: User model validators, controller logic, related code
Step 6.1: Identify Migration Complexity Assess:
Step 6.2: Prioritize by Business Value Map:
Business Capability โ Migration Priority
โโโ Core Revenue Generating โ HIGH (do first, carefully)
โโโ Customer-Facing โ MEDIUM (visible impact)
โโโ Internal Tools โ LOW (can defer)
Step 6.3: Generate Migration Roadmap Structure:
// CRUD pattern
public function actionIndex() // โ LIST endpoint
public function actionView($id) // โ GET/:id endpoint
public function actionCreate() // โ POST endpoint
public function actionUpdate($id) // โ PUT/:id endpoint
public function actionDelete($id) // โ DELETE/:id endpoint
Maps to NestJS:
@Controller('users')
export class UsersController {
@Get() findAll()
@Get(':id') findOne()
@Post() create()
@Put(':id') update()
@Delete(':id') remove()
}
// Validation rules
public function rules() {
return [
[['email'], 'required'],
[['email'], 'email'],
];
}
Maps to NestJS DTO:
export class CreateUserDto {
@IsNotEmpty()
@IsEmail()
email: string;
}
// ActiveRecord query
$users = User::find()
->where(['status' => User::STATUS_ACTIVE])
->orderBy('created_at DESC')
->all();
Maps to TypeORM:
const users = await this.userRepository.find({
where: { status: UserStatus.ACTIVE },
order: { createdAt: 'DESC' },
});
graph TD
Controller[Controllers] --> Service[Business Logic]
Service --> Model[ActiveRecord Models]
Model --> DB[(Database)]
Controller --> View[Views]
## Core Capabilities
- User Management (UserController, User model)
- Order Processing (OrderController, Order/OrderItem models)
- Payment Handling (PaymentController, Payment model)
## Supporting Capabilities
- Reporting (ReportController)
- Notifications (EmailService)
Symptom: Analyzer reports 0 controllers
Cause: Non-standard directory structure
Solution: Check @app alias configuration in Yii2, adjust paths
Symptom: Cannot extract models properly Cause: Database not accessible or migrations not run Solution: Ensure database connection configured, run pending migrations
Symptom: Dependency graph shows circular references Meaning: Code smell - tight coupling between modules Action: Plan refactoring to break cycles during migration
Symptom: Complex logic in controllers with no comments Action:
extract-requirements.md - For detailed requirements extractionsemantic-search.md - For code explorationsoftware-architect.md - For architecture perspectiveFrom .ai/capabilities.json:
yii2-analyzer - Main analysis moduleast-analyzer - PHP parsingdatabase-analyzer - Schema extractionrequirements - Business rules extractionbusiness-analyzer - Capability mappingRemember: The goal is not just to understand the code, but to preserve the business knowledge embedded in it.