SlicerCode conceptsIntermediate9 min read

Code Flow & Graph Analysis

Modern systems are too tangled to understand file-by-file. Code flow analysis models a program as a graph — functions as nodes, calls and data dependencies as edges — so you can answer questions like "what actually happens when this endpoint is hit?" This guide covers call graphs, control/data/object flow, the difference between static and runtime-refined flow, why a code graph is the best possible context for an AI agent, how external systems get detected on a path, and how to visualize a flow you can actually read.

What Is Code Flow & Graph Analysis?

Code flow analysis is the practice of tracing how control and data move through a program — not reading files top to bottom, but following the path execution actually takes from an entry point through every function it touches. The natural data structure for that path is a graph: nodes are functions, methods or modules, and edges are the relationships between them (a call, a value passed, an object mutated). Together, code flow analysis and the resulting code graph turn a pile of files into a navigable model of behavior.

The distinction matters because a file tree tells you where code lives, not what it does. Two functions in the same file may never interact, while a single request handler can fan out across a dozen packages, a message queue and a database before it returns. A flow graph captures those real relationships; a directory listing hides them.

This is why the words flow and graph show up everywhere in program analysis: compilers use control-flow graphs to optimize, security tools use data-flow graphs to track taint, and modern AI coding tools use call graphs to ground their edits. The rest of this guide builds up each layer — call, control, data and object flow — and shows why the graph, not the file, is the real unit of understanding.

Key takeaway — Code flow analysis models a program as a graph of functions and their relationships, capturing what the code does rather than where it lives.

Call Graphs: The Backbone of Code Flow

A call graph is the foundational layer. Each node is a function or method; a directed edge from A to B means "A may call B." Start from an entry point — an HTTP route, a scheduled job, a CLI command, a main() — and the set of nodes reachable by following edges is everything that endpoint can execute. That reachable subgraph is the flow for that entry point.

Building a call graph statically means parsing source into syntax trees and resolving every call site to its target definition, across files and packages. Fast, incremental parsers like tree-sitter make this practical over a large repo and several languages at once. The hard part is resolution: a direct function call is easy, but method calls through an interface, function values, callbacks and reflection can each point to several possible targets.

Because of that, honest engines classify each edge rather than silently guessing. That classification is what makes the static-versus-dynamic distinction below tractable — you know exactly which edges are certain and which need runtime evidence to pin down.

  • Resolved — exactly one target; the safe, certain edges
  • Ambiguous — a polymorphic call site (e.g. an interface with several implementations)
  • Unresolved — a dynamic target the static analyzer can't determine
  • Cycle — recursion or mutual recursion between nodes
Key takeaway — A call graph roots every endpoint's flow; the real engineering challenge is resolving polymorphic and dynamic call sites honestly instead of guessing.

Control Flow, Data Flow, and Object Flow

The call graph tells you which functions run; three finer-grained flows tell you how. Control flow describes the order and branching within and across functions — the if/else, loops and early returns that decide which path executes. A control-flow graph (CFG) is the classic compiler representation of a single function's possible execution paths.

Data flow tracks values instead of control. Def-use analysis follows a variable from where it's defined to every place it's read, so you can answer "where does this request parameter end up?" or "what feeds this SQL query?" This is the backbone of taint tracking, dead-code detection, and understanding how an input propagates to a side effect.

Object flow is the object-oriented sibling: it follows a specific object from construction through the calls it's passed into, the fields written on it, and the point it's returned or persisted. For a service that builds an order, mutates it across layers, and writes it to a database, object flow is what makes that lifecycle legible. Layered over the call graph, control, data and object flow give you a complete, queryable picture of a single request.

  • Control flow — branching and ordering (the CFG within and across functions)
  • Data flow — def-use chains: how a value propagates to reads and side effects
  • Object flow — an object's lifecycle: construction, mutation, passing, return/persist
Key takeaway — Control flow captures branching, data flow captures value propagation, and object flow captures an object's lifecycle — layered on the call graph they fully describe a request.

Static vs Dynamic (Runtime-Refined) Flow

Static flow analysis reads source code without running it. It's comprehensive — it can see every branch, even ones that rarely execute — but it over-approximates: at a polymorphic call site it must assume any implementation might run, so the graph fills with ambiguous edges that may never fire in practice.

Dynamic flow analysis is the opposite. By observing an actual execution — via a debugger, instrumentation or tracing — it records exactly which functions ran, which branch was taken, and what values flowed through. It's precise but partial: it only knows about the paths you actually exercised.

The strongest approach combines the two. Build a static skeleton for completeness, then refine it with runtime traces: ambiguous polymorphic edges collapse to the concrete implementation that actually ran, the executed path is highlighted, and hit counts reveal hot paths. You keep the static graph's coverage and gain the dynamic run's precision.

This is exactly how SlicerCode builds flows: static call-, data- and object-flow for every endpoint and job (tree-sitter, 6+ languages), then refined by runtime tracing that attaches the debugger to resolve polymorphic edges to what actually ran.

Key takeaway — Static analysis is complete but over-approximates; dynamic tracing is precise but partial — refining a static graph with runtime data gives you both coverage and precision.

Why a Code Graph Is the Ideal Context for an AI Agent

An LLM agent is only as good as the context it's given. The naive approach — paste in whole files, or a vector-search grab-bag of snippets — is noisy and expensive: it burns the context budget on irrelevant code and still misses the cross-file relationships that matter most. A code graph fixes both problems at once.

With a graph, an agent can request exactly the subgraph for the flow it's editing: the functions on the path, their real input and output shapes, their immediate callers and callees, and the external systems they touch. That's a small, dense, highly relevant context instead of a large, sparse one — which lowers cost and reduces hallucination, because the model sees how the code actually connects rather than inferring it.

SlicerCode's coding agent is grounded in exactly this graph. Before it writes, it consults the call graph, flows and captured runtime values, so multi-file edits match how the system really works. See Context Engineering and AI Coding Agents for why graph-shaped context consistently outperforms raw file dumps.

Key takeaway — A code graph gives an agent minimal, dense, relationship-aware context — cheaper on tokens and far less hallucination-prone than pasting files or vector-search snippets.

Detecting External Systems on the Flow Path

Real flows don't stay inside your process. Somewhere on the path a handler publishes to Kafka, opens a database transaction, calls an HTTP API, enqueues a background job, or reads a cache. These boundaries are among the most important nodes in the whole graph, because they're where side effects, latency and failure modes live.

Detecting them means recognizing the client libraries, annotations and call patterns that signal an I/O boundary — a message producer, an ORM or repository call, an HTTP client, a queue publisher, a cache read. Marking those on the flow tells you a request's true blast radius: what it reads, what it mutates, and what it can't be tested against without a mock or a live dependency.

SlicerCode detects external systems — Kafka, databases, HTTP, queues and caches — directly on the flow path and renders them as distinct nodes, so you can see every integration point a single endpoint reaches at a glance.

  • Message brokers — Kafka and similar producers/consumers on the path
  • Datastores — SQL/NoSQL via ORM or repository calls
  • HTTP — outbound API calls to other services
  • Queues & caches — job enqueues and cache reads/writes
Key takeaway — External-system boundaries are the highest-value nodes on a flow — they define a request's side effects, latency and blast radius, and what it can be tested against.

Visualizing a Flow as a Graph

A flow you can't see is a flow you won't use. Rendering the reachable subgraph as an interactive diagram turns analysis into something a developer actually reaches for — onboarding onto an unfamiliar service, reviewing the blast radius of a change, or debugging where a value goes wrong three layers deep.

Different questions want different layouts. A node-link graph shows structure and branching; a sequence view shows temporal order across services; a tree or mindmap view shows hierarchy from an entry point. Being able to open the same flow in whichever view fits the question keeps the graph useful across tasks rather than a one-shot picture.

SlicerCode renders any flow as a graph you can open in its own editor tab or mirror to a browser with a shareable deep link, and clicking any node returns an on-demand, plain-English explanation of that step's inputs and outputs.

Key takeaway — Rendering a flow as an interactive graph — with graph, sequence and tree views — turns static analysis into a tool developers actually use for onboarding, review and debugging.

How SlicerCode Builds and Uses the Flow Graph

SlicerCode builds the flow graph the moment a project loads: it parses the workspace with tree-sitter across 6+ languages (Java, Kotlin, Python, JavaScript/TypeScript, Go, Ruby and more) and constructs call-, data- and object-flow for every endpoint and job, with external systems detected on each path. Runtime tracing then refines that static graph into what actually ran.

That single graph powers the rest of the product. The AI agent grounds its edits in it; PRD validation scores a flow against requirements across four dimensions — code, executed flow, changes still to make, and tests — using observed runtime values; and test generation seeds real cases from captured values, then compiles, runs and repairs until green. Coverage overlays real line percentages (JaCoCo, coverage.py, c8, go cover) plus executed-flow coverage onto the same map.

To try it, install the VS Code extension and open the Flows tab in the Analyzer — search a flow by class or route, open it as a graph, and click any node to see it explained. See the docs for setup, and note that IntelliJ and a CLI are on the roadmap.

Key takeaway — One flow graph — static, runtime-refined and external-system-aware — is the shared foundation for SlicerCode's agent, PRD validation, test generation and coverage.

Frequently asked questions

What is code flow analysis?

Code flow analysis traces how control and data move through a program, from an entry point through every function it touches, and models that path as a graph of functions (nodes) and their relationships (edges). It answers "what actually happens when this endpoint runs?" rather than just where the code lives.

What is the difference between static and dynamic flow analysis?

Static analysis reads source without running it, so it sees every branch but over-approximates polymorphic calls; dynamic analysis observes a real execution, so it's precise but only covers the paths you exercised. Refining a static graph with runtime traces gives you the coverage of one and the precision of the other.

What is a call graph?

A call graph is a directed graph where each node is a function or method and each edge means one function may call another. Starting from an entry point, the reachable nodes are everything that endpoint can execute — which forms the basis of its flow.

Why is a code graph better context for an AI coding agent than pasting files?

A graph lets the agent pull exactly the subgraph for the flow it's editing — the relevant functions, real data shapes and external systems — instead of large, noisy file dumps. That is cheaper on context budget and reduces hallucination, because the model sees how the code actually connects instead of inferring it.

How does SlicerCode detect external systems like Kafka or a database in a flow?

It recognizes the client libraries, annotations and call patterns that signal an I/O boundary — message producers, ORM/repository calls, HTTP clients, queues and caches — and marks them as distinct nodes on the flow path, so you can see every integration point an endpoint reaches. See /features#flow.

What languages does SlicerCode's flow analysis support?

It parses with tree-sitter across 6+ languages — Java, Kotlin, Python, JavaScript/TypeScript, Go and Ruby, and more — building call-, data- and object-flow for each. It runs in VS Code today, with IntelliJ and a CLI on the roadmap.

See it in your codebase

SlicerCode brings the agent, flow graphs, runtime capture, PRD validation and test generation into VS Code.