Architecture Overview
Rev-dep’s architecture is designed for maximum performance through several key design decisions:Go-Based Implementation
Rev-dep is written entirely in Go, which provides:- Native compilation - Runs directly on the OS without a JavaScript runtime
- Efficient memory management - Go’s garbage collector is optimized for high-throughput applications
- Concurrent execution - Built-in goroutines enable true parallelism across CPU cores
Core Components
1. File Discovery & Parsing
Rev-dep discovers and parses source files using a multi-stage process:parseImports.go) uses a custom-built lexer that:
- Handles
importandexportstatements - Detects
require()calls - Skips comments, strings, and template literals
- Processes Vue and Svelte single-file components
2. Dependency Graph Construction
Rev-dep builds a minimal dependency tree representation:- Nodes represent files
- Edges represent import relationships
- Vertices store children and parent references
- Modules track external dependencies
3. Analysis Engines
Each check type has its own optimized analysis engine: Circular Dependency Detection (circularDeps.go):
Execution Flow
Single Command Execution
- Parse CLI arguments - Cobra framework handles command routing
- Discover files - Walk directory tree, apply gitignore patterns
- Parse imports - Parallel parsing with worker pool (GOMAXPROCS × 2)
- Resolve imports - Match import requests to actual files
- Build graph - Construct in-memory dependency tree
- Run analysis - Execute the requested check
- Format output - Display results to user
Config-Based Execution
When runningrev-dep config run, the process is optimized:
- Single tree build - Dependency graph is built once and reused
- Parallel rule processing - Multiple rules run simultaneously
- Parallel check execution - All checks within a rule run concurrently
Parallelization Strategy
Rev-dep leverages Go’s concurrency primitives extensively:File Parsing Parallelization
Graph Building Parallelization
When analyzing multiple entry points:Import Resolution
Rev-dep implements comprehensive import resolution:TypeScript Path Aliases
Readstsconfig.json and resolves path aliases like:
Package.json Exports
Supports the modernexports field in package.json:
Monorepo Support
Automatically detects and resolves workspace packages:- Reads
pnpm-workspace.yaml,package.jsonworkspaces - Resolves cross-package imports
- Validates dependencies are declared in
package.json
Performance Impact
The Go-based architecture with parallel processing enables Rev-dep to analyze 500k+ LoC codebases in under 500ms, making it 10x-200x faster than JavaScript-based alternatives.
