Chahuadev-smart-roadmap / src /analyzers /phase-analyzer.js
chahuadev's picture
Upload 74 files
4fea3ee verified
/**
* PhaseAnalyzer - Detects and tracks project phases with detailed status
* Generates phase-based roadmaps with checkboxes, dependencies, and completion tracking
*/
class PhaseAnalyzer {
constructor() {
this.version = '1.0.0';
}
/**
* Analyze project phases from task data
* @param {Array} tasks - All tasks from analysis
* @param {Array} files - All files from analysis
* @returns {Object} Phase analysis
*/
analyze(tasks, files) {
const phases = this.identifyPhases(tasks, files);
const dependencies = this.analyzeDependencies(phases);
const timeline = this.estimateTimeline(phases);
const completionMetrics = this.calculatePhaseCompletion(phases);
return {
phases,
dependencies,
timeline,
completionMetrics,
summary: this.generatePhaseSummary(phases)
};
}
/**
* Identify phases from tasks and files
* @param {Array} tasks - All tasks
* @param {Array} files - All files
* @returns {Array} Phases with tasks
*/
identifyPhases(tasks, files) {
const phases = [];
// Phase 1: Setup & Infrastructure
phases.push({
id: 1,
name: 'Setup & Infrastructure',
description: 'Establish project foundation, configuration, and dependencies',
status: this.determinePhaseStatus(tasks, ['setup', 'config', 'infrastructure']),
tasks: tasks.filter(t => this.isSetupTask(t)),
estimatedDays: 3,
priority: 'HIGH',
blockers: []
});
// Phase 2: Core Implementation
phases.push({
id: 2,
name: 'Core Implementation',
description: 'Implement main business logic and core features',
status: this.determinePhaseStatus(tasks, ['implementation', 'feature', 'core']),
tasks: tasks.filter(t => this.isCoreTask(t)),
estimatedDays: 10,
priority: 'CRITICAL',
blockers: ['Phase 1']
});
// Phase 3: Testing & Quality Assurance
phases.push({
id: 3,
name: 'Testing & Quality Assurance',
description: 'Comprehensive testing, bug fixes, and quality improvements',
status: this.determinePhaseStatus(tasks, ['test', 'quality', 'bug']),
tasks: tasks.filter(t => this.isTestingTask(t)),
estimatedDays: 5,
priority: 'HIGH',
blockers: ['Phase 2']
});
// Phase 4: Documentation & Polish
phases.push({
id: 4,
name: 'Documentation & Polish',
description: 'Write documentation, refine UI, and prepare for release',
status: this.determinePhaseStatus(tasks, ['documentation', 'docs', 'polish']),
tasks: tasks.filter(t => this.isDocumentationTask(t)),
estimatedDays: 3,
priority: 'MEDIUM',
blockers: ['Phase 3']
});
// Phase 5: Migration & Refactoring (if applicable)
const migrationTasks = tasks.filter(t => this.isMigrationTask(t));
if (migrationTasks.length > 0) {
phases.push({
id: 5,
name: 'Migration & Refactoring',
description: 'System-wide migration, refactoring, and modernization',
status: this.determinePhaseStatus(tasks, ['migration', 'refactor', 'modernize']),
tasks: migrationTasks,
estimatedDays: 7,
priority: 'HIGH',
blockers: ['Phase 2']
});
}
// Phase 6: Security & Performance
const securityTasks = tasks.filter(t => this.isSecurityTask(t));
if (securityTasks.length > 0) {
phases.push({
id: 6,
name: 'Security & Performance',
description: 'Security hardening, performance optimization, and auditing',
status: this.determinePhaseStatus(tasks, ['security', 'performance', 'optimization']),
tasks: securityTasks,
estimatedDays: 5,
priority: 'CRITICAL',
blockers: ['Phase 3']
});
}
return phases;
}
/**
* Determine phase status based on tasks
* @param {Array} tasks - All tasks
* @param {Array} keywords - Keywords for this phase
* @returns {string} Phase status
*/
determinePhaseStatus(tasks, keywords) {
const phaseTasks = tasks.filter(t => {
const text = `${t.title} ${t.message} ${t.type}`.toLowerCase();
return keywords.some(kw => text.includes(kw));
});
if (phaseTasks.length === 0) return 'NOT_STARTED';
const completed = phaseTasks.filter(t => t.completed).length;
const total = phaseTasks.length;
const percentage = (completed / total) * 100;
if (percentage === 100) return 'COMPLETED';
if (percentage >= 50) return 'IN_PROGRESS';
if (percentage > 0) return 'STARTED';
return 'NOT_STARTED';
}
/**
* Check if task is setup-related
*/
isSetupTask(task) {
const text = `${task.title} ${task.message} ${task.type}`.toLowerCase();
return text.includes('setup') ||
text.includes('config') ||
text.includes('install') ||
text.includes('initialize') ||
text.includes('package.json') ||
text.includes('dependency');
}
/**
* Check if task is core implementation
*/
isCoreTask(task) {
const text = `${task.title} ${task.message} ${task.type}`.toLowerCase();
return text.includes('implement') ||
text.includes('feature') ||
text.includes('function') ||
text.includes('class') ||
text.includes('module') ||
(task.type === 'quality' && !text.includes('test'));
}
/**
* Check if task is testing-related
*/
isTestingTask(task) {
const text = `${task.title} ${task.message} ${task.type}`.toLowerCase();
return text.includes('test') ||
text.includes('bug') ||
text.includes('fix') ||
text.includes('coverage') ||
text.includes('quality');
}
/**
* Check if task is documentation-related
*/
isDocumentationTask(task) {
const text = `${task.title} ${task.message} ${task.type}`.toLowerCase();
return text.includes('doc') ||
text.includes('readme') ||
text.includes('comment') ||
text.includes('polish') ||
text.includes('ui') ||
text.includes('ux');
}
/**
* Check if task is migration-related
*/
isMigrationTask(task) {
const text = `${task.title} ${task.message} ${task.type}`.toLowerCase();
return text.includes('migrat') ||
text.includes('refactor') ||
text.includes('moderniz') ||
text.includes('upgrade') ||
text.includes('convert');
}
/**
* Check if task is security-related
*/
isSecurityTask(task) {
const text = `${task.title} ${task.message} ${task.type}`.toLowerCase();
return task.type === 'security' ||
text.includes('security') ||
text.includes('vulnerab') ||
text.includes('performance') ||
text.includes('optimiz');
}
/**
* Analyze dependencies between phases
* @param {Array} phases - All phases
* @returns {Object} Dependency graph
*/
analyzeDependencies(phases) {
const graph = {};
phases.forEach(phase => {
graph[phase.name] = {
dependsOn: phase.blockers || [],
blockedBy: phases
.filter(p => (p.blockers || []).includes(`Phase ${phase.id}`))
.map(p => p.name)
};
});
return graph;
}
/**
* Estimate timeline for phases
* @param {Array} phases - All phases
* @returns {Object} Timeline estimate
*/
estimateTimeline(phases) {
const today = new Date();
let currentDate = new Date(today);
const schedule = [];
phases.forEach(phase => {
const startDate = new Date(currentDate);
currentDate.setDate(currentDate.getDate() + phase.estimatedDays);
const endDate = new Date(currentDate);
schedule.push({
phase: phase.name,
startDate: startDate.toISOString().split('T')[0],
endDate: endDate.toISOString().split('T')[0],
duration: phase.estimatedDays,
status: phase.status
});
});
const totalDays = phases.reduce((sum, p) => sum + p.estimatedDays, 0);
const completionDate = new Date(today);
completionDate.setDate(completionDate.getDate() + totalDays);
return {
schedule,
totalDays,
estimatedCompletion: completionDate.toISOString().split('T')[0]
};
}
/**
* Calculate phase completion metrics
* @param {Array} phases - All phases
* @returns {Object} Completion metrics
*/
calculatePhaseCompletion(phases) {
const metrics = {
totalPhases: phases.length,
completed: phases.filter(p => p.status === 'COMPLETED').length,
inProgress: phases.filter(p => p.status === 'IN_PROGRESS' || p.status === 'STARTED').length,
notStarted: phases.filter(p => p.status === 'NOT_STARTED').length
};
metrics.completionPercentage = Math.round((metrics.completed / metrics.totalPhases) * 100);
return metrics;
}
/**
* Generate phase summary
* @param {Array} phases - All phases
* @returns {Object} Summary
*/
generatePhaseSummary(phases) {
return {
totalPhases: phases.length,
criticalPhases: phases.filter(p => p.priority === 'CRITICAL').length,
totalTasks: phases.reduce((sum, p) => sum + p.tasks.length, 0),
totalDays: phases.reduce((sum, p) => sum + p.estimatedDays, 0),
currentPhase: phases.find(p => p.status === 'IN_PROGRESS' || p.status === 'STARTED')?.name || 'Not Started'
};
}
}
module.exports = PhaseAnalyzer;