AI, please explain this code base

Can AI tell me what design is implemented ?

Recently, I wanted to contribute to some open-source Go packages that I use. Some of them have a large codebase with lots of subpackages. Despite the carefully chosen names for this these packages, without an overview and design description, it will require quite some time reading sources and debugging tests before a mental model is created. Without such an understanding, contributing to that open-source project is likely to fail.

LLMs (large-language-models) are now capable of summarizing texts extracting the most relevant pieces of information. This capability is already being using in several coding assistances suchs as Microsoft Co-Pilot, Google Gemini and many others.

As a proof of concept, I hacked together a small tool called gemini-code-explain to see what kind of design documentation (and whether is makes sense) the Google Gemini LLM can produce today given a versioned Go package.

Basically, the tool creates a large context window with all the sources from a given Go package and then sends a prompt like “please document the design of this package”.

After installation and creating an API Key to access the Gemini API, you can use it like this:

GEMINI_API_KEY=YOUR_TOKEN gemini-code-explain -gopkg github.com/emicklei/[email protected]

which after downloading, context building and prompting results in a document that starts with:

The Go software you've provided is a library designed to help developers 
create graphs and diagrams using the DOT language, which is commonly used with Graphviz. 
Here's a breakdown of its design:

Core Components:

- Graph: The Graph struct represents the entire graph or subgraph. It holds attributes, nodes, edges, and subgraphs. Key characteristics:
- Hierarchical: Graphs can be nested, forming subgraphs within parent graphs.
- Directed/Undirected: Can be configured to represent both directed and undirected graphs.
- Attribute Management: Uses an AttributesMap to manage key-value pairs for styling and metadata.
- Node: The Node struct represents a single element in the graph. Each node has attributes and is associated with a graph.
- Edge: The Edge struct represents a connection between two nodes. It also uses AttributesMap for attributes like labels and styles.

...

See AI explained my dot package for the complete document.

You can find the MIT licensed OSS tool at github.com/emicklei/gemini-code-explain.