# chanhx/crabviz architecture

> Architecture diagram of the GitHub repository chanhx/crabviz, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chanhx/crabviz
- Repository: https://github.com/chanhx/crabviz

## Overview

##### Project Type and Purpose
- Crabviz is a tool that leverages the Language Server Protocol (LSP) to generate interactive call graphs. It’s designed for visual code exploration and is most effective as an IDE/editor extension.
- The project is implemented primarily in Rust (indicated by Cargo.toml, Cargo.lock, and src/) with an additional editor integration component found under editors/code (which contains VS Code extension files and configurations).

##### Main Components
- Core Call Graph Generation Engine (Rust Core):
- Represented by the src/ directory with key modules:
▪ Generator: Files in src/generator (generator.rs, tests.rs, types.rs, wasm.rs) which handle the logic for generating call graphs.
▪ Graph: The src/graph directory (graph.rs, dot.rs) dealing with the construction and representation of call graphs.
▪ Language-specific Parsers/Adapters: In src/lang (and its submodules like go.rs and rust.rs) which tailor graph generation to different languages.
▪ Additional utilities like src/lsp_types.rs and src/lib.rs that help interface with the Language Server Protocol.
- Editor/Extension Integration:
- Found under editors/code/ which contains:
▪ VS Code extension-specific files (extension.ts, command-manager.ts, webview.ts) for interfacing with the editor.
▪ Configuration files (.eslintrc.json, package.json, webpack.config.js) that define the extension’s setup.
▪ UI assets (media folder with CSS, JS files) for rendering the interactive graphs.

##### Relationships and Interactions
- The VS Code Extension (editors/code) communicates with the Rust core via the language server protocol.
- User actions in the editor (e.g., file selection, function highlight) trigger commands (via command-manager.ts) that call into the Rust backend for processing.
- The Rust core processes source code, generates the call graph data (using the generator, graph, and language modules), and provides output that the extension then transforms into interactive UI elements (such as SVG exports and clickable nodes).
- There is also a separation between UI rendering (front end) and core business logic (back end), with data flowing from the core calculation modules to the user interface components.

##### Architectural Patterns and Design Principles
- Modular Architecture: The project splits its responsibilities clearly between core processing (Rust modules) and UI/editor integration (VS Code extension code).
- Separation of Concerns: Distinct boundaries exist where LSP functionalities, graph algorithm implementations, and visual presentation are isolated into separate directories/components.
- Extensibility: The use of modular language-specific adapters (in src/lang) indicates the design supports multiple programming languages.
- Clear command flow: The “command-manager.ts” and associated helper utilities in the editors section hint at a command-driven pattern coordinating interactions triggered by editor events.

##### Technologies and Frameworks
- Programming Languages: Rust for the core functionality and TypeScript/JavaScript for the VS Code extension.
- LSP (Language Server Protocol): Used by the core engine to interact with languages and communicate with the editor.
- VS Code Extension API: Used in the editors/code components for integration.
- Webpack and other build tools: Employed for bundling the extension’s web assets.
- Testing: The presence of test files (e.g., src/generator/tests.rs, extension.test.ts) demonstrates that testing is an integral part of the system, so include test components as secondary nodes if needed.

##### Emphasizing Essential Architectural Elements
- Recognize that while the project only currently supports VS Code, the design is modular enough to integrate with other editors – include an architectural note about potential extension points.

## Diagram (Mermaid)

```mermaid
graph TD
  subgraph "Core Engine Domain (Rust Core)"
    A1["LSP Interface / Core Library"]:::rust
    A2["Generator Module"]:::rust
    A3["Graph Representation Module"]:::rust
    A4["Language-Specific Parsers/Adapters"]:::rust
  end

  subgraph "Editor Integration Domain (VS Code Extension)"
    B1["VS Code Extension Main"]:::editor
    B2["Command Manager"]:::editor
    B3["Webview UI Component"]:::editor
    B4["Configuration & Assets"]:::config
  end

  B1 --> B2
  B1 --> B3
  B2 -->|"sendsCommands"| A1
  A1 -->|"invokesGeneration"| A2
  A1 -->|"buildsGraph"| A3
  A1 -->|"parsesLanguages"| A4
  A1 -->|"returnsGraphData"| B3

  classDef rust fill:#FFDDAA,stroke:#333,stroke-width:2px;
  classDef editor fill:#AADDFF,stroke:#333,stroke-width:2px;
  classDef config fill:#FFCC99,stroke:#333,stroke-width:2px;

  click A1 "https://github.com/chanhx/crabviz/blob/main/src/lib.rs"
  click A2 "https://github.com/chanhx/crabviz/tree/main/src/generator"
  click A3 "https://github.com/chanhx/crabviz/tree/main/src/graph"
  click A4 "https://github.com/chanhx/crabviz/tree/main/src/lang"
  click B1 "https://github.com/chanhx/crabviz/blob/main/editors/code/src/extension.ts"
  click B2 "https://github.com/chanhx/crabviz/blob/main/editors/code/src/command-manager.ts"
  click B3 "https://github.com/chanhx/crabviz/blob/main/editors/code/src/webview.ts"
  click B4 "https://github.com/chanhx/crabviz/tree/main/editors/code/"
```
