docs

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package docs turns the indexed graph into a document a person can read, and does it deterministically enough to commit the result.

Why this exists

Two kinds of architecture documentation are common and both fail. Hand-written documents describe a system that stopped existing three refactors ago. Prose generated by a language model reads beautifully and cites nothing, so a reader who doubts a sentence has no way to check it and no way to tell which sentences changed because the code changed.

This package takes the third option: every node and every edge in every diagram is DERIVED from a fact in the index, and carries the file and line that fact came from. A reader who does not believe a arrow can open the file.

Determinism is the feature

The same index produces byte-identical output, so the document can live in the repository and its diff is a real diff — the lines that changed are the architecture that changed. That is a property an LLM cannot offer at any temperature, and it is the reason to prefer a derived document to a written one even when the written one reads better.

Concretely: nothing here iterates a map to decide an order, and nothing here writes a timestamp into the document body. Inputs are re-sorted on entry rather than trusted to arrive sorted, so a caller supplying rows in a different order still gets the same bytes.

Components are DECLARED, never inferred

Where .graphlume.yml declares a component model, that model is used. Where it does not, this package SAYS SO and stops, rather than clustering packages and presenting the result as the architecture. The argument is already made in internal/capability/architecture's package doc and it applies with more force here: a component model GraphLume guessed would be a description of the code's current shape, and a diagram of a description of the code is a picture of the code with fewer details. Naming it "the architecture" would be the same unverifiable assertion the competing tools ship, dressed as a diagram.

The endpoint flows and the inheritance view are different: those are read directly off EXPOSES, CALLS, READS, WRITES, IMPLEMENTS and EXTENDS edges, each of which is a fact somebody's parser produced with evidence attached. They are rendered whether or not a component model exists.

Bounded

A 10,000-symbol repository must not produce a 10,000-node diagram; nobody reads that and no renderer lays it out. Every section has a cap, the ordering that decides what survives the cap is deterministic and documented, and what was dropped is stated in the document rather than silently missing. A truncated diagram that admits it is truncated is usable; one that does not is a lie with a legend.

What this deliberately does not do

It does not write files. Generate returns strings; where they land is the caller's decision and the caller's error to wrap.

It does not render Mermaid to images, and it does not depend on a Mermaid version's newer syntax. The emitted diagrams use `graph`, `flowchart` and `classDiagram` with quoted labels and nothing else, because a diagram that only renders on the latest renderer is a diagram that does not render in the reader's code host.

It does not use internal/graph's traversal. That traversal is confidence-weighted and budget-bounded by design, which is right for context assembly and wrong here: the endpoint flow needs one specific shape (EXPOSES, then CALLS to a bounded depth, then READS/WRITES) and needs the result to be a pure function of the edge set. Re-deriving that locally from edges already read is both simpler and the only version that can promise byte-identical output. See ports.go.

Index

Constants

View Source
const DefaultConfigPath = ".graphlume.yml"

DefaultConfigPath is where GraphLume reads a repository's declarations from.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallHop

type CallHop struct {
	Symbol   SymbolRef
	FromFQN  string
	Depth    int
	Evidence Evidence // the CALLS edge, not the symbol
}

CallHop is one step along the path from a handler towards the data.

type Capability

type Capability struct {
	Component string
	Include   []string
	Endpoints []SymbolRef
	Tables    []TableRef
	// DependsOn is what this capability needs from the others, read straight
	// off the component crossings. A capability described only by what it
	// exposes and what it stores is described as if it were alone in the
	// system, and the first question anyone asks of a capability model is which
	// other capabilities a change to this one reaches.
	DependsOn []CapabilityLink
	Symbols   int
	Files     int
	Silent    bool
	Evidence  Evidence
	Omissions []Omission
}

Capability is one candidate business capability. A26.

DERIVED, not inferred, and the distinction is the whole design. The name is the declared component's name — not a name generated from the code — and the contents are the endpoints the index says that component exposes and the tables the index says it touches. Nothing here reads a method name and decides the system does "payments".

Silent is set when a declared component has neither endpoints nor tables in the index. That component is still listed, saying exactly that. Dropping it would leave a reader believing the model covers the repository when it covers the part of the repository with HTTP routes in it.

type CapabilityLink struct {
	To       string
	Kinds    []string
	Count    int
	Verdict  string
	RuleID   string
	Evidence Evidence
}

CapabilityLink is one capability's dependency on another.

A projection of the Crossing already derived for the architecture document, not a second derivation of it: two derivations of the same dependency are two chances for the two documents to disagree about the system.

type Component

type Component struct {
	Name     string
	Include  []string
	Exclude  []string
	Files    int
	Symbols  int
	Evidence Evidence // the declaration itself, in the config file
}

Component is one DECLARED component, with what the index found inside it.

Include and Exclude are echoed from the declaration because they are the evidence for the component's existence in a way a file count is not: they are the text somebody wrote, and a component whose patterns match nothing is the single most useful thing this section can surface.

type Counts

type Counts struct {
	Files          int
	Symbols        int
	Edges          int
	Endpoints      int
	Tables         int
	ExposesEdges   int
	InheritEdges   int
	TableAccessEdg int
}

Counts are the raw index totals, printed so a reader can see how much of the repository the document is a view of.

type Coverage

type Coverage struct {
	Endpoints        int
	EndpointsClaimed int
	Tables           int
	TablesClaimed    int
}

Coverage is how much of what the index knows the capability model names.

Printed as a fraction, never as a percentage alone: "62%" of four endpoints is a number pretending to be a measurement, and the denominator is the part a reader needs in order to judge the rest of the document.

type Crossing

type Crossing struct {
	From    string
	To      string
	Kinds   []string // distinct edge kinds behind it, sorted
	Count   int
	Weakest model.Confidence
	// Verdict and RuleID come from the declared rules. A crossing the rules
	// forbid is drawn differently, because a diagram that renders a violation
	// identically to a permitted dependency has hidden the only part of it
	// anybody needed to see.
	Verdict  string
	RuleID   string
	Evidence Evidence // a stable representative among Count edges
}

Crossing is one component-to-component dependency, aggregated.

type Diagram

type Diagram struct {
	ID    string
	Title string
	Kind  DiagramKind
	Nodes []DiagramNode
	Edges []DiagramEdge
	// Note explains an empty or partial diagram, e.g. "this index contains no
	// IMPLEMENTS or EXTENDS edges". An empty diagram with no note is
	// indistinguishable from a broken generator.
	Note      string
	Omissions []Omission
}

Diagram is one renderable picture plus the evidence behind every part of it.

The evidence is not a footnote bolted on afterwards — it is carried on the node and the edge, and Validate refuses a diagram where any part lacks it. That refusal is the whole difference between this and a generated picture: an arrow a reader cannot check is an assertion, and a page of unverifiable assertions is what the competing tools already ship.

func (Diagram) Mermaid

func (d Diagram) Mermaid() string

Mermaid renders the diagram.

Conservative syntax only: `graph`, `flowchart` and `classDiagram` with quoted labels. Newer Mermaid spellings are avoided on purpose — a diagram that renders only on the latest renderer does not render in the reader's code host, and a document whose diagrams show as a wall of text is worse than one with no diagrams.

func (Diagram) Validate

func (d Diagram) Validate() []string

Validate reports every part of the diagram that cannot be traced back to the index.

Every part, not the first, because this is a correctness invariant of the generator rather than user input: if it ever fires, the useful output is the full list of what lost its provenance, not one example.

type DiagramEdge

type DiagramEdge struct {
	From     string
	To       string
	Label    string
	Violates bool
	Evidence Evidence
}

DiagramEdge is one arrow.

type DiagramKind

type DiagramKind string

DiagramKind selects the Mermaid dialect.

const (
	// KindComponentGraph renders declared components and the dependencies
	// between them.
	KindComponentGraph DiagramKind = "component"
	// KindFlow renders one endpoint's path to the data.
	KindFlow DiagramKind = "flow"
	// KindInheritance renders IMPLEMENTS and EXTENDS.
	KindInheritance DiagramKind = "inheritance"
)

type DiagramNode

type DiagramNode struct {
	ID       string
	Label    string
	Role     NodeRole
	Evidence Evidence
}

DiagramNode is one box. Shape is chosen by Role.

type EndpointFlow

type EndpointFlow struct {
	Endpoint SymbolRef
	Handler  *SymbolRef
	// Exposes is the EXPOSES edge's own citation, which is a different fact
	// from the handler's declaration site.
	Exposes   Evidence
	Calls     []CallHop
	Tables    []TableRef
	Omissions []Omission
}

EndpointFlow is one HTTP endpoint and everything the graph says it reaches.

Handler is nil when the endpoint has no EXPOSES edge. That happens for real — a route whose handler the framework's syntax did not reveal — and the endpoint is still shown, because "this endpoint exists and we could not see what serves it" is a fact worth printing and inventing an edge to the nearest function would be a guess wearing an edge's clothes. internal/pipeline declines to write that edge for the same reason.

type Evidence

type Evidence struct {
	FilePath   string
	Line       int
	Source     model.SourceType
	Confidence model.Confidence
	Detail     string
}

Evidence is the citation carried by every derived fact in this package.

It is a narrowed copy of model.Evidence plus the confidence of the edge or symbol it came from, rather than model.Evidence itself, because a citation without a confidence is only half a citation: "controller writes payments" is a different claim when the edge behind it is compiler-proven than when it was guessed from a name, and a document that renders both as the same arrow is exactly the unverifiable artifact this package exists to avoid.

The zero value means "no citation", and Cited reports that. Nothing that cannot answer Cited is allowed into a diagram; see View.Diagrams.

func (Evidence) Cited

func (e Evidence) Cited() bool

Cited reports whether this evidence can actually be checked by a reader.

A file path is the load-bearing part — it is what someone opens. A line of 0 is tolerated because several real sources (a config declaration, a table bound from a migration) legitimately point at a file rather than a line, and demanding a fake line number would make the citation less true, not more.

func (Evidence) Location

func (e Evidence) Location() string

Location renders the citation the way a reader greps for it.

func (Evidence) String

func (e Evidence) String() string

String is the full citation: where, from what kind of source, how strongly.

type Generator

type Generator struct {
	// contains filtered or unexported fields
}

Generator derives documents from an index.

Constructed with functional options per docs/development.md §2, and holds no mutable state: Derive takes everything that varies per call as an argument, so one Generator is safe to share and two concurrent Derives cannot see each other.

func New

func New(reg Registry, opts ...Option) (*Generator, error)

New returns a Generator reading through reg.

func (*Generator) Derive

func (g *Generator) Derive(ctx context.Context, runID int64, m arch.Model) (*View, error)

Derive reads the index once and builds every view both documents need.

m is the DECLARED component model, exactly as internal/capability/architecture takes it. An empty model is not an error here — unlike Check, which refuses to grade a repository that declared nothing — because the endpoint flows and the inheritance view are derived from edges and are worth rendering either way. What the documents must not do is invent components, and they do not: see View.ComponentsDeclared.

type Inheritance

type Inheritance struct {
	Kind     model.EdgeKind
	Child    SymbolRef
	Parent   SymbolRef
	Evidence Evidence
}

Inheritance is one IMPLEMENTS or EXTENDS relationship.

type Limits

type Limits struct {
	// MaxComponents caps the component table and the component diagram's nodes.
	MaxComponents int
	// MaxCrossings caps the component diagram's edges. Higher than the node cap
	// because a readable component diagram is dense in edges and sparse in
	// boxes, which is the opposite of the flow diagrams.
	MaxCrossings int
	// MaxEndpointFlows caps how many endpoints get a diagram.
	MaxEndpointFlows int
	// MaxCallDepth bounds the CALLS walk out of a handler. Three hops covers
	// handler -> service -> repository, which is the shape the flow diagram is
	// named after. Deeper walks reach the whole program and stop describing the
	// endpoint.
	MaxCallDepth int
	// MaxCallsPerFlow and MaxTablesPerFlow cap one endpoint's diagram.
	MaxCallsPerFlow  int
	MaxTablesPerFlow int
	// MaxInheritance caps the inheritance view's edges.
	MaxInheritance int
	// MaxCapabilities caps the capability model.
	MaxCapabilities int
	// MaxEndpointsPerCapability and MaxTablesPerCapability cap one capability's
	// listing.
	MaxEndpointsPerCapability int
	MaxTablesPerCapability    int
	// MaxDependenciesPerCapability caps one capability's "depends on" list.
	MaxDependenciesPerCapability int
	// MaxSharedTables caps the shared-data section.
	MaxSharedTables int
	// MaxUnclaimed caps EACH of the two unclaimed listings — endpoints and
	// tables — rather than their total. A repository with 400 unattributed
	// endpoints and 3 unattributed tables must still be told about the 3, and a
	// shared budget spent in declaration order would hide them.
	MaxUnclaimed int
}

Limits bound every section of the document.

Why caps rather than a page budget

The failure this prevents is specific: a 10,000-symbol repository producing a 10,000-node diagram. That is not a large document, it is an unusable one — Mermaid's layout is superlinear, code hosts stop rendering past a few hundred nodes, and no human reads a graph they cannot see the edges of. A single overall byte budget would fix the file size and leave one runaway section eating the document, so each section is capped on its own and each one reports what it dropped.

Where the numbers come from

They are set at the point a diagram stops being readable, not at the point it stops being renderable, and those are far apart. A component diagram is legible to about thirty boxes; a repository declaring more than 40 components has a taxonomy problem no diagram will fix. Fifty endpoint flows is already fifty diagrams, which is a long document; past that, the reader wants a filtered regeneration, not more pages.

Zero means "use the default"

Not "show nothing". A caller building a Limits literal and setting one field is the overwhelmingly common case, and reading the other seven as "suppress that section entirely" would turn a partial literal into a silently empty document. A caller who genuinely wants a section gone omits the section, not the number. Negative values are rejected by Validate rather than clamped, because -1 in a config is a typo and rendering something for it hides the typo.

func DefaultLimits

func DefaultLimits() Limits

DefaultLimits is what a caller gets when it asks for nothing.

func (Limits) Validate

func (l Limits) Validate() error

Validate rejects limits that would produce a document nobody asked for.

Reports every problem at once, like arch.Model.Validate, because these arrive from a flag set or a config block a person is editing.

type NodeRole

type NodeRole string

NodeRole picks a shape so the reader can tell an endpoint from a table without reading every label.

const (
	RoleComponent NodeRole = "component"
	RoleEndpoint  NodeRole = "endpoint"
	RoleHandler   NodeRole = "handler"
	RoleCall      NodeRole = "call"
	RoleTable     NodeRole = "table"
	RoleType      NodeRole = "type"
)

type Omission

type Omission struct {
	Subject string // what was truncated, e.g. "component dependencies"
	Shown   int
	Total   int
	Order   string // the rule that decided which ones survived
}

Omission records something the caps kept out of the document.

Every truncation produces one and every one is printed. A bounded diagram is honest; a bounded diagram that does not say it is bounded reads as a complete picture of a system, which is worse than no picture at all.

func (Omission) String

func (o Omission) String() string

type Option

type Option func(*Generator) error

Option configures a Generator.

func WithConfigPath

func WithConfigPath(path string) Option

WithConfigPath names the file the component declarations were read from.

It exists so the component section can cite something. A component's evidence is not a file in the repository — it is the line somebody wrote in .graphlume.yml — and a component node with no citation would be the one node in the document a reader could not check.

func WithLimits

func WithLimits(l Limits) Option

WithLimits overrides the output caps. Zero fields keep their defaults; see Limits.

type Registry

type Registry interface {
	Files(ctx context.Context, runID int64) ([]model.File, error)
	Symbols(ctx context.Context, runID int64) ([]model.Symbol, error)
	Edges(ctx context.Context, runID int64) ([]model.Edge, error)
	// TopLevelCalls is the calls made outside every definition and the
	// synthetic per-file callers that make them.
	TopLevelCalls(ctx context.Context, runID int64) (registry.TopLevel, error)
}

Registry is the read surface this package needs, declared here at the consumer rather than imported as a concrete type.

Three methods, matching internal/capability/architecture's port exactly. That is deliberate: the two packages ask the index the same question — "give me the whole graph for this run" — and a second, differently-shaped port for the same question would mean two fakes to keep in step. Every method here is a method a test double has to implement, and a double that has grown to mirror the real registry has stopped being a test aid.

Note what is NOT here. There is no Endpoints method even though registry.EndpointReport exists and would have saved the endpoint derivation below: EndpointReport returns a registry DTO, which would put a concrete adapter type in this package's signature, and it answers only half the question — it knows the handler but not what the handler goes on to touch. The EXPOSES edges are in Edges already.

There is no Graph port either. The obvious one — Traverse(ctx, graph.Query) — would name graph.Query in this package's signatures and would hand the document's shape to a confidence-weighted, budget-bounded expansion whose output is deliberately not a pure function of the edge set. Both are wrong for an artifact whose entire value is that it regenerates byte-identically. The endpoint→handler→service→table walk is done here, over the edges Edges already returned, bounded by Limits and ordered explicitly. This is a real deviation from the "ports for the registry and the graph" instruction and it is recorded here rather than left to be discovered.

type SharedTable

type SharedTable struct {
	Table string
	By    []TableAccess // sorted by component name
}

SharedTable is a table more than one capability reaches.

This is the fact a per-capability listing cannot show and the one that most often decides whether a capability model is real: two capabilities writing the same table are coupled through the database whatever the component diagram says, and a reader planning a change needs to see it without cross-referencing every section by hand. Derived entirely from the READS/WRITES edges already attributed above — nothing here decides that a table "belongs" to anybody.

type SymbolRef

type SymbolRef struct {
	Name      string
	FQN       string
	Kind      model.EntityKind
	Component string // "" when no declared component owns its file
	Evidence  Evidence
}

SymbolRef is one symbol as a document cites it.

type TableAccess

type TableAccess struct {
	Component string
	Access    string // "reads", "writes" or "reads/writes"
	Evidence  Evidence
}

TableAccess is one capability's access to one table.

type TableRef

type TableRef struct {
	Table    string
	Access   string // "reads", "writes" or "reads/writes"
	ViaName  string // the symbol performing the access
	ViaFQN   string
	Evidence Evidence
}

TableRef is one table a piece of code touches, and how.

type Unclaimed

type Unclaimed struct {
	Symbol SymbolRef
	// Detail states WHY it is unclaimed, in one sentence, chosen from a fixed
	// set at derivation time. "Unclaimed" alone is ambiguous between "nothing
	// declares it" and "nothing in the index touches it", and those call for
	// different responses.
	Detail string
}

Unclaimed is one endpoint or table the index knows about that no declared component accounts for.

The reason this exists: a capability model derived only from what the declarations cover reads as a description of the whole system, and a reader has no way to see the part it left out. Listing what fell outside turns the gap into a finding — either the declarations are incomplete, or that code genuinely belongs to nobody, and both are worth knowing. It is also the only thing this document can honestly say about a repository that declared no components at all: the endpoints are still facts, the capability names are not.

type View

type View struct {
	RunID      int64
	ConfigPath string
	Limits     Limits

	// ComponentsDeclared is false when .graphlume.yml declares no components.
	// The documents then say so instead of inventing a component model.
	ComponentsDeclared bool
	RulesDeclared      int

	Components   []Component
	Crossings    []Crossing
	Endpoints    []EndpointFlow
	Inheritance  []Inheritance
	Capabilities []Capability

	// SharedTables, UnclaimedEndpoints, UnclaimedTables and Coverage complete
	// the capability model: what the capabilities share, what they do not
	// account for, and how much of the index they cover. The three are derived
	// from the same attribution the capabilities are, so they cannot disagree
	// with it.
	//
	// The unclaimed sets and Coverage are computed from the DECLARATIONS, not
	// from the capped Capabilities slice: an endpoint whose capability was
	// dropped by MaxCapabilities is claimed but omitted, which is a different
	// fact from unclaimed, and the omission list is where it is reported.
	SharedTables       []SharedTable
	UnclaimedEndpoints []Unclaimed
	UnclaimedTables    []Unclaimed
	Coverage           Coverage

	Counts    Counts
	Omissions []Omission
}

View is the whole derived model: one pass over the index, two documents.

Architecture (A27) and Capabilities (A26) render from the same View rather than each deriving their own, so the two documents can never disagree about what the graph contains.

func (*View) ArchitectureMarkdown

func (v *View) ArchitectureMarkdown() string

ArchitectureMarkdown renders A27: the component view, the endpoint flows and the inheritance view, each with the evidence behind it.

func (*View) CapabilityMarkdown

func (v *View) CapabilityMarkdown() string

CapabilityMarkdown renders A26: candidate business capabilities.

func (*View) ComponentDiagram

func (v *View) ComponentDiagram() Diagram

ComponentDiagram is the declared component model and the dependencies the graph actually contains between its parts.

Returns a diagram with a Note and no nodes when the repository declares no components. That is not an empty result to be hidden: "this repository has not declared an architecture" is the most useful thing the section can say, and the alternative — clustering directories and calling the result the architecture — is the inference this package exists to refuse. See the package doc, and internal/capability/architecture's, which makes the same argument for the checker.

func (*View) Diagrams

func (v *View) Diagrams() []Diagram

Diagrams returns every diagram the architecture document contains, in document order.

Exists so the invariant "every node and edge carries evidence" can be checked over the whole document at once rather than diagram by diagram, and so a caller rendering to some other format does not have to re-derive the set.

func (*View) FlowDiagram

func (v *View) FlowDiagram(f EndpointFlow) Diagram

FlowDiagram renders one endpoint's path from route to data.

The shape is fixed — endpoint, handler, calls, tables — because that is the question the diagram answers. A general reachability picture out of a handler is a different and much less useful drawing.

func (*View) InheritanceDiagram

func (v *View) InheritanceDiagram() Diagram

InheritanceDiagram renders IMPLEMENTS and EXTENDS.

These edge kinds are recent; an index built before they were produced contains none at all. An empty diagram here therefore means "this index has none", which is a fact about the index and not about the code, and the Note says exactly that rather than letting a reader conclude the code has no interfaces.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL