Skip to content
aryxPublic

About

Source code dependencies visualizer

Resources

Stars

6 stars

Watchers

1 watching

Forks

Repository files navigation

Codegraph

Hierarchical dependency analyzer and visualizer using a Dependency Structure Matrix (DSM). Builds dependency graphs from source code at multiple granularities (packages, modules, types, functions) and renders them via a GTK2/Cairo GUI. Uses semgrep parsers for multi-language support.

codegraph screenshot

Understanding dependencies is at the essence of software architecture: code is a tree when looked at locally (AST), but it's really a graph of dependencies when looked at globally. Codegraph helps you understand and improve that structure.

A great introduction to DSM for improving a codebase: https://blog.ndepend.com/identify-net-code-structure-patterns-with-no-effort/

Why a matrix?

Traditional node-link dependency graphs (graphviz, gephi, ocamldot) work fine for small projects, but quickly become an unreadable mess of crossing edges on large codebases. Even with filtering and layout tuning, the visual noise makes it hard to extract useful architectural information.

After years of experimenting with various graph visualizations — directed graphs, force-atlas layouts, chord diagrams — on codebases ranging from compilers to the Facebook monorepo, it became clear that node-link displays simply don't scale. Paradoxically, going back to a tabular representation of the graph — the Dependency Structure Matrix — makes large dependency graphs manageable. The matrix scales to hundreds of components, makes dependency cycles immediately visible, and the hierarchical drill-down lets you move from a high-level package view all the way down to the individual functions responsible for a dependency.

Related tools

Other tools using DSM for software architecture analysis:

See also the old codegraph page at Facebook for more information.

Building

Prerequisites

OCaml 4.14+ (via opam >= 2.1), gcc, git, curl, pkg-config.

On Ubuntu/Debian:

apt-get install build-essential pkg-config opam curl libcairo2-dev libgtk2.0-dev

On macOS:

brew install opam pkg-config cairo gtk+

C libraries (pcre, pcre2, gmp, libev, libcurl) are installed automatically by ./configure via opam — no need to install them manually.

Quick start

git clone --recurse-submodules https://github.com/aryx/codegraph
cd codegraph
./configure     # installs opam deps and sets up tree-sitter (run infrequently)
make            # routine build
make test       # run tests

Docker

A reference build using Ubuntu is provided:

docker build -t codegraph .

To build with OCaml 5:

docker build -t codegraph --build-arg OCAML_VERSION=5.2.1 .

Usage

codegraph_build

codegraph_build -lang cmt ~/my-project

Generates a graph_code.marshall file in ~/my-project containing all dependency information, using the typed bytecode .cmt files generated during compilation.

codegraph

codegraph ~/my-project

Launches a GTK-based GUI that lets you visualize source code dependencies as a DSM. You can interactively expand/collapse nodes to navigate between different granularities (packages, modules, functions) and zoom into specific dependencies to see the actual code entities involved.

You can also run codegraph from a subdirectory to get a focused slice of the dependency graph:

codegraph ~/my-project/src/core

About

Source code dependencies visualizer

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages