How unclebob/arch-view works
Purpose and entry point
architecture-viewer is a Clojure CLI tool that analyzes a target Clojure project, constructs a namespace dependency architecture, optionally exports it as EDN, and presents an interactive layered diagram. The application entry point is src/arch_view/core.clj; it supports project scanning, EDN-oriented headless output, and GUI sessions.
Input acquisition and dependency discovery
The analysis boundary is the target project directory and configured source paths. Source scanning locates Clojure files and captures namespace-to-source-path associations in src/arch_view/input/source_scan.clj. Namespace forms are parsed to extract project-local :require edges in src/arch_view/input/dependency_extract.clj, while src/arch_view/input/dependency_checker.clj filters or validates dependencies against the discovered project namespace set.
Domain projection and graph model
Raw namespace/dependency facts are transformed into an architecture projection in src/arch_view/domain/architecture_projection.cljc. The central dependency graph representation and graph operations live in src/arch_view/model/graph.clj. This model preserves dependency relationships, source locations, and cycle-related information for both output and rendering.
Component classification
Namespaces are classified into architectural roles, including leaf/source modules and higher-level groupings, by src/arch_view/model/classify.clj. Component/tree construction is handled by src/arch_view/model/components.clj. The classification also recognizes abstract namespaces from constructs such as protocols, multimethods, and interfaces, which affects visual treatment.
Cycle handling and layered layout
The architecture graph is made rankable by identifying cyclic dependencies and removing offending edges from the ordering graph, while retaining them as visible cycle indicators. src/arch_view/layout/layers.clj topologically ranks the resulting acyclic graph into vertical levels and peer groups. This creates the top-down view: high-level namespaces above leaf modules.
Interactive rendering and navigation
The desktop UI is a Quil-based canvas view, coordinated by src/arch_view/render/ui/quil/view.clj, src/arch_view/render/ui/quil/canvas.clj, and src/arch_view/render/ui/quil/events.clj. It renders modules, dependency triangles, cycle labels, scrollable content, and drill-down scenes. UI state—current root, navigation history, scrolling, and reanalysis state—is maintained through src/arch_view/render/ui/util/scene_state.clj and src/arch_view/render/ui/util/view_bootstrap.clj.
Source inspection and runtime boundaries
Clicking a leaf namespace opens a Swing source viewer implemented in src/arch_view/render/ui/swing/source_window.clj, with source markup support in src/arch_view/render/ui/util/source_html.clj. The tool runs on the Clojure/JVM runtime (deps.edn), uses Quil for the graphical canvas and Swing for source windows, and has no server or external service dependency. Target projects are read from the local filesystem; --no-gui keeps execution headless and emits architecture data rather than initializing UI runtime components.
Main entry points: graph.clj Dependency graph · core.clj CLI entry point · source_scan.clj Source scanner · view.clj Quil view
Components 17
Project Analysis
Discovers local namespaces and dependency facts.
- Target project · Directory and configured source paths being analyzed.
- Source scanner · Maps namespaces to Clojure source files.
src/arch_view/input/source_scan.clj - Dependency extractor · Extracts project-local require edges.
src/arch_view/input/dependency_extract.clj - Dependency checker · Validates edges against discovered namespaces.
src/arch_view/input/dependency_checker.clj
Architecture Model
Projects dependencies into classified components.
- Architecture projection · Transforms raw namespace facts into architecture data.
src/arch_view/domain/architecture_projection.cljc - Dependency graph · Preserves dependencies, source locations, and cycle information.
src/arch_view/model/graph.clj - Role classifier · Identifies leaf, grouped, and abstract namespaces.
src/arch_view/model/classify.clj - Component tree · Builds architectural component and tree structure.
src/arch_view/model/components.clj
Layout
Ranks the graph while preserving cycle indicators.
- Layer ranking · Removes ordering-cycle edges and assigns levels and peer groups.
src/arch_view/layout/layers.clj
Interactive UI
Quil canvas navigation and Swing source inspection.
- View bootstrap · Initializes scenes and reanalysis state.
src/arch_view/render/ui/util/view_bootstrap.clj - Scene state · Tracks root, history, scrolling, and reanalysis.
src/arch_view/render/ui/util/scene_state.clj - Quil view · Coordinates canvas rendering and interaction.
src/arch_view/render/ui/quil/view.clj - Canvas renderer · Draws modules, dependencies, cycle labels, and scenes.
src/arch_view/render/ui/quil/canvas.clj - Canvas events · Handles navigation and leaf selection.
src/arch_view/render/ui/quil/events.clj - Swing source viewer · Opens selected leaf namespace source with markup.
src/arch_view/render/ui/swing/source_window.clj
Other components
- CLI entry point · Selects headless export or GUI analysis session.
src/arch_view/core.clj - EDN export · Emits architecture data without UI initialization.
Connections 21
- CLI entry point → Target project: analyzes
- Target project → Source scanner: source paths
- Source scanner → Dependency extractor: namespace files
- Source scanner → Dependency checker: known namespaces
- Dependency extractor → Dependency checker: require edges
- Dependency checker → Architecture projection: validated facts
- Architecture projection → Dependency graph: builds
- Dependency graph → Role classifier: namespace graph
- Role classifier → Component tree: roles
- Dependency graph → Component tree: relationships
- Component tree → Layer ranking: component graph
- Dependency graph → Layer ranking: cycles
- CLI entry point → EDN export: --no-gui
- CLI entry point → View bootstrap: GUI mode
- Layer ranking → View bootstrap: layered architecture
- View bootstrap → Scene state: initializes
- Scene state → Quil view: scene state
- Quil view → Canvas renderer: renders
- Quil view → Canvas events: receives input
- Canvas events → Scene state: updates navigation
- Canvas events → Swing source viewer: selected leaf