CodeContext is built as a modular, pipeline-based system that analyzes codebases and generates interactive reports.
graph TD
A[CLI Entry Point] --> B[Repository Scanner]
B --> C[Code Parser]
C --> D[Dependency Graph Builder]
D --> E[Analysis Engine]
E --> F[Report Generator]
F --> G[HTML Output]
H[Git Analyzer] --> C
I[Cache Manager] --> C
J[Config Loader] --> A
style A fill:#4CAF50
style G fill:#2196F3
cli/)Purpose: Command-line interface for user interaction
Components:
MainCommand.kt - Root command handlerImprovedAnalyzeCommand.kt - Main analysis workflowServerCommand.kt - REST API serverAIAssistantCommand.kt - AI-powered insightsEvolutionCommand.kt - Codebase evolution trackingFlow:
User Input → Clikt Parser → Command Handler → Core Engine
core/scanner/)Purpose: Discover and filter source files
Components:
RepositoryScanner.kt - File discovery with gitignore supportOptimizedGitAnalyzer.kt - Git history analysisAlgorithm:
Performance: O(n) where n = total files in repository
core/parser/)Purpose: Extract metadata from source files
Components:
LanguageParser - Interface for all parsersJavaRealParser.kt - Uses JavaParser library for AST parsingKotlinRegexParser.kt - Regex-based Kotlin parsingParserFactory.kt - Factory pattern for parser selectionParsedFile.kt - Data model for parsed resultsData Extracted:
Parallel Processing:
// CodeParallelParser uses coroutines for performance
files.chunked(100).flatMap { chunk ->
chunk.map { file ->
async(Dispatchers.IO) {
parser.parse(file)
}
}.awaitAll()
}
core/graph/)Purpose: Build and analyze dependency relationships
Component: RobustDependencyGraph.kt
Algorithm:
For each import:
Graph Structure:
PageRank Scoring:
score(file) = (1-d)/N + d * Σ(score(incoming) / outgoing_count(incoming))
Where d=0.85 (damping factor)
core/generator/)Purpose: Create learning paths for developers
Component: LearningPathGenerator.kt
Algorithm:
Output: List of LearningStep with reasoning
output/)Purpose: Generate interactive HTML reports
Component: ReportGenerator.kt
Features:
Data Flow:
Graph + ParsedFiles → JSON serialization → HTML template → D3.js rendering
core/cache/)Purpose: Speed up re-analysis
Component: CacheManager.kt
Strategy:
.codecontext/ directoryPerformance Gain: ~70% faster on re-analysis
server/)Purpose: REST API for programmatic access
Component: CodeContextServer.kt
Endpoints:
POST /analyze - Trigger analysisGET /report/:id - Retrieve reportGET /health - Health checkTechnology: Ktor framework
1. User runs: ./gradlew run --args="analyze /path"
↓
2. CLI parses arguments → ImprovedAnalyzeCommand
↓
3. RepositoryScanner finds files (with gitignore)
↓
4. CodeParallelParser parses files (parallel)
├─ JavaRealParser (for .java)
└─ KotlinRegexParser (for .kt)
↓
5. OptimizedGitAnalyzer enriches with Git data
↓
6. RobustDependencyGraph builds graph
├─ Create vertices (files)
├─ Create edges (imports)
└─ Run PageRank
↓
7. LearningPathGenerator creates reading order
↓
8. ReportGenerator creates HTML
├─ Serialize graph to JSON
├─ Generate HTML with kotlinx.html
└─ Embed D3.js visualization
↓
9. Output: output/index.html
ParserFactory - Creates appropriate parser based on file extensionLanguageParser interface - Different parsing strategies per languageRobustDependencyGraph - Builds graph incrementally| Layer | Technology | Purpose |
|---|---|---|
| Language | Kotlin 2.1.0 | Type-safe, concise, coroutines |
| CLI | Clikt | Command-line parsing |
| Parsing | JavaParser | Java AST parsing |
| Graphs | JGraphT | Graph algorithms (PageRank) |
| Git | JGit | Git history analysis |
| HTML | kotlinx.html | Type-safe HTML generation |
| Visualization | D3.js | Interactive force graphs |
| Server | Ktor | REST API framework |
| Testing | Kotest | Property-based testing |
| Serialization | kotlinx.serialization | JSON handling |
| Operation | Complexity | Notes |
|---|---|---|
| File Scanning | O(n) | n = total files |
| Parsing | O(n) | Parallelized |
| Graph Building | O(n + e) | n = files, e = imports |
| PageRank | O(k * (n + e)) | k = iterations (100) |
| Report Generation | O(n + e) | JSON serialization |
LanguageParser:
class PythonParser : LanguageParser {
override fun parse(file: File): ParsedFile {
// Extract package, imports, description
}
}
ParserFactory:
"py" -> pythonParser
src/test/kotlin/core/analyzer/:
class ComplexityAnalyzer {
fun analyze(files: List<ParsedFile>): Map<String, Int> {
// Calculate complexity metrics
}
}
Integrate in ImprovedAnalyzeCommand
ReportGenerator to display results