Use this when user provides a Yii2 codebase for analysis or migration planning...
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.