smalltalk-dev-plugin-graph-example

Description

Example of smalltalk-dev-plugin: Graph and Shortest Path

Details

Source
GitHub
License
MIT
Created
Feb. 6, 2026
Updated
March 27, 2026
Topics
claude-code demo example pharo-smalltalk

Categories

Testing Education / Howto

README excerpt

# smalltalk-dev-plugin: Graph and Shortest Path

This repository showcases a project created by [smalltalk-dev-plugin](https://github.com/mumez/smalltalk-dev-plugin) — a Claude Code extension for Pharo Smalltalk development.

This is a slightly more advanced example. From a single prompt with basic class hints, Claude Code designed a detailed implementation plan and generated working source code — including Dijkstra's shortest-path algorithm, complete with tests.

You can watch the actual development process in the video below.

[![Watch the video](https://img.youtube.com/vi/MpWw6nuDxcA/0.jpg)](https://youtu.be/MpWw6nuDxcA)

## Prompt

The following prompt was given to `/st-buddy`:

```
/st-buddy I want to create GrNode and GrArc to represent directed graphs
and solve shortest path problems. Nodes have a name, arcs have a score.
Let's start this as a GraphGear project.
```

## Generated Source

The source code is in the [src](./src) directory. Three packages were generated:

| Package | Description |
|---------|-------------|
| **BaselineOfGraphGear** | Metacello baseline configuration |
| **GraphGear** | Core classes — `GrNode`, `GrArc`, `GrGraph` |
| **GraphGear-Tests** | SUnit tests — `GrNodeTest`, `GrArcTest`, `GrGraphTest` |

### Class Overview

- **GrNode** — A named node (vertex) in a directed graph. Maintains outgoing arcs.
- **GrArc** — A weighted, directed arc (edge) connecting two nodes.
- **GrGraph** — A directed weighted graph with Dijkstra's shortest-path algorithm.

## Try It in Pharo

If you would like to try the generated source code in a live Pharo environment, you can load the `GraphGear` project using Metacello:

```smalltalk
Metacello new
  baseline: 'GraphGear';
  repository: 'github://mumez/smalltalk-dev-plugin-graph-example:main/src';
  load.
```

Once loaded, verify that all tests pass:

```smalltalk
GrGraphTest suite run. "print it"
```

Here is a usage example — building a graph and finding the shortest path with Dijkstra's algorithm:

```smalltalk
graph := GrGraph new.
graph addNodeNamed: 'A'.
graph addNodeNamed: 'B'.
graph addNodeNamed: 'C'.
graph addNodeNamed: 'D'.
graph addArcFrom: 'A' to: 'B' score: 1.
graph addArcFrom: 'A' to: 'C' score: 4.
graph addArcFrom: 'B' to: 'D' score: 3.
graph addArcFrom: 'C' to: 'D' score: 1.

graph shortestDistanceFrom: 'A' to: 'D'.              "=> 4"
(graph shortestPathFrom: 'A' to: 'D') collect: #name. "=> #('A' 'B' 'D')"
```

```
    A ---1--- B
    |         |
    4         3
    |         |
    C ---1--- D

  Shortest path A to D: A -> B -> D (cost 4)
  Not: A -> C -> D (cost 5)
```

You can browse the `GrNode`, `GrArc`, and `GrGraph` classes in the System Browser. You will notice that CRC-style class comments were also generated along with the source code.
← Back to results