Kind: Service
Source: atloria-monorepo/apps/code-analyzer/src/app/analysis/analysis.service.ts
Analysis orchestrator service
This service coordinates the entire code analysis pipeline:
- Clone repository (with mono-repo support)
- Analyze codebase using file optimization techniques
- Generate UI documentation and element extraction
- Create Playwright tests
- Track progress in database
- Cleanup after completion
AnalysisService orchestrates the end-to-end repository analysis workflow for the code analyzer application. It coordinates repository cloning (including monorepos), optimized code analysis, UI documentation and element extraction, Playwright test generation, database-backed progress tracking, and cleanup once processing completes.
Methods
| Method | Signature | Returns | Description |
|---|---|---|---|
startAnalysis | startAnalysis(dto: StartAnalysisDto) | Promise<string> | Start a new code analysis job |
getJobStatus | getJobStatus(jobId: string) | unknown | Get analysis job status |
getProjectJobs | getProjectJobs(projectId: string) | unknown | Get all jobs for a project |
Dependencies
PrismaServiceGitService
Where it refuses work
AnalysisServicestops the work withNotFoundExceptionwhen!job.AnalysisServicestops the work with an early return whendeps['next'].AnalysisServicestops the work with an early return whendeps['@nestjs/core'].AnalysisServicestops the work with an early return whendeps['react'].AnalysisServicestops the work with an early return whendeps['@angular/core'].AnalysisServicestops the work with an early return whendeps['vue'].
When something fails
AnalysisServicehandles failure in 2 places: it turns it into a return value in 1, and lets it reach the caller in 1.
Diagram
mermaidsequenceDiagram participant Client participant AnalysisService participant Database participant RepositoryService participant CodeAnalyzer participant DocumentationGenerator participant PlaywrightGenerator Client->>AnalysisService: startAnalysis(request) AnalysisService->>Database: Create analysis job / set status AnalysisService->>RepositoryService: Clone repository and resolve monorepo RepositoryService-->>AnalysisService: Local repository path AnalysisService->>CodeAnalyzer: Analyze optimized file set CodeAnalyzer-->>AnalysisService: Code analysis results AnalysisService->>Database: Update analysis progress AnalysisService->>DocumentationGenerator: Generate UI docs and extract elements DocumentationGenerator-->>AnalysisService: Documentation artifacts AnalysisService->>Database: Update generation progress AnalysisService->>PlaywrightGenerator: Generate Playwright tests PlaywrightGenerator-->>AnalysisService: Test artifacts AnalysisService->>Database: Mark job completed AnalysisService->>RepositoryService: Cleanup cloned repository AnalysisService-->>Client: Analysis job ID Client->>AnalysisService: getJobStatus(jobId) AnalysisService->>Database: Retrieve job status Database-->>AnalysisService: Job status AnalysisService-->>Client: Job status
Usage
tsimport { Injectable } from '@nestjs/common';
import { AnalysisService } from './analysis.service';
@Injectable()
export class ProjectAnalysisController {
constructor(private readonly analysisService: AnalysisService) {}
async analyzeProject(projectId: string, repositoryUrl: string) {
const jobId = await this.analysisService.startAnalysis({
projectId,
repositoryUrl,
branch: 'main',
});
return {
jobId,
message: 'Analysis started successfully',
};
}
async getAnalysisStatus(jobId: string) {
return this.analysisService.getJobStatus(jobId);
}
async listProjectAnalysisJobs(projectId: string) {
return this.analysisService.getProjectJobs(projectId);
}
}
AI Coding Instructions
- Keep
AnalysisServicefocused on orchestration; delegate cloning, parsing, documentation generation, and test generation to specialized services. - Update the persisted job status at meaningful pipeline boundaries so clients can reliably poll
getJobStatus(). - Ensure repository cleanup runs in a
finallyblock or equivalent failure-safe path, including when cloning or generation steps fail. - Preserve monorepo-aware repository resolution when adding analysis stages; downstream tools should receive the resolved package or workspace path.
- Return the analysis job ID immediately from
startAnalysis()and avoid blocking request handlers on long-running analysis work.
Relationships
- DEPENDS_ON →
PrismaService - DEPENDS_ON →
GitService
Referenced By
AnalysisController(DEPENDS_ON)AnalysisModule(MODULE_PROVIDES)AnalysisModule(MODULE_EXPORTS)
Was this page helpful?