How smontanari/code-forensics works
Project type and purpose
• This is a full-stack, Node.js-based analysis tool (code-forensics) that runs as a set of gulp tasks (CLI) to analyse version-controlled repositories, generates JSON reports, serves them over HTTP, and visualises them in the browser using D3.
Main architectural components
a. CLI/Gulp Task Runner
• Entry point for all analyses (scripts/webserver.js + gulpfile.js calling lib/index.js).
• Defines tasks, parses parameters, configures runtime.
b. Core Library (lib/)
• Task definitions (lib/tasks/*), models (lib/models/*), configuration / runtime (lib/runtime/*), logging (lib/log), utilities (lib/utils).
c. Analyser Modules (lib/analysers/*)
• Language-agnostic analysers (sloc, word_count).
• Wrappers for external tools: Code-maat (Java jar or Docker), flog (Ruby), escomplex (JS).
d. VCS Adapters (lib/vcs/*)
• Git and SVN adapters to stream log data to analysers.
e. Parallel Processing (lib/parallel_processing/*)
• Job scheduler, stream processor, task executor to run analysers in parallel.
f. Reporting Engine (lib/reporting/*)
• Data source handler, merge strategies, object transformer, report composer, publisher (writes JSON).
g. API Middleware (lib/api_middleware/*)
• Serves report JSON files over HTTP for the front-end.
h. Web Front-End (lib/web/* + public/)
• Static assets in public/: HTML, LESS/CSS, templates.
i. External Dependencies
• Java 8 (for Code-maat .jar), or Docker image (if configured).
• Node.js (v4+), npm, gulp v4, browser for D3 UI.
Relationships & Data Flow
1. Developer invokes gulp <task> → CLI/Gulp Runner reads config & parameters.
2. Task definitions delegate to Core Library → instantiate TaskContext, load reports, build pipeline.
3. VCS Adapter streams commit/log data into Analyser Modules.
4. Parallel Processing Engine schedules and runs multiple analysers concurrently (e.g., sloc, complexity, coupling).
5. Analysers may shell out to external tools (Java jar, Docker, Ruby flog, escomplex) → output raw metrics.
6. Reporting Engine merges, transforms metric outputs → JSON report files on disk.
7. API Middleware watches reports folder and exposes HTTP endpoint (e.g., GET /reports/:id).
8. Front-End (Browser) loads index.html, fetches report JSON via API, renders D3 visuals (charts, word clouds, graphs).
Architectural patterns & design principles
• Modular layering:
• Core CLI layer → Task layer → Analyser/VCS layer → Reporting layer → API layer → UI layer.
• Pipeline/stream processing: VCS logs → analysers → reporting.
• Plugin-style analysers: new metric analysers drop into lib/analysers.
• Parallelism: job scheduler and task executor to maximize CPU use.
• Separation of concerns: CLI, analysis, reporting, API, UI are discrete modules.